commit b89f6ca3fa90631e9c0aa5f5e3e6e4dcf492fcc6 Author: Damian Johnson atagar@torproject.org Date: Mon Nov 6 12:03:25 2017 -0800
Switch installation to setuptools
Got additional testers on #tor-dev and turns out our custom installer causes it to fail for just about everybody. Dropping the ability to specify a man or samplerc path to get us back on the road best traveled. Also swapping from distutil to setuptools so we have entry_points (which we need for a bin script). --- nyx/__init__.py | 2 +- setup.py | 113 +++------------------------------------------------ test/installation.py | 2 +- 3 files changed, 7 insertions(+), 110 deletions(-)
diff --git a/nyx/__init__.py b/nyx/__init__.py index 48dd767..d500970 100644 --- a/nyx/__init__.py +++ b/nyx/__init__.py @@ -89,7 +89,7 @@ except ImportError:
sys.exit(1)
-__version__ = '2.0.2' +__version__ = '2.0.3' __release_date__ = 'November 5, 2017' __author__ = 'Damian Johnson' __contact__ = 'atagar@torproject.org' diff --git a/setup.py b/setup.py index 37923cc..5659053 100644 --- a/setup.py +++ b/setup.py @@ -2,16 +2,10 @@ # Copyright 2010-2017, Damian Johnson and The Tor Project # See LICENSE for licensing information
-import gzip +import setuptools import os import re -import stat import sys -import sysconfig - -from distutils import log -from distutils.core import setup -from distutils.command.install import install
if '--dryrun' in sys.argv: DRY_RUN = True @@ -66,113 +60,15 @@ with open('nyx/__init__.py') as init_file: if m: ATTR[m.group(1)] = m.group(2)
- -class NyxInstaller(install): - """ - Nyx installer. This adds the following additional options... - - --man-page [path] - --sample-path [path] - - If the man page path ends in '.gz' it will be compressed. Empty paths such - as... - - % python setup.py install --man-page '' - - ... will cause that resource to be omitted. - """ - - # We don't actually use single-version-externally-managed. Unfortunately pip - # has a bug where it expects any cmdclass to be setuptools, otherwise it - # fails with... - # - # % sudo pip install nyx - # ... - # Installing collected packages: nyx - # Running setup.py install for nyx ... error - # Complete output from command /usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-EOQT9b/nyx/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-PHiCsl-record/install-record.txt --single-version-externally-managed --compile: - # usage: -c [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...] - # or: -c --help [cmd1 cmd2 ...] - # or: -c --help-commands - # or: -c cmd --help - # - # error: option --single-version-externally-managed not recognized - # - # We have a few options to sidestep this... - # - # * Have users install with 'sudo pip install --egg nyx' instead. - # * Extend setuptools.command.install, which has the argument. - # * Hack in a no-op argument to sidestep as we do here. - - user_options = install.user_options + [ - ('man-page=', None, 'man page location'), - ('sample-path=', None, 'example nyxrc location'), - ('single-version-externally-managed', None, ''), # needed to sidestep pip bug - ] - - def initialize_options(self): - install.initialize_options(self) - self.man_page = None - self.sample_path = None - self.single_version_externally_managed = None - - def run(self): - install.run(self) - - self.install_bin_script('run_nyx', os.path.join(self.install_scripts, 'nyx')) - self.install_file('man page', 'nyx.1', self.man_page) - self.install_file('nyxrc sample', os.path.join('web', 'nyxrc.sample'), self.sample_path) - - def install_bin_script(self, source, dest): - # Install our bin script. We do this ourselves rather than with the setup() - # method's scripts argument because we want to call the script 'nyx' rather - # than 'run_nyx'. - # - # If using setuptools this would be better replaced with its entry_points. - - self.mkpath(os.path.dirname(dest)) - - with open(source, 'rb') as source_file: - with open(dest, 'wb') as dest_file: - orig_shebang = source_file.readline() - - python_cmd = 'python%s%s' % (sysconfig.get_config_var('VERSION'), sysconfig.get_config_var('EXE')) - new_shebang = '#!%s\n' % os.path.join(sysconfig.get_config_var('BINDIR'), python_cmd) - - log.info("adjusting bin script's shebang line '%s' -> '%s'" % (orig_shebang.strip(), new_shebang.strip())) - dest_file.write(str.encode(new_shebang)) - dest_file.write(source_file.read()) - - mode = ((os.stat(dest)[stat.ST_MODE]) | 0o555) & 0o7777 - os.chmod(dest, mode) - log.info("installed bin script to '%s'" % dest) - - def install_file(self, resource, source, dest): - if not dest: - log.info('skipping installation of the %s' % resource) - return - elif not os.path.exists(source): - raise OSError(None, "%s doesn't exist at '%s'" % (resource, source)) - - self.mkpath(os.path.dirname(dest)) - open_func = gzip.open if dest.endswith('.gz') else open - - with open(source, 'rb') as source_file: - with open_func(dest, 'wb') as dest_file: - dest_file.write(source_file.read()) - log.info("installed %s to '%s'" % (resource, dest)) - - # installation requires us to be in our setup.py's directory
-setup_dir = os.path.dirname(os.path.join(os.getcwd(), __file__)) -os.chdir(setup_dir) +os.chdir(os.path.dirname(os.path.abspath(__file__)))
with open('MANIFEST.in', 'w') as manifest_file: manifest_file.write(MANIFEST)
try: - setup( + setuptools.setup( name = 'nyx-dry-run' if DRY_RUN else 'nyx', version = ATTR['version'], description = DRY_RUN_SUMMARY if DRY_RUN else SUMMARY, @@ -185,7 +81,8 @@ try: keywords = 'tor onion controller', install_requires = ['stem>=1.6.0'], package_data = {'nyx': ['settings/*']}, - cmdclass = {'install': NyxInstaller}, + data_files = [('man/man1', ['nyx.1'])], + entry_points = {'console_scripts': ['nyx = nyx.__init__:main']}, classifiers = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Console :: Curses', diff --git a/test/installation.py b/test/installation.py index 3095e16..d37d852 100644 --- a/test/installation.py +++ b/test/installation.py @@ -20,7 +20,7 @@ class TestInstallation(unittest.TestCase):
try: os.chdir(base_directory) - stem.util.system.call(sys.executable + ' setup.py install --prefix /tmp/nyx_test --man-page /tmp/nyx_test/nyx.1.gz --sample-path /tmp/nyx_test/nyxrc.sample') + stem.util.system.call(sys.executable + ' setup.py install --prefix /tmp/nyx_test') stem.util.system.call(sys.executable + ' setup.py clean --all') # tidy up the build directory site_packages_paths = glob.glob('/tmp/nyx_test/lib*/*/site-packages')
tor-commits@lists.torproject.org