Skip to content
This repository was archived by the owner on Nov 11, 2024. It is now read-only.

Tests broken with setuptools 36 and above #361

Closed
astrofrog opened this issue Jan 15, 2018 · 1 comment
Closed

Tests broken with setuptools 36 and above #361

astrofrog opened this issue Jan 15, 2018 · 1 comment

Comments

@astrofrog
Copy link
Member

Since the following commit in setuptools: nwpushuai/python-setuptools@472c79f - some of the tests in astropy-helpers are failing, e.g.:

=============================================================== test session starts ================================================================
platform darwin -- Python 3.6.4, pytest-3.3.2, py-1.5.2, pluggy-0.6.0
rootdir: /Users/tom/Dropbox/Code/Astropy/astropy-helpers, inifile: setup.cfg
plugins: hypothesis-3.38.5
collected 28 items                                                                                                                                 

astropy_helpers/tests/test_ah_bootstrap.py F                                                                                                 [100%]

===================================================================== FAILURES =====================================================================
___________________________________________________________ test_bootstrap_from_archive ____________________________________________________________

    @contextlib.contextmanager
    def save_modules():
        """
        Context in which imported modules are saved.
    
        Translates exceptions internal to the context into the equivalent exception
        outside the context.
        """
        saved = sys.modules.copy()
        with ExceptionSaver() as saved_exc:
>           yield saved

/Users/tom/tmp/setuptools/setuptools/sandbox.py:158: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

setup_dir = '/private/var/folders/zy/t1l3sx310d3d6p0kyxqzlrnr0000gr/T/pytest-of-tom/pytest-27/test_bootstrap_from_archive0/orig'

    @contextlib.contextmanager
    def setup_context(setup_dir):
        temp_dir = os.path.join(setup_dir, 'temp')
        with save_pkg_resources_state():
            with save_modules():
                hide_setuptools()
                with save_path():
                    with save_argv():
                        with override_temp(temp_dir):
                            with pushd(setup_dir):
                                # ensure setuptools commands are available
                                __import__('setuptools')
>                               yield

/Users/tom/tmp/setuptools/setuptools/sandbox.py:199: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

setup_script = 'setup.py', args = []

    def run_setup(setup_script, args):
        """Run a distutils setup script, sandboxed in its directory"""
        setup_dir = os.path.abspath(os.path.dirname(setup_script))
        with setup_context(setup_dir):
            try:
                sys.argv[:] = [setup_script] + list(args)
                sys.path.insert(0, setup_dir)
                # reset to include setup dir, w/clean callback list
                working_set.__init__()
                working_set.callbacks.append(lambda dist: dist.activate())
    
                # __file__ should be a byte string on Python 2 (#712)
                dunder_file = (
                    setup_script
                    if isinstance(setup_script, str) else
                    setup_script.encode(sys.getfilesystemencoding())
                )
    
                with DirectorySandbox(setup_dir):
                    ns = dict(__file__=dunder_file, __name__='__main__')
>                   _execfile(setup_script, ns)

/Users/tom/tmp/setuptools/setuptools/sandbox.py:254: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

filename = 'setup.py'
globals = {'__builtins__': {'ArithmeticError': <class 'ArithmeticError'>, 'AssertionError': <class 'AssertionError'>, 'Attribute...', 'ah_bootstrap': <module 'ah_bootstrap' from '/Users/tom/Dropbox/Code/Astropy/astropy-helpers/ah_bootstrap.py'>, ...}
locals = {'__builtins__': {'ArithmeticError': <class 'ArithmeticError'>, 'AssertionError': <class 'AssertionError'>, 'Attribute...', 'ah_bootstrap': <module 'ah_bootstrap' from '/Users/tom/Dropbox/Code/Astropy/astropy-helpers/ah_bootstrap.py'>, ...}

    def _execfile(filename, globals, locals=None):
        """
        Python 3 implementation of execfile.
        """
        mode = 'rb'
        with open(filename, mode) as stream:
            script = stream.read()
        # compile() function in Python 2.6 and 3.1 requires LF line endings.
        if sys.version_info[:2] < (2, 7) or sys.version_info[:2] >= (3, 0) and sys.version_info[:2] < (3, 2):
            script = script.replace(b'\r\n', b'\n')
            script = script.replace(b'\r', b'\n')
        if locals is None:
            locals = globals
        code = compile(script, filename, 'exec')
>       exec(code, globals, locals)

/Users/tom/tmp/setuptools/setuptools/sandbox.py:49: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

>   ???

setup.py:18: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

kwargs = {'path': 'astropy-helpers-test-0.1.tar.gz'}
config = {'auto_upgrade': False, 'index_url': 'https://pypi.python.org/simple', 'offline': False, 'path': 'astropy-helpers-test-0.1.tar.gz', ...}

    def use_astropy_helpers(**kwargs):
        """
        Ensure that the `astropy_helpers` module is available and is importable.
        This supports automatic submodule initialization if astropy_helpers is
        included in a project as a git submodule, or will download it from PyPI if
        necessary.
    
        Parameters
        ----------
    
        path : str or None, optional
            A filesystem path relative to the root of the project's source code
            that should be added to `sys.path` so that `astropy_helpers` can be
            imported from that path.
    
            If the path is a git submodule it will automatically be initialized
            and/or updated.
    
            The path may also be to a ``.tar.gz`` archive of the astropy_helpers
            source distribution.  In this case the archive is automatically
            unpacked and made temporarily available on `sys.path` as a ``.egg``
            archive.
    
            If `None` skip straight to downloading.
    
        download_if_needed : bool, optional
            If the provided filesystem path is not found an attempt will be made to
            download astropy_helpers from PyPI.  It will then be made temporarily
            available on `sys.path` as a ``.egg`` archive (using the
            ``setup_requires`` feature of setuptools.  If the ``--offline`` option
            is given at the command line the value of this argument is overridden
            to `False`.
    
        index_url : str, optional
            If provided, use a different URL for the Python package index than the
            main PyPI server.
    
        use_git : bool, optional
            If `False` no git commands will be used--this effectively disables
            support for git submodules. If the ``--no-git`` option is given at the
            command line the value of this argument is overridden to `False`.
    
        auto_upgrade : bool, optional
            By default, when installing a package from a non-development source
            distribution ah_boostrap will try to automatically check for patch
            releases to astropy-helpers on PyPI and use the patched version over
            any bundled versions.  Setting this to `False` will disable that
            functionality. If the ``--offline`` option is given at the command line
            the value of this argument is overridden to `False`.
    
        offline : bool, optional
            If `False` disable all actions that require an internet connection,
            including downloading packages from the package index and fetching
            updates to any git submodule.  Defaults to `True`.
        """
    
        global BOOTSTRAPPER
    
        config = BOOTSTRAPPER.config
        config.update(**kwargs)
    
        # Create a new bootstrapper with the updated configuration and run it
        BOOTSTRAPPER = _Bootstrapper(**config)
>       BOOTSTRAPPER.run()

ah_bootstrap.py:952: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ah_bootstrap._Bootstrapper object at 0x10fd8ef60>

    def run(self):
        strategies = ['local_directory', 'local_file', 'index']
        dist = None
    
        # First, remove any previously imported versions of astropy_helpers;
        # this is necessary for nested installs where one package's installer
        # is installing another package via setuptools.sandbox.run_setup, as in
        # the case of setup_requires
        for key in list(sys.modules):
            try:
                if key == PACKAGE_NAME or key.startswith(PACKAGE_NAME + '.'):
                    del sys.modules[key]
            except AttributeError:
                # Sometimes mysterious non-string things can turn up in
                # sys.modules
                continue
    
        # Check to see if the path is a submodule
        self.is_submodule = self._check_submodule()
    
        for strategy in strategies:
            method = getattr(self, 'get_{0}_dist'.format(strategy))
            dist = method()
            if dist is not None:
                break
        else:
            raise _AHBootstrapSystemExit(
                "No source found for the {0!r} package; {0} must be "
                "available and importable as a prerequisite to building "
>               "or installing this package.".format(PACKAGE_NAME))
E           ah_bootstrap._AHBootstrapSystemExit: No source found for the '_astropy_helpers_test_' package; _astropy_helpers_test_ must be available and importable as a prerequisite to building or installing this package.
E           
E           If the problem persists consider installing astropy_helpers manually using pip
E           (`pip install astropy_helpers`) or by manually downloading the source archive,
E           extracting it, and installing by running `python setup.py install` from the
E           root of the extracted source code.

ah_bootstrap.py:314: _AHBootstrapSystemExit

During handling of the above exception, another exception occurred:

tmpdir = local('/private/var/folders/zy/t1l3sx310d3d6p0kyxqzlrnr0000gr/T/pytest-of-tom/pytest-27/test_bootstrap_from_archive0')
testpackage = local('/private/var/folders/zy/t1l3sx310d3d6p0kyxqzlrnr0000gr/T/pytest-of-tom/pytest-27/test_bootstrap_from_archive0/testpkg')
capsys = <_pytest.capture.CaptureFixture object at 0x10fc1a748>

    def test_bootstrap_from_archive(tmpdir, testpackage, capsys):
        """
        Tests importing _astropy_helpers_test_ from a .tar.gz source archive
        shipped alongside the package that uses it.
        """
    
        orig_repo = tmpdir.mkdir('orig')
    
        # Ensure ah_bootstrap is imported from the local directory
        import ah_bootstrap  # noqa
    
        # Make a source distribution of the test package
        with silence():
            run_setup(str(testpackage.join('setup.py')),
                      ['sdist', '--dist-dir=dist', '--formats=gztar'])
    
        dist_dir = testpackage.join('dist')
        for dist_file in dist_dir.visit('*.tar.gz'):
            dist_file.copy(orig_repo)
    
        with orig_repo.as_cwd():
            # Write a test setup.py that uses ah_bootstrap; it also ensures that
            # any previous reference to astropy_helpers is first wiped from
            # sys.modules
            args = 'path={0!r}'.format(os.path.basename(str(dist_file)))
            orig_repo.join('setup.py').write(TEST_SETUP_PY.format(args=args))
    
>           run_setup('setup.py', [])

astropy_helpers/tests/test_ah_bootstrap.py:260: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
astropy_helpers/tests/__init__.py:50: in run_setup
    return sandbox.run_setup(*args, **kwargs)
/Users/tom/tmp/setuptools/setuptools/sandbox.py:257: in run_setup
    raise
/Users/tom/miniconda3/envs/setuptools-dev/lib/python3.6/contextlib.py:99: in __exit__
    self.gen.throw(type, value, traceback)
/Users/tom/tmp/setuptools/setuptools/sandbox.py:199: in setup_context
    yield
/Users/tom/miniconda3/envs/setuptools-dev/lib/python3.6/contextlib.py:99: in __exit__
    self.gen.throw(type, value, traceback)
/Users/tom/tmp/setuptools/setuptools/sandbox.py:170: in save_modules
    saved_exc.resume()
/Users/tom/tmp/setuptools/setuptools/sandbox.py:145: in resume
    six.reraise(type, exc, self._tb)
/Users/tom/tmp/setuptools/pkg_resources/_vendor/six.py:685: in reraise
    raise value.with_traceback(tb)
/Users/tom/tmp/setuptools/setuptools/sandbox.py:158: in save_modules
    yield saved
/Users/tom/tmp/setuptools/setuptools/sandbox.py:199: in setup_context
    yield
/Users/tom/tmp/setuptools/setuptools/sandbox.py:254: in run_setup
    _execfile(setup_script, ns)
/Users/tom/tmp/setuptools/setuptools/sandbox.py:49: in _execfile
    exec(code, globals, locals)
setup.py:18: in <module>
    ???
ah_bootstrap.py:952: in use_astropy_helpers
    BOOTSTRAPPER.run()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <ah_bootstrap._Bootstrapper object at 0x10fd8ef60>

    def run(self):
        strategies = ['local_directory', 'local_file', 'index']
        dist = None
    
        # First, remove any previously imported versions of astropy_helpers;
        # this is necessary for nested installs where one package's installer
        # is installing another package via setuptools.sandbox.run_setup, as in
        # the case of setup_requires
        for key in list(sys.modules):
            try:
                if key == PACKAGE_NAME or key.startswith(PACKAGE_NAME + '.'):
                    del sys.modules[key]
            except AttributeError:
                # Sometimes mysterious non-string things can turn up in
                # sys.modules
                continue
    
        # Check to see if the path is a submodule
        self.is_submodule = self._check_submodule()
    
        for strategy in strategies:
            method = getattr(self, 'get_{0}_dist'.format(strategy))
            dist = method()
            if dist is not None:
                break
        else:
            raise _AHBootstrapSystemExit(
                "No source found for the {0!r} package; {0} must be "
                "available and importable as a prerequisite to building "
>               "or installing this package.".format(PACKAGE_NAME))
E           ah_bootstrap._AHBootstrapSystemExit: No source found for the '_astropy_helpers_test_' package; _astropy_helpers_test_ must be available and importable as a prerequisite to building or installing this package.
E           
E           If the problem persists consider installing astropy_helpers manually using pip
E           (`pip install astropy_helpers`) or by manually downloading the source archive,
E           extracting it, and installing by running `python setup.py install` from the
E           root of the extracted source code.
E           
E           
E           If the problem persists consider installing astropy_helpers manually using pip
E           (`pip install astropy_helpers`) or by manually downloading the source archive,
E           extracting it, and installing by running `python setup.py install` from the
E           root of the extracted source code.

ah_bootstrap.py:314: _AHBootstrapSystemExit
--------------------------------------------------------------- Captured stdout call ---------------------------------------------------------------
Attempting to unpack and import astropy_helpers from 'astropy-helpers-test-0.1.tar.gz'
--------------------------------------------------------------- Captured stderr call ---------------------------------------------------------------
Downloading 'astropy-helpers-test' disabled.

I don't understand yet why this is happening. If anyone fancies figuring out how to fix it, feel free to try! :) In the mean time I'm pinning the setuptools version in #360

@astrofrog
Copy link
Member Author

I made a minimal failing example and reported this to setuptools: pypa/setuptools#1273

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant