Skip to content

Commit

Permalink
Drop use of setuptools extension
Browse files Browse the repository at this point in the history
We were wrapping easy_install's 'install_scripts' and 'develop' methods
to generate a custom WSGI script. This was a replacement of
functionality previously provided by PBR. Unfortunately easy_install is
deprecated for removal at a future date and we don't yet have a modern
equivalent in pip [1]. As such, we need a migration plan for this and it
seems like the old school 'scripts' option is probably it. The main
downside of this is that the shebang isn't updated accordingly, which
means this won't work very well in virtualenvs, but I'm hoping that the
use of '/usr/bin/env' will allow us to work around this. At least in
local testing, it seems like this is the case:

  ❯ virtualenv .venv
  ❯ pip install .
  ❯ cat .venv/bin/gnocchi-api | head -1
  #!/gnocchi/.venv/bin/python

[1] https://discuss.python.org/t/adding-support-for-wsgi-scripts-entrypoint/30905

Signed-off-by: Stephen Finucane <[email protected]>
  • Loading branch information
stephenfin committed Aug 4, 2023
1 parent 51c35cd commit 3f45e24
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 75 deletions.
21 changes: 21 additions & 0 deletions bin/gnocchi-api
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from gnocchi.cli import api

if __name__ == '__main__':
sys.exit(api.api())
else:
application = api.wsgi()
3 changes: 3 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ packages =

include_package_data = true

scripts =
bin/gnocchi-api

install_requires =
numpy>=1.14.0
iso8601
Expand Down
76 changes: 1 addition & 75 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,82 +15,8 @@
# limitations under the License.

import setuptools
import sys

from setuptools.command import develop
from setuptools.command import easy_install
from setuptools.command import install_scripts


# NOTE(sileht): We use a template to set the right
# python version in the sheban
SCRIPT_TMPL = """
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import sys
from gnocchi.cli import api
if __name__ == '__main__':
sys.exit(api.api())
else:
application = api.wsgi()
"""


PY3 = sys.version_info >= (3,)


class local_install_scripts(install_scripts.install_scripts):
def run(self):
# NOTE(tobias-urdin): Always install_scripts so that we get
# gnocchi-api otherwise it's left out when installing with pip.
self.no_ep = False
install_scripts.install_scripts.run(self)
# NOTE(sileht): Build wheel embed custom script as data, and put sheban
# in script of the building machine. To workaround that build_scripts
# on bdist_whell return '#!python' and then during whl install it's
# replaced by the correct interpreter. We do the same here.
bs_cmd = self.get_finalized_command('build_scripts')
executable = getattr(bs_cmd, 'executable', easy_install.sys_executable)
try:
script = easy_install.get_script_header(
"", executable) + SCRIPT_TMPL
except AttributeError:
script = easy_install.ScriptWriter.get_header(
"", executable) + SCRIPT_TMPL
if PY3:
script = script.encode('ascii')
self.write_script("gnocchi-api", script, 'b')


class local_develop(develop.develop):
def install_wrapper_scripts(self, dist):
develop.develop.install_wrapper_scripts(self, dist)
if self.exclude_scripts:
return
try:
script = easy_install.get_script_header("") + SCRIPT_TMPL
except AttributeError:
script = easy_install.ScriptWriter.get_header("") + SCRIPT_TMPL
if PY3:
script = script.encode('ascii')
self.write_script("gnocchi-api", script, 'b')


cmdclass = {
'develop': local_develop,
'install_scripts': local_install_scripts,
}
cmdclass = {}

try:
from sphinx import setup_command
Expand Down

0 comments on commit 3f45e24

Please sign in to comment.