Skip to content

Commit f9964a6

Browse files
committed
RF - add doctest conversion to 2to3
1 parent 7405d76 commit f9964a6

File tree

3 files changed

+56
-32
lines changed

3 files changed

+56
-32
lines changed

nisext/py3builder.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
""" distutils utilities for porting to python 3 within 2-compatible tree """
2+
3+
try:
4+
from distutils.command.build_py import build_py_2to3
5+
except ImportError:
6+
# 2.x - no parsing of code
7+
from distutils.command.build_py import build_py
8+
else: # Python 3
9+
# Command to also apply 2to3 to doctests
10+
from distutils import log
11+
class build_py(build_py_2to3):
12+
def run_2to3(self, files):
13+
# Add doctest parsing; this stuff copied from distutils.utils in
14+
# python 3.2 source
15+
if not files:
16+
return
17+
fixer_names, options, explicit = (self.fixer_names,
18+
self.options,
19+
self.explicit)
20+
# Make this class local, to delay import of 2to3
21+
from lib2to3.refactor import RefactoringTool, get_fixers_from_package
22+
class DistutilsRefactoringTool(RefactoringTool):
23+
def log_error(self, msg, *args, **kw):
24+
log.error(msg, *args)
25+
26+
def log_message(self, msg, *args):
27+
log.info(msg, *args)
28+
29+
def log_debug(self, msg, *args):
30+
log.debug(msg, *args)
31+
32+
if fixer_names is None:
33+
fixer_names = get_fixers_from_package('lib2to3.fixes')
34+
r = DistutilsRefactoringTool(fixer_names, options=options)
35+
r.refactor(files, write=True)
36+
# Then doctests
37+
r.refactor(files, write=True, doctests_only=True)
38+

setup.py

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,18 @@
1717
# update it when the contents of directories change.
1818
if os.path.exists('MANIFEST'): os.remove('MANIFEST')
1919

20-
from distutils.core import setup
21-
22-
# For some commands, use setuptools.
20+
# For some commands, use setuptools.
2321
if len(set(('develop', 'bdist_egg', 'bdist_rpm', 'bdist', 'bdist_dumb',
2422
'bdist_wininst', 'install_egg_info', 'egg_info', 'easy_install',
2523
)).intersection(sys.argv)) > 0:
26-
# setup_egg imports setuptools setup, thus monkeypatching distutils.
27-
from setup_egg import extra_setuptools_args
24+
# setup_egg imports setuptools setup, thus monkeypatching distutils.
25+
import setup_egg
2826

29-
# extra_setuptools_args can be defined from the line above, but it can
30-
# also be defined here because setup.py has been exec'ed from
31-
# setup_egg.py.
32-
if not 'extra_setuptools_args' in globals():
33-
extra_setuptools_args = dict()
27+
from distutils.core import setup
3428

3529
# Python 2 to 3 build
36-
try:
37-
from distutils.command.build_py import build_py_2to3 as build_py
38-
except ImportError:
39-
# 2.x
40-
from distutils.command.build_py import build_py
41-
30+
from nisext.py3builder import build_py
31+
# Commit hash writing, and dependency checking
4232
from nisext.sexts import get_comrec_build, package_check
4333
cmdclass = {'build_py': get_comrec_build('nibabel', build_py)}
4434

@@ -49,11 +39,17 @@
4939
# Do dependency checking
5040
package_check('numpy', NUMPY_MIN_VERSION)
5141
package_check('dicom', PYDICOM_MIN_VERSION, optional=True)
42+
extra_setuptools_args = {}
5243
if 'setuptools' in sys.modules:
53-
extra_setuptools_args['extras_require'] = dict(
54-
doc='Sphinx>=0.3',
55-
test='nose>=0.10.1',
56-
nicom = 'dicom>=' + PYDICOM_MIN_VERSION)
44+
extra_setuptools_args = dict(
45+
tests_require=['nose'],
46+
test_suite='nose.collector',
47+
zip_safe=False,
48+
extras_require = dict(
49+
doc='Sphinx>=0.3',
50+
test='nose>=0.10.1',
51+
nicom = 'dicom>=' + PYDICOM_MIN_VERSION)
52+
)
5753

5854
def main(**extra_args):
5955
setup(name=NAME,

setup_egg.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,11 @@
33
# vi: set ft=python sts=4 ts=4 sw=4 et:
44
"""Wrapper to run setup.py using setuptools."""
55

6-
from setuptools import setup
6+
import setuptools
77

88
################################################################################
99
# Call the setup.py script, injecting the setuptools-specific arguments.
1010

11-
extra_setuptools_args = dict(
12-
tests_require=['nose'],
13-
test_suite='nose.collector',
14-
zip_safe=False,
15-
)
16-
17-
1811
if __name__ == '__main__':
19-
execfile('setup.py', dict(__name__='__main__',
20-
extra_setuptools_args=extra_setuptools_args))
21-
22-
12+
exec(open('setup.py', 'rt').read(), dict(__name__='__main__'))
2313

0 commit comments

Comments
 (0)