summaryrefslogtreecommitdiff
path: root/src/distutils2/command
diff options
context:
space:
mode:
Diffstat (limited to 'src/distutils2/command')
-rw-r--r--src/distutils2/command/build.py9
-rw-r--r--src/distutils2/command/build_py.py70
-rw-r--r--src/distutils2/command/build_scripts.py17
-rw-r--r--src/distutils2/command/cmd.py6
-rw-r--r--src/distutils2/command/install.py2
-rw-r--r--src/distutils2/command/install_distinfo.py3
6 files changed, 43 insertions, 64 deletions
diff --git a/src/distutils2/command/build.py b/src/distutils2/command/build.py
index e1ad18a..3f7aad7 100644
--- a/src/distutils2/command/build.py
+++ b/src/distutils2/command/build.py
@@ -43,6 +43,12 @@ class build(Command):
"forcibly build everything (ignore file timestamps)"),
('executable=', 'e',
"specify final destination interpreter path (build.py)"),
+ ('use-2to3', None,
+ "use 2to3 to make source python 3.x compatible"),
+ ('convert-2to3-doctests', None,
+ "use 2to3 to convert doctests in seperate text files"),
+ ('use-2to3-fixers', None,
+ "list additional fixers opted for during 2to3 conversion"),
]
boolean_options = ['debug', 'force']
@@ -66,6 +72,9 @@ class build(Command):
self.debug = None
self.force = 0
self.executable = None
+ self.use_2to3 = False
+ self.convert_2to3_doctests = None
+ self.use_2to3_fixers = None
def finalize_options(self):
if self.plat_name is None:
diff --git a/src/distutils2/command/build_py.py b/src/distutils2/command/build_py.py
index 1a9d18b..98b1619 100644
--- a/src/distutils2/command/build_py.py
+++ b/src/distutils2/command/build_py.py
@@ -13,57 +13,10 @@ import distutils2
from distutils2.core import Command
from distutils2.errors import DistutilsOptionError, DistutilsFileError
from distutils2.util import convert_path
-from distutils2.converter.refactor import DistutilsRefactoringTool
+from distutils2.compat import Mixin2to3
# marking public APIs
-__all__ = ['Mixin2to3', 'build_py']
-
-try:
- from distutils2.util import Mixin2to3 as _Mixin2to3
- from lib2to3.refactor import get_fixers_from_package
- _CONVERT = True
- _KLASS = _Mixin2to3
-except ImportError:
- _CONVERT = False
- _KLASS = object
-
-class Mixin2to3(_KLASS):
- """ The base class which can be used for refactoring. When run under
- Python 3.0, the run_2to3 method provided by Mixin2to3 is overridden.
- When run on Python 2.x, it merely creates a class which overrides run_2to3,
- yet does nothing in particular with it.
- """
- if _CONVERT:
- def _run_2to3(self, files, doctests=[]):
- """ Takes a list of files and doctests, and performs conversion
- on those.
- - First, the files which contain the code(`files`) are converted.
- - Second, the doctests in `files` are converted.
- - Thirdly, the doctests in `doctests` are converted.
- """
-
- # Convert the ".py" files.
- logging.info("Converting Python code")
- _KLASS.run_2to3(self, files)
-
- # Convert the doctests in the ".py" files.
- logging.info("Converting doctests with '.py' files")
- _KLASS.run_2to3(self, files, doctests_only=True)
-
- # If the following conditions are met, then convert:-
- # 1. User has specified the 'convert_2to3_doctests' option. So, we
- # can expect that the list 'doctests' is not empty.
- # 2. The default is allow distutils2 to allow conversion of text files
- # containing doctests. It is set as
- # distutils2.run_2to3_on_doctests
-
- if doctests != [] and distutils2.run_2to3_on_doctests:
- logging.info("Converting text files which contain doctests")
- _KLASS.run_2to3(self, doctests, doctests_only=True)
- else:
- # If run on Python 2.x, there is nothing to do.
- def _run_2to3(self, files, doctests=[]):
- pass
+__all__ = ['build_py']
class build_py(Command, Mixin2to3):
@@ -77,6 +30,12 @@ class build_py(Command, Mixin2to3):
"also compile with optimization: -O1 for \"python -O\", "
"-O2 for \"python -OO\", and -O0 to disable [default: -O0]"),
('force', 'f', "forcibly build everything (ignore file timestamps)"),
+ ('use-2to3', None,
+ "use 2to3 to make source python 3.x compatible"),
+ ('convert-2to3-doctests', None,
+ "use 2to3 to convert doctests in seperate text files"),
+ ('use-2to3-fixers', None,
+ "list additional fixers opted for during 2to3 conversion"),
]
boolean_options = ['compile', 'force']
@@ -93,9 +52,15 @@ class build_py(Command, Mixin2to3):
self.force = None
self._updated_files = []
self._doctests_2to3 = []
+ self.use_2to3 = False
+ self.convert_2to3_doctests = None
+ self.use_2to3_fixers = None
def finalize_options(self):
- self.set_undefined_options('build', 'build_lib', 'force')
+ self.set_undefined_options('build',
+ 'use_2to3', 'use_2to3_fixers',
+ 'convert_2to3_doctests', 'build_lib',
+ 'force')
# Get the distribution options that are aliases for build_py
# options -- list of packages and list of modules.
@@ -145,8 +110,9 @@ class build_py(Command, Mixin2to3):
self.build_packages()
self.build_package_data()
- if self.distribution.use_2to3 and self_updated_files:
- self.run_2to3(self._updated_files, self._doctests_2to3)
+ if self.use_2to3 and self._updated_files:
+ self.run_2to3(self._updated_files, self._doctests_2to3,
+ self.use_2to3_fixers)
self.byte_compile(self.get_outputs(include_bytecode=0))
diff --git a/src/distutils2/command/build_scripts.py b/src/distutils2/command/build_scripts.py
index b62ade7..758e4d6 100644
--- a/src/distutils2/command/build_scripts.py
+++ b/src/distutils2/command/build_scripts.py
@@ -13,11 +13,12 @@ try:
import sysconfig
except ImportError:
from distutils2._backport import sysconfig
+from distutils2.compat import Mixin2to3
# check if Python is called on the first line with this expression
first_line_re = re.compile('^#!.*python[0-9.]*([ \t].*)?$')
-class build_scripts (Command):
+class build_scripts (Command, Mixin2to3):
description = "\"build\" scripts (copy and fixup #! line)"
@@ -36,11 +37,16 @@ class build_scripts (Command):
self.force = None
self.executable = None
self.outfiles = None
+ self.use_2to3 = False
+ self.convert_2to3_doctests = None
+ self.use_2to3_fixers = None
def finalize_options (self):
self.set_undefined_options('build',
('build_scripts', 'build_dir'),
- 'force', 'executable')
+ 'use_2to3', 'use_2to3_fixers',
+ 'convert_2to3_doctests', 'force',
+ 'executable')
self.scripts = self.distribution.scripts
def get_source_files(self):
@@ -49,8 +55,9 @@ class build_scripts (Command):
def run (self):
if not self.scripts:
return
- self.copy_scripts()
-
+ copied_files = self.copy_scripts()
+ if self.use_2to3 and self.copied_files:
+ self._run_2to3(self.copied_files, fixers=self.use_2to3_fixers)
def copy_scripts (self):
"""Copy each script listed in 'self.scripts'; if it's marked as a
@@ -126,7 +133,7 @@ class build_scripts (Command):
log.info("changing mode of %s from %o to %o",
file, oldmode, newmode)
os.chmod(file, newmode)
-
+ return outfiles
# copy_scripts ()
# class build_scripts
diff --git a/src/distutils2/command/cmd.py b/src/distutils2/command/cmd.py
index a4e4b9b..17a4379 100644
--- a/src/distutils2/command/cmd.py
+++ b/src/distutils2/command/cmd.py
@@ -53,7 +53,7 @@ class Command(object):
# Pre and post command hooks are run just before or just after the command
# itself. They are simple functions that receive the command instance. They
- # should be specified as dotted strings.
+ # are specified as callable objects or dotted strings (for lazy loading).
pre_hook = None
post_hook = None
@@ -162,13 +162,12 @@ class Command(object):
def dump_options(self, header=None, indent=""):
- from distutils2.fancy_getopt import longopt_xlate
if header is None:
header = "command options for '%s':" % self.get_command_name()
self.announce(indent + header, level=log.INFO)
indent = indent + " "
for (option, _, _) in self.user_options:
- option = option.translate(longopt_xlate)
+ option = option.replace('-', '_')
if option[-1] == "=":
option = option[:-1]
value = getattr(self, option)
@@ -331,7 +330,6 @@ class Command(object):
setattr(self, dst_option,
getattr(src_cmd_obj, src_option))
-
def get_finalized_command(self, command, create=1):
"""Wrapper around Distribution's 'get_command_obj()' method: find
(create if necessary and 'create' is true) the command object for
diff --git a/src/distutils2/command/install.py b/src/distutils2/command/install.py
index 1a6bd0e..c0c6fac 100644
--- a/src/distutils2/command/install.py
+++ b/src/distutils2/command/install.py
@@ -18,7 +18,6 @@ from distutils2.util import write_file
from distutils2.util import convert_path, change_root, get_platform
from distutils2.errors import DistutilsOptionError
-
class install(Command):
description = "install everything from build directory"
@@ -193,6 +192,7 @@ class install(Command):
# array of user input is decided. Yes, it's quite complex!)
def finalize_options(self):
+ """Finalizes options."""
# This method (and its pliant slaves, like 'finalize_unix()',
# 'finalize_other()', and 'select_scheme()') is where the default
# installation directories for modules, extension modules, and
diff --git a/src/distutils2/command/install_distinfo.py b/src/distutils2/command/install_distinfo.py
index 0e30f09..d39b7a1 100644
--- a/src/distutils2/command/install_distinfo.py
+++ b/src/distutils2/command/install_distinfo.py
@@ -25,9 +25,8 @@ except ImportError:
class install_distinfo(Command):
- """Install a .dist-info directory for the package"""
- description = 'Install a .dist-info directory for the package'
+ description = 'install a .dist-info directory for the distribution'
user_options = [
('distinfo-dir=', None,