Skip to content
This repository has been archived by the owner on May 25, 2022. It is now read-only.

Commit

Permalink
Fixed a couple tests that were broken by earlier changes on this bran…
Browse files Browse the repository at this point in the history
…ch, and fixes the issue with Sphinx 1.3 and syntax issues using Python 2.
  • Loading branch information
embray committed Mar 28, 2015
1 parent 27f2924 commit 7ee7e54
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 4 deletions.
9 changes: 9 additions & 0 deletions astropy_helpers/commands/build_sphinx.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
from distutils import log
from distutils.cmd import DistutilsOptionError

import sphinx
from sphinx.setup_command import BuildDoc as SphinxBuildDoc

from ..utils import minversion


PY3 = sys.version_info[0] >= 3

Expand Down Expand Up @@ -146,6 +149,12 @@ def run(self):
subproccode[i] = repr(val)
subproccode = ''.join(subproccode)

# This is a quick gross hack, but it ensures that the code grabbed from
# SphinxBuildDoc.run will work in Python 2 if it uses the print
# function
if minversion(sphinx, '1.3'):
subproccode = 'from __future__ import print_function' + subproccode

if self.no_intersphinx:
# the confoverrides variable in sphinx.setup_command.BuildDoc can
# be used to override the conf.py ... but this could well break
Expand Down
3 changes: 1 addition & 2 deletions astropy_helpers/sphinx/ext/automodapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
sphinx markup.
"""

env = app.builder.env

spl = _automodapirex.split(sourcestr)
if len(spl) > 1: # automodsumm is in this document

Expand Down Expand Up @@ -313,6 +311,7 @@ def automodapi_replace(sourcestr, app, dotoctree=True, docname=None,
f.write('\n**NEW DOC**\n\n')
f.write(ustr)
else:
env = app.builder.env
# Determine the filename associated with this doc (specifically
# the extension)
filename = docname + os.path.splitext(env.doc2path(docname))[1]
Expand Down
6 changes: 4 additions & 2 deletions astropy_helpers/sphinx/ext/tests/test_automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ def warn(self, msg, loc):
automodsumm_to_autosummary_lines
generate_automodsumm_docs
process_automodsumm_generation
setup"""
setup
"""


def test_ams_to_asmry(tmpdir):
Expand Down Expand Up @@ -97,7 +98,8 @@ def test_ams_to_asmry(tmpdir):
.. autosummary::
:p:
pilot"""
pilot
"""


def test_ams_cython(tmpdir, cython_testpackage):
Expand Down
67 changes: 67 additions & 0 deletions astropy_helpers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,70 @@ def delete(self):
delattr(self, private_name)

return property(get, set, delete)


def minversion(module, version, inclusive=True, version_path='__version__'):
"""
Returns `True` if the specified Python module satisfies a minimum version
requirement, and `False` if not.
By default this uses `pkg_resources.parse_version` to do the version
comparison if available. Otherwise it falls back on
`distutils.version.LooseVersion`.
Parameters
----------
module : module or `str`
An imported module of which to check the version, or the name of
that module (in which case an import of that module is attempted--
if this fails `False` is returned).
version : `str`
The version as a string that this module must have at a minimum (e.g.
``'0.12'``).
inclusive : `bool`
The specified version meets the requirement inclusively (i.e. ``>=``)
as opposed to strictly greater than (default: `True`).
version_path : `str`
A dotted attribute path to follow in the module for the version.
Defaults to just ``'__version__'``, which should work for most Python
modules.
Examples
--------
>>> import astropy
>>> minversion(astropy, '0.4.4')
True
"""

if isinstance(module, types.ModuleType):
module_name = module.__name__
elif isinstance(module, six.string_types):
module_name = module
try:
module = resolve_name(module_name)
except ImportError:
return False
else:
raise ValueError('module argument must be an actual imported '
'module, or the import name of the module; '
'got {0!r}'.format(module))

if '.' not in version_path:
have_version = getattr(module, version_path)
else:
have_version = resolve_name('.'.join([module.__name__, version_path]))

try:
from pkg_resources import parse_version
except ImportError:
from distutils.version import LooseVersion as parse_version

if inclusive:
return parse_version(have_version) >= parse_version(version)
else:
return parse_version(have_version) > parse_version(version)

0 comments on commit 7ee7e54

Please sign in to comment.