Skip to content

Commit

Permalink
Merge 1e35639 into acaa02e
Browse files Browse the repository at this point in the history
  • Loading branch information
bsipocz committed Jul 7, 2017
2 parents acaa02e + 1e35639 commit 1580f80
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 78 deletions.
57 changes: 14 additions & 43 deletions ah_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,24 @@
use_setuptools()


# typing as a dependency for 1.6.1+ Sphinx causes issues when imported after
# initializing submodule with ah_boostrap.py
# See discussion and references in
# https://github.com/astropy/astropy-helpers/issues/302

try:
import typing # noqa
except ImportError:
pass


# Note: The following import is required as a workaround to
# https://github.com/astropy/astropy-helpers/issues/89; if we don't import this
# module now, it will get cleaned up after `run_setup` is called, but that will
# later cause the TemporaryDirectory class defined in it to stop working when
# used later on by setuptools
try:
import setuptools.py31compat
import setuptools.py31compat # noqa
except ImportError:
pass

Expand Down Expand Up @@ -702,7 +713,7 @@ def _update_submodule(self, submodule, status):
if self.offline:
cmd.append('--no-fetch')
elif status == 'U':
raise _AHBoostrapSystemExit(
raise _AHBootstrapSystemExit(
'Error: Submodule {0} contains unresolved merge conflicts. '
'Please complete or abandon any changes in the submodule so that '
'it is in a usable state, then try again.'.format(submodule))
Expand Down Expand Up @@ -763,7 +774,7 @@ def run_cmd(cmd):
msg = 'Command not found: `{0}`'.format(' '.join(cmd))
raise _CommandNotFound(msg, cmd)
else:
raise _AHBoostrapSystemExit(
raise _AHBootstrapSystemExit(
'An unexpected error occurred when running the '
'`{0}` command:\n{1}'.format(' '.join(cmd), str(e)))

Expand Down Expand Up @@ -878,46 +889,6 @@ def __init__(self, *args):
super(_AHBootstrapSystemExit, self).__init__(msg, *args[1:])


if sys.version_info[:2] < (2, 7):
# In Python 2.6 the distutils log does not log warnings, errors, etc. to
# stderr so we have to wrap it to ensure consistency at least in this
# module
import distutils

class log(object):
def __getattr__(self, attr):
return getattr(distutils.log, attr)

def warn(self, msg, *args):
self._log_to_stderr(distutils.log.WARN, msg, *args)

def error(self, msg):
self._log_to_stderr(distutils.log.ERROR, msg, *args)

def fatal(self, msg):
self._log_to_stderr(distutils.log.FATAL, msg, *args)

def log(self, level, msg, *args):
if level in (distutils.log.WARN, distutils.log.ERROR,
distutils.log.FATAL):
self._log_to_stderr(level, msg, *args)
else:
distutils.log.log(level, msg, *args)

def _log_to_stderr(self, level, msg, *args):
# This is the only truly 'public' way to get the current threshold
# of the log
current_threshold = distutils.log.set_threshold(distutils.log.WARN)
distutils.log.set_threshold(current_threshold)
if level >= current_threshold:
if args:
msg = msg % args
sys.stderr.write('%s\n' % msg)
sys.stderr.flush()

log = log()


BOOTSTRAPPER = _Bootstrapper.main()


Expand Down
2 changes: 1 addition & 1 deletion astropy_helpers
Submodule astropy_helpers updated 61 files
+17 −19 .travis.yml
+59 −9 CHANGES.rst
+19 −0 README.rst
+14 −43 ah_bootstrap.py
+5 −7 appveyor.yml
+3 −3 astropy_helpers/commands/_test_compat.py
+12 −7 astropy_helpers/commands/build_ext.py
+34 −12 astropy_helpers/commands/build_sphinx.py
+1 −1 astropy_helpers/commands/test.py
+0 −38 astropy_helpers/compat/_subprocess_py2/__init__.py
+0 −18 astropy_helpers/compat/subprocess.py
+1 −1 astropy_helpers/distutils_helpers.py
+11 −0 astropy_helpers/extern/__init__.py
+1 −0 astropy_helpers/extern/automodapi/__init__.py
+28 −18 astropy_helpers/extern/automodapi/autodoc_enhancements.py
+64 −28 astropy_helpers/extern/automodapi/automodapi.py
+71 −53 astropy_helpers/extern/automodapi/automodsumm.py
+0 −1 astropy_helpers/extern/automodapi/smart_resolver.py
+0 −0 astropy_helpers/extern/automodapi/templates/autosummary_core/base.rst
+0 −0 astropy_helpers/extern/automodapi/templates/autosummary_core/class.rst
+0 −0 astropy_helpers/extern/automodapi/templates/autosummary_core/module.rst
+36 −0 astropy_helpers/extern/automodapi/utils.py
+3 −0 astropy_helpers/extern/numpydoc/__init__.py
+107 −53 astropy_helpers/extern/numpydoc/docscrape.py
+21 −11 astropy_helpers/extern/numpydoc/docscrape_sphinx.py
+83 −0 astropy_helpers/extern/numpydoc/linkcode.py
+38 −20 astropy_helpers/extern/numpydoc/numpydoc.py
+4 −0 astropy_helpers/extern/setup_package.py
+26 −15 astropy_helpers/setup_helpers.py
+3 −1 astropy_helpers/sphinx/__init__.py
+19 −15 astropy_helpers/sphinx/conf.py
+0 −1 astropy_helpers/sphinx/ext/__init__.py
+0 −123 astropy_helpers/sphinx/ext/astropyautosummary.py
+0 −169 astropy_helpers/sphinx/ext/comment_eater.py
+0 −865 astropy_helpers/sphinx/ext/compiler_unparse.py
+1 −1 astropy_helpers/sphinx/ext/doctest.py
+1 −2 astropy_helpers/sphinx/ext/edit_on_github.py
+0 −167 astropy_helpers/sphinx/ext/phantom_import.py
+0 −70 astropy_helpers/sphinx/ext/tests/__init__.py
+0 −56 astropy_helpers/sphinx/ext/tests/test_autodoc_enhancements.py
+0 −343 astropy_helpers/sphinx/ext/tests/test_automodapi.py
+0 −114 astropy_helpers/sphinx/ext/tests/test_automodsumm.py
+0 −791 astropy_helpers/sphinx/ext/tests/test_docscrape.py
+0 −34 astropy_helpers/sphinx/ext/tests/test_utils.py
+0 −142 astropy_helpers/sphinx/ext/traitsdoc.py
+ astropy_helpers/sphinx/local/python2_local_links.inv
+7 −0 astropy_helpers/sphinx/local/python2_local_links.txt
+ astropy_helpers/sphinx/local/python3_local_links.inv
+22 −0 astropy_helpers/sphinx/local/python3_local_links.txt
+0 −1 astropy_helpers/sphinx/setup_package.py
+14 −8 astropy_helpers/sphinx/themes/bootstrap-astropy/static/copybutton.js
+1 −1 astropy_helpers/test_helpers.py
+4 −0 astropy_helpers/tests/coveragerc
+13 −10 astropy_helpers/tests/test_ah_bootstrap.py
+6 −7 astropy_helpers/tests/test_git_helpers.py
+21 −12 astropy_helpers/tests/test_setup_helpers.py
+4 −20 astropy_helpers/utils.py
+2 −2 astropy_helpers/version_helpers.py
+234 −202 ez_setup.py
+1 −1 setup.cfg
+2 −5 setup.py
57 changes: 23 additions & 34 deletions ez_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
Maintained at https://github.com/pypa/setuptools/tree/bootstrap.
Run this script to install or upgrade setuptools.
This method is DEPRECATED. Check https://github.com/pypa/setuptools/issues/581 for more details.
"""

import os
Expand All @@ -18,27 +20,28 @@
import platform
import textwrap
import contextlib
import json
import codecs

from distutils import log

try:
from urllib.request import urlopen
from urllib.parse import urljoin
except ImportError:
from urllib2 import urlopen
from urlparse import urljoin

try:
from site import USER_SITE
except ImportError:
USER_SITE = None

LATEST = object()
DEFAULT_VERSION = LATEST
# 33.1.1 is the last version that supports setuptools self upgrade/installation.
DEFAULT_VERSION = "33.1.1"
DEFAULT_URL = "https://pypi.io/packages/source/s/setuptools/"
DEFAULT_SAVE_DIR = os.curdir
DEFAULT_DEPRECATION_MESSAGE = "ez_setup.py is deprecated and when using it setuptools will be pinned to {0} since it's the last version that supports setuptools self upgrade/installation, check https://github.com/pypa/setuptools/issues/581 for more info; use pip to install setuptools"

MEANINGFUL_INVALID_ZIP_ERR_MSG = 'Maybe {0} is corrupted, delete it and try again.'

log.warn(DEFAULT_DEPRECATION_MESSAGE.format(DEFAULT_VERSION))


def _python_cmd(*args):
Expand Down Expand Up @@ -104,8 +107,16 @@ def archive_context(filename):
old_wd = os.getcwd()
try:
os.chdir(tmpdir)
with ContextualZipFile(filename) as archive:
archive.extractall()
try:
with ContextualZipFile(filename) as archive:
archive.extractall()
except zipfile.BadZipfile as err:
if not err.args:
err.args = ('', )
err.args = err.args + (
MEANINGFUL_INVALID_ZIP_ERR_MSG.format(filename),
)
raise

# going in the directory
subdir = os.path.join(tmpdir, os.listdir(tmpdir)[0])
Expand All @@ -120,11 +131,12 @@ def archive_context(filename):

def _do_download(version, download_base, to_dir, download_delay):
"""Download Setuptools."""
egg = os.path.join(to_dir, 'setuptools-%s-py%d.%d.egg'
% (version, sys.version_info[0], sys.version_info[1]))
py_desig = 'py{sys.version_info[0]}.{sys.version_info[1]}'.format(sys=sys)
tp = 'setuptools-{version}-{py_desig}.egg'
egg = os.path.join(to_dir, tp.format(**locals()))
if not os.path.exists(egg):
archive = download_setuptools(version, download_base,
to_dir, download_delay)
to_dir, download_delay)
_build_egg(egg, archive, to_dir)
sys.path.insert(0, egg)

Expand All @@ -146,7 +158,6 @@ def use_setuptools(
Return None. Raise SystemExit if the requested version
or later cannot be installed.
"""
version = _resolve_version(version)
to_dir = os.path.abspath(to_dir)

# prior to importing, capture the module state for
Expand Down Expand Up @@ -333,7 +344,6 @@ def download_setuptools(
``downloader_factory`` should be a function taking no arguments and
returning a function for downloading a URL to a target.
"""
version = _resolve_version(version)
# making sure we use the absolute path
to_dir = os.path.abspath(to_dir)
zip_name = "setuptools-%s.zip" % version
Expand All @@ -346,27 +356,6 @@ def download_setuptools(
return os.path.realpath(saveto)


def _resolve_version(version):
"""
Resolve LATEST version
"""
if version is not LATEST:
return version

meta_url = urljoin(DEFAULT_URL, '/pypi/setuptools/json')
resp = urlopen(meta_url)
with contextlib.closing(resp):
try:
charset = resp.info().get_content_charset()
except Exception:
# Python 2 compat; assume UTF-8
charset = 'UTF-8'
reader = codecs.getreader(charset)
doc = json.load(reader(resp))

return str(doc['info']['version'])


def _build_install_args(options):
"""
Build the arguments to 'python setup.py install' on the setuptools package.
Expand Down

0 comments on commit 1580f80

Please sign in to comment.