Skip to content

Commit

Permalink
Merge pull request #117 from bsipocz/update-helpers-v3.0.1
Browse files Browse the repository at this point in the history
Update astropy-helpers to v3.0.1
  • Loading branch information
cdeil authored Jun 14, 2018
2 parents e5ea0b0 + e2e60a3 commit 8d6078f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
79 changes: 55 additions & 24 deletions ah_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@
contains an option called ``auto_use`` with a value of ``True``, it will
automatically call the main function of this module called
`use_astropy_helpers` (see that function's docstring for full details).
Otherwise no further action is taken (however,
``ah_bootstrap.use_astropy_helpers`` may be called manually from within the
setup.py script).
Otherwise no further action is taken and by default the system-installed version
of astropy-helpers will be used (however, ``ah_bootstrap.use_astropy_helpers``
may be called manually from within the setup.py script).
This behavior can also be controlled using the ``--auto-use`` and
``--no-auto-use`` command-line flags. For clarity, an alias for
``--no-auto-use`` is ``--use-system-astropy-helpers``, and we recommend using
the latter if needed.
Additional options in the ``[ah_boostrap]`` section of setup.cfg have the same
names as the arguments to `use_astropy_helpers`, and can be used to configure
Expand All @@ -47,14 +52,7 @@
from configparser import ConfigParser, RawConfigParser


if sys.version_info[0] < 3:
_str_types = (str, unicode)
_text_type = unicode
PY3 = False
else:
_str_types = (str, bytes)
_text_type = str
PY3 = True
_str_types = (str, bytes)


# What follows are several import statements meant to deal with install-time
Expand Down Expand Up @@ -137,7 +135,6 @@

from setuptools import Distribution
from setuptools.package_index import PackageIndex
from setuptools.sandbox import run_setup

from distutils import log
from distutils.debug import DEBUG
Expand All @@ -146,6 +143,7 @@
# TODO: Maybe enable checking for a specific version of astropy_helpers?
DIST_NAME = 'astropy-helpers'
PACKAGE_NAME = 'astropy_helpers'
UPPER_VERSION_EXCLUSIVE = None

# Defaults for other options
DOWNLOAD_IF_NEEDED = True
Expand Down Expand Up @@ -177,7 +175,7 @@ def __init__(self, path=None, index_url=None, use_git=None, offline=None,
if not (isinstance(path, _str_types) or path is False):
raise TypeError('path must be a string or False')

if PY3 and not isinstance(path, _text_type):
if not isinstance(path, str):
fs_encoding = sys.getfilesystemencoding()
path = path.decode(fs_encoding) # path to unicode

Expand Down Expand Up @@ -287,6 +285,18 @@ def parse_command_line(cls, argv=None):
config['offline'] = True
argv.remove('--offline')

if '--auto-use' in argv:
config['auto_use'] = True
argv.remove('--auto-use')

if '--no-auto-use' in argv:
config['auto_use'] = False
argv.remove('--no-auto-use')

if '--use-system-astropy-helpers' in argv:
config['auto_use'] = False
argv.remove('--use-system-astropy-helpers')

return config

def run(self):
Expand Down Expand Up @@ -464,9 +474,10 @@ def _directory_import(self):
# setup.py exists we can generate it
setup_py = os.path.join(path, 'setup.py')
if os.path.isfile(setup_py):
with _silence():
run_setup(os.path.join(path, 'setup.py'),
['egg_info'])
# We use subprocess instead of run_setup from setuptools to
# avoid segmentation faults - see the following for more details:
# https://github.com/cython/cython/issues/2104
sp.check_output([sys.executable, 'setup.py', 'egg_info'], cwd=path)

for dist in pkg_resources.find_distributions(path, True):
# There should be only one...
Expand Down Expand Up @@ -501,16 +512,32 @@ def get_option_dict(self, command_name):
if version:
req = '{0}=={1}'.format(DIST_NAME, version)
else:
req = DIST_NAME
if UPPER_VERSION_EXCLUSIVE is None:
req = DIST_NAME
else:
req = '{0}<{1}'.format(DIST_NAME, UPPER_VERSION_EXCLUSIVE)

attrs = {'setup_requires': [req]}

# NOTE: we need to parse the config file (e.g. setup.cfg) to make sure
# it honours the options set in the [easy_install] section, and we need
# to explicitly fetch the requirement eggs as setup_requires does not
# get honored in recent versions of setuptools:
# https://github.com/pypa/setuptools/issues/1273

try:
if DEBUG:
_Distribution(attrs=attrs)
else:
with _silence():
_Distribution(attrs=attrs)

context = _verbose if DEBUG else _silence
with context():
dist = _Distribution(attrs=attrs)
try:
dist.parse_config_files(ignore_option_errors=True)
dist.fetch_build_eggs(req)
except TypeError:
# On older versions of setuptools, ignore_option_errors
# doesn't exist, and the above two lines are not needed
# so we can just continue
pass

# If the setup_requires succeeded it will have added the new dist to
# the main working_set
Expand Down Expand Up @@ -791,9 +818,9 @@ def run_cmd(cmd):
stdio_encoding = 'latin1'

# Unlikely to fail at this point but even then let's be flexible
if not isinstance(stdout, _text_type):
if not isinstance(stdout, str):
stdout = stdout.decode(stdio_encoding, 'replace')
if not isinstance(stderr, _text_type):
if not isinstance(stderr, str):
stderr = stderr.decode(stdio_encoding, 'replace')

return (p.returncode, stdout, stderr)
Expand Down Expand Up @@ -846,6 +873,10 @@ def flush(self):
pass


@contextlib.contextmanager
def _verbose():
yield

@contextlib.contextmanager
def _silence():
"""A context manager that silences sys.stdout and sys.stderr."""
Expand Down
2 changes: 1 addition & 1 deletion astropy_helpers
1 change: 1 addition & 0 deletions hips/tiles/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

__doctest_skip__ = [
'HipsTile',
'HipsTileMeta',
]


Expand Down

0 comments on commit 8d6078f

Please sign in to comment.