diff options
Diffstat (limited to 'distutils2/command')
| -rw-r--r-- | distutils2/command/bdist.py | 2 | ||||
| -rw-r--r-- | distutils2/command/bdist_dumb.py | 4 | ||||
| -rw-r--r-- | distutils2/command/bdist_msi.py | 8 | ||||
| -rw-r--r-- | distutils2/command/bdist_wininst.py | 6 | ||||
| -rw-r--r-- | distutils2/command/build.py | 2 | ||||
| -rw-r--r-- | distutils2/command/build_py.py | 77 | ||||
| -rw-r--r-- | distutils2/command/cmd.py | 24 | ||||
| -rw-r--r-- | distutils2/command/install_dist.py | 4 | ||||
| -rw-r--r-- | distutils2/command/install_distinfo.py | 25 | ||||
| -rw-r--r-- | distutils2/command/install_lib.py | 72 | ||||
| -rw-r--r-- | distutils2/command/register.py | 2 | ||||
| -rw-r--r-- | distutils2/command/test.py | 2 |
12 files changed, 93 insertions, 135 deletions
diff --git a/distutils2/command/bdist.py b/distutils2/command/bdist.py index 0a39fb1..583041e 100644 --- a/distutils2/command/bdist.py +++ b/distutils2/command/bdist.py @@ -126,7 +126,7 @@ class bdist(Command): # Reinitialize and run each command. for i in range(len(self.formats)): cmd_name = commands[i] - sub_cmd = self.get_reinitialized_command(cmd_name) + sub_cmd = self.reinitialize_command(cmd_name) sub_cmd.format = self.formats[i] # passing the owner and group names for tar archiving diff --git a/distutils2/command/bdist_dumb.py b/distutils2/command/bdist_dumb.py index 677deb9..dfe80b9 100644 --- a/distutils2/command/bdist_dumb.py +++ b/distutils2/command/bdist_dumb.py @@ -80,8 +80,8 @@ class bdist_dumb(Command): if not self.skip_build: self.run_command('build') - install = self.get_reinitialized_command('install_dist', - reinit_subcommands=True) + install = self.reinitialize_command('install_dist', + reinit_subcommands=True) install.root = self.bdist_dir install.skip_build = self.skip_build install.warn_dir = False diff --git a/distutils2/command/bdist_msi.py b/distutils2/command/bdist_msi.py index 40e733f..704e695 100644 --- a/distutils2/command/bdist_msi.py +++ b/distutils2/command/bdist_msi.py @@ -35,7 +35,7 @@ class PyDialog(Dialog): def __init__(self, *args, **kw): """Dialog(database, name, x, y, w, h, attributes, title, first, default, cancel, bitmap=true)""" - Dialog.__init__(self, *args) + super(PyDialog, self).__init__(*args) ruler = self.h - 36 #if kw.get("bitmap", True): # self.bitmap("Bitmap", 0, 0, bmwidth, ruler, "PythonWin") @@ -183,13 +183,13 @@ class bdist_msi(Command): if not self.skip_build: self.run_command('build') - install = self.get_reinitialized_command('install_dist', - reinit_subcommands=True) + install = self.reinitialize_command('install_dist', + reinit_subcommands=True) install.prefix = self.bdist_dir install.skip_build = self.skip_build install.warn_dir = False - install_lib = self.get_reinitialized_command('install_lib') + install_lib = self.reinitialize_command('install_lib') # we do not want to include pyc or pyo files install_lib.compile = False install_lib.optimize = 0 diff --git a/distutils2/command/bdist_wininst.py b/distutils2/command/bdist_wininst.py index e4cde7a..fcd0955 100644 --- a/distutils2/command/bdist_wininst.py +++ b/distutils2/command/bdist_wininst.py @@ -2,7 +2,6 @@ import sys import os -import codecs from shutil import rmtree @@ -117,14 +116,13 @@ class bdist_wininst(Command): if not self.skip_build: self.run_command('build') - install = self.get_reinitialized_command('install', - reinit_subcommands=True) + install = self.reinitialize_command('install', reinit_subcommands=True) install.root = self.bdist_dir install.skip_build = self.skip_build install.warn_dir = False install.plat_name = self.plat_name - install_lib = self.get_reinitialized_command('install_lib') + install_lib = self.reinitialize_command('install_lib') # we do not want to include pyc or pyo files install_lib.compile = False install_lib.optimize = 0 diff --git a/distutils2/command/build.py b/distutils2/command/build.py index b2e5bf8..708b848 100644 --- a/distutils2/command/build.py +++ b/distutils2/command/build.py @@ -41,7 +41,7 @@ class build(Command): ('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 to convert doctests in separate text files"), ('use-2to3-fixers', None, "list additional fixers opted for during 2to3 conversion"), ] diff --git a/distutils2/command/build_py.py b/distutils2/command/build_py.py index e27e271..f9b9bcd 100644 --- a/distutils2/command/build_py.py +++ b/distutils2/command/build_py.py @@ -1,22 +1,25 @@ """Build pure Python modules (just copy to build directory).""" import os -import sys from glob import glob from distutils2 import logger -from distutils2.command.cmd import Command -from distutils2.errors import PackagingOptionError, PackagingFileError from distutils2.util import convert_path -from distutils2.compat import Mixin2to3 +from distutils2.compat import Mixin2to3, cache_from_source +from distutils2.errors import PackagingOptionError, PackagingFileError +from distutils2.command.cmd import Command # marking public APIs __all__ = ['build_py'] + class build_py(Command, Mixin2to3): description = "build pure Python modules (copy to build directory)" + # The options for controlling byte compilation are two independent sets; + # more info in install_lib or the reST docs + user_options = [ ('build-lib=', 'd', "directory to build (copy) to"), ('compile', 'c', "compile .py to .pyc"), @@ -28,13 +31,14 @@ class build_py(Command, Mixin2to3): ('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 to convert doctests in separate text files"), ('use-2to3-fixers', None, "list additional fixers opted for during 2to3 conversion"), ] boolean_options = ['compile', 'force'] - negative_opt = {'no-compile' : 'compile'} + + negative_opt = {'no-compile': 'compile'} def initialize_options(self): self.build_lib = None @@ -108,14 +112,15 @@ class build_py(Command, Mixin2to3): self.run_2to3(self._updated_files, self._doctests_2to3, self.use_2to3_fixers) - self.byte_compile(self.get_outputs(include_bytecode=False)) + self.byte_compile(self.get_outputs(include_bytecode=False), + prefix=self.build_lib) # -- Top-level worker functions ------------------------------------ def get_data_files(self): """Generate list of '(package,src_dir,build_dir,filenames)' tuples. - Helper function for `finalize_options()`. + Helper function for finalize_options. """ data = [] if not self.packages: @@ -130,7 +135,7 @@ class build_py(Command, Mixin2to3): # Length of path to strip from found files plen = 0 if src_dir: - plen = len(src_dir)+1 + plen = len(src_dir) + 1 # Strip directory from globbed filenames filenames = [ @@ -142,7 +147,7 @@ class build_py(Command, Mixin2to3): def find_data_files(self, package, src_dir): """Return filenames for package's data files in 'src_dir'. - Helper function for `get_data_files()`. + Helper function for get_data_files. """ globs = (self.package_data.get('', []) + self.package_data.get(package, [])) @@ -157,7 +162,7 @@ class build_py(Command, Mixin2to3): def build_package_data(self): """Copy data files into build directory. - Helper function for `run()`. + Helper function for run. """ # FIXME add tests for this method for package, src_dir, build_dir, filenames in self.data_files: @@ -167,16 +172,17 @@ class build_py(Command, Mixin2to3): self.mkpath(os.path.dirname(target)) outf, copied = self.copy_file(srcfile, target, preserve_mode=False) - if copied and srcfile in self.distribution.convert_2to3.doctests: + doctests = self.distribution.convert_2to3_doctests + if copied and srcfile in doctests: self._doctests_2to3.append(outf) # XXX - this should be moved to the Distribution class as it is not # only needed for build_py. It also has no dependencies on this class. def get_package_dir(self, package): """Return the directory, relative to the top of the source - distribution, where package 'package' should be found - (at least according to the 'package_dir' option, if any).""" - + distribution, where package 'package' should be found + (at least according to the 'package_dir' option, if any). + """ path = package.split('.') if self.package_dir is not None: path.insert(0, self.package_dir) @@ -187,8 +193,7 @@ class build_py(Command, Mixin2to3): return '' def check_package(self, package, package_dir): - """Helper function for `find_package_modules()` and `find_modules()'. - """ + """Helper function for find_package_modules and find_modules.""" # Empty dir name means current directory, which we can probably # assume exists. Also, os.path.exists and isdir don't know about # my "empty string means current dir" convention, so we have to @@ -208,8 +213,8 @@ class build_py(Command, Mixin2to3): if os.path.isfile(init_py): return init_py else: - logger.warning(("package init file '%s' not found " + - "(or not a regular file)"), init_py) + logger.warning("package init file %r not found " + "(or not a regular file)", init_py) # Either not in a package at all (__init__.py not expected), or # __init__.py doesn't exist -- so don't return the filename. @@ -217,7 +222,7 @@ class build_py(Command, Mixin2to3): def check_module(self, module, module_file): if not os.path.isfile(module_file): - logger.warning("file %s (for module %s) not found", + logger.warning("file %r (for module %r) not found", module_file, module) return False else: @@ -238,7 +243,7 @@ class build_py(Command, Mixin2to3): module = os.path.splitext(os.path.basename(f))[0] modules.append((package, module, f)) else: - logger.debug("excluding %s", setup_script) + logger.debug("excluding %r", setup_script) return modules def find_modules(self): @@ -330,9 +335,9 @@ class build_py(Command, Mixin2to3): outputs.append(filename) if include_bytecode: if self.compile: - outputs.append(filename + "c") - if self.optimize > 0: - outputs.append(filename + "o") + outputs.append(cache_from_source(filename, True)) + if self.optimize: + outputs.append(cache_from_source(filename, False)) outputs += [ os.path.join(build_dir, filename) @@ -359,7 +364,6 @@ class build_py(Command, Mixin2to3): def build_modules(self): modules = self.find_modules() for package, module, module_file in modules: - # Now "build" the module -- ie. copy the source file to # self.build_lib (the build directory for Python source). # (Actually, it gets copied to the directory for this package @@ -368,7 +372,6 @@ class build_py(Command, Mixin2to3): def build_packages(self): for package in self.packages: - # Get list of (package, module, module_file) tuples based on # scanning the package directory. 'package' is only included # in the tuple so that 'find_modules()' and @@ -386,25 +389,3 @@ class build_py(Command, Mixin2to3): for package_, module, module_file in modules: assert package == package_ self.build_module(module, module_file, package) - - def byte_compile(self, files): - if sys.dont_write_bytecode: - logger.warning('%s: byte-compiling is disabled, skipping.', - self.get_command_name()) - return - - from distutils2.util import byte_compile # FIXME use compileall - prefix = self.build_lib - if prefix[-1] != os.sep: - prefix = prefix + os.sep - - # XXX this code is essentially the same as the 'byte_compile() - # method of the "install_lib" command, except for the determination - # of the 'prefix' string. Hmmm. - - if self.compile: - byte_compile(files, optimize=0, - force=self.force, prefix=prefix, dry_run=self.dry_run) - if self.optimize > 0: - byte_compile(files, optimize=self.optimize, - force=self.force, prefix=prefix, dry_run=self.dry_run) diff --git a/distutils2/command/cmd.py b/distutils2/command/cmd.py index 6d76e7f..956623d 100644 --- a/distutils2/command/cmd.py +++ b/distutils2/command/cmd.py @@ -10,7 +10,7 @@ from distutils2._backport.shutil import copyfile, move, make_archive class Command: """Abstract base class for defining command classes, the "worker bees" - of the Packaging. A useful analogy for command classes is to think of + of Packaging. A useful analogy for command classes is to think of them as subroutines with local variables called "options". The options are "declared" in 'initialize_options()' and "defined" (given their final values, aka "finalized") in 'finalize_options()', both of which @@ -318,8 +318,8 @@ class Command: cmd_obj.ensure_finalized() return cmd_obj - def get_reinitialized_command(self, command, reinit_subcommands=False): - return self.distribution.get_reinitialized_command( + def reinitialize_command(self, command, reinit_subcommands=False): + return self.distribution.reinitialize_command( command, reinit_subcommands) def run_command(self, command): @@ -386,7 +386,6 @@ class Command: if self.dry_run: return # see if we want to display something - return util.copy_tree(infile, outfile, preserve_mode, preserve_times, preserve_symlinks, not self.force, dry_run=self.dry_run) @@ -439,3 +438,20 @@ class Command: # Otherwise, print the "skip" message else: logger.debug(skip_msg) + + def byte_compile(self, files, prefix=None): + """Byte-compile files to pyc and/or pyo files. + + This method requires that the calling class define compile and + optimize options, like build_py and install_lib. It also + automatically respects the force and dry-run options. + + prefix, if given, is a string that will be stripped off the + filenames encoded in bytecode files. + """ + if self.compile: + util.byte_compile(files, optimize=False, prefix=prefix, + force=self.force, dry_run=self.dry_run) + if self.optimize: + util.byte_compile(files, optimize=self.optimize, prefix=prefix, + force=self.force, dry_run=self.dry_run) diff --git a/distutils2/command/install_dist.py b/distutils2/command/install_dist.py index 159ccc2..8d8b675 100644 --- a/distutils2/command/install_dist.py +++ b/distutils2/command/install_dist.py @@ -55,9 +55,7 @@ class install_dist(Command): ('install-data=', None, "installation directory for data files"), - # Byte-compilation options -- see install_lib.py for details, as - # these are duplicated from there (but only install_lib does - # anything with them). + # Byte-compilation options -- see install_lib for details ('compile', 'c', "compile .py to .pyc [default]"), ('no-compile', None, "don't compile .py files"), ('optimize=', 'O', diff --git a/distutils2/command/install_distinfo.py b/distutils2/command/install_distinfo.py index 167844c..d495bc2 100644 --- a/distutils2/command/install_distinfo.py +++ b/distutils2/command/install_distinfo.py @@ -16,8 +16,8 @@ class install_distinfo(Command): description = 'create a .dist-info directory for the distribution' user_options = [ - ('distinfo-dir=', None, - "directory where the the .dist-info directory will be installed"), + ('install-dir=', None, + "directory where the the .dist-info directory will be created"), ('installer=', None, "the name of the installer"), ('requested', None, @@ -35,7 +35,7 @@ class install_distinfo(Command): negative_opt = {'no-requested': 'requested'} def initialize_options(self): - self.distinfo_dir = None + self.install_dir = None self.installer = None self.requested = None self.no_record = None @@ -46,8 +46,7 @@ class install_distinfo(Command): self.set_undefined_options('install_dist', 'installer', 'requested', 'no_record') - self.set_undefined_options('install_lib', - ('install_dir', 'distinfo_dir')) + self.set_undefined_options('install_lib', 'install_dir') if self.installer is None: # FIXME distutils or packaging or distutils2? @@ -64,26 +63,26 @@ class install_distinfo(Command): basename = metadata.get_fullname(filesafe=True) + ".dist-info" - self.distinfo_dir = os.path.join(self.distinfo_dir, basename) + self.install_dir = os.path.join(self.install_dir, basename) def run(self): - target = self.distinfo_dir + target = self.install_dir if os.path.isdir(target) and not os.path.islink(target): if not self.dry_run: rmtree(target) elif os.path.exists(target): - self.execute(os.unlink, (self.distinfo_dir,), + self.execute(os.unlink, (self.install_dir,), "removing " + target) self.execute(os.makedirs, (target,), "creating " + target) - metadata_path = os.path.join(self.distinfo_dir, 'METADATA') + metadata_path = os.path.join(self.install_dir, 'METADATA') self.execute(self.distribution.metadata.write, (metadata_path,), "creating " + metadata_path) self.outfiles.append(metadata_path) - installer_path = os.path.join(self.distinfo_dir, 'INSTALLER') + installer_path = os.path.join(self.install_dir, 'INSTALLER') logger.info('creating %s', installer_path) if not self.dry_run: with open(installer_path, 'w') as f: @@ -91,7 +90,7 @@ class install_distinfo(Command): self.outfiles.append(installer_path) if self.requested: - requested_path = os.path.join(self.distinfo_dir, 'REQUESTED') + requested_path = os.path.join(self.install_dir, 'REQUESTED') logger.info('creating %s', requested_path) if not self.dry_run: open(requested_path, 'wb').close() @@ -100,7 +99,7 @@ class install_distinfo(Command): if not self.no_resources: install_data = self.get_finalized_command('install_data') if install_data.get_resources_out() != []: - resources_path = os.path.join(self.distinfo_dir, + resources_path = os.path.join(self.install_dir, 'RESOURCES') logger.info('creating %s', resources_path) if not self.dry_run: @@ -114,7 +113,7 @@ class install_distinfo(Command): self.outfiles.append(resources_path) if not self.no_record: - record_path = os.path.join(self.distinfo_dir, 'RECORD') + record_path = os.path.join(self.install_dir, 'RECORD') logger.info('creating %s', record_path) if not self.dry_run: with open(record_path, 'w', encoding='utf-8') as f: diff --git a/distutils2/command/install_lib.py b/distutils2/command/install_lib.py index ea53eab..8ee1fd5 100644 --- a/distutils2/command/install_lib.py +++ b/distutils2/command/install_lib.py @@ -1,34 +1,26 @@ """Install all modules (extensions and pure Python).""" import os -import sys -import logging from distutils2 import logger +from distutils2.compat import cache_from_source from distutils2.command.cmd import Command from distutils2.errors import PackagingOptionError # Extension for Python source files. +# XXX dead code? most of the codebase checks for literal '.py' if hasattr(os, 'extsep'): PYTHON_SOURCE_EXTENSION = os.extsep + "py" else: PYTHON_SOURCE_EXTENSION = ".py" + class install_lib(Command): description = "install all modules (extensions and pure Python)" - # The byte-compilation options are a tad confusing. Here are the - # possible scenarios: - # 1) no compilation at all (--no-compile --no-optimize) - # 2) compile .pyc only (--compile --no-optimize; default) - # 3) compile .pyc and "level 1" .pyo (--compile --optimize) - # 4) compile "level 1" .pyo only (--no-compile --optimize) - # 5) compile .pyc and "level 2" .pyo (--compile --optimize-more) - # 6) compile "level 2" .pyo only (--no-compile --optimize-more) - # - # The UI for this is two option, 'compile' and 'optimize'. + # The options for controlling byte compilation are two independent sets: # 'compile' is strictly boolean, and only decides whether to # generate .pyc files. 'optimize' is three-way (0, 1, or 2), and # decides both whether to generate .pyo files and what level of @@ -36,7 +28,7 @@ class install_lib(Command): user_options = [ ('install-dir=', 'd', "directory to install to"), - ('build-dir=','b', "build directory (where to install from)"), + ('build-dir=', 'b', "build directory (where to install from)"), ('force', 'f', "force installation (overwrite existing files)"), ('compile', 'c', "compile .py to .pyc [default]"), ('no-compile', None, "don't compile .py files"), @@ -47,7 +39,8 @@ class install_lib(Command): ] boolean_options = ['force', 'compile', 'skip-build'] - negative_opt = {'no-compile' : 'compile'} + + negative_opt = {'no-compile': 'compile'} def initialize_options(self): # let the 'install_dist' command dictate our installation directory @@ -65,7 +58,8 @@ class install_lib(Command): self.set_undefined_options('install_dist', ('build_lib', 'build_dir'), ('install_lib', 'install_dir'), - 'force', 'compile', 'optimize', 'skip_build') + 'force', 'compile', 'optimize', + 'skip_build') if self.compile is None: self.compile = True @@ -89,9 +83,14 @@ class install_lib(Command): # having a build directory!) outfiles = self.install() - # (Optionally) compile .py to .pyc + # (Optionally) compile .py to .pyc and/or .pyo if outfiles is not None and self.distribution.has_pure_modules(): - self.byte_compile(outfiles) + # XXX comment from distutils: "This [prefix stripping] is far from + # complete, but it should at least generate usable bytecode in RPM + # distributions." -> need to find exact requirements for + # byte-compiled files and fix it + install_root = self.get_finalized_command('install_dist').root + self.byte_compile(outfiles, prefix=install_root) # -- Top-level worker functions ------------------------------------ # (called from 'run()') @@ -113,38 +112,6 @@ class install_lib(Command): return return outfiles - def byte_compile(self, files): - if sys.dont_write_bytecode: - # XXX do we want this? because a Python runs without bytecode - # doesn't mean that the *dists should not contain bytecode - #--or does it? - logger.warning('%s: byte-compiling is disabled, skipping.', - self.get_command_name()) - return - - from distutils2.util import byte_compile # FIXME use compileall - - # Get the "--root" directory supplied to the "install_dist" command, - # and use it as a prefix to strip off the purported filename - # encoded in bytecode files. This is far from complete, but it - # should at least generate usable bytecode in RPM distributions. - install_root = self.get_finalized_command('install_dist').root - - # Temporary kludge until we remove the verbose arguments and use - # logging everywhere - verbose = logger.getEffectiveLevel() >= logging.DEBUG - - if self.compile: - byte_compile(files, optimize=0, - force=self.force, prefix=install_root, - dry_run=self.dry_run) - if self.optimize > 0: - byte_compile(files, optimize=self.optimize, - force=self.force, prefix=install_root, - verbose=verbose, - dry_run=self.dry_run) - - # -- Utility methods ----------------------------------------------- def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir): @@ -172,13 +139,12 @@ class install_lib(Command): if ext != PYTHON_SOURCE_EXTENSION: continue if self.compile: - bytecode_files.append(py_file + "c") - if self.optimize > 0: - bytecode_files.append(py_file + "o") + bytecode_files.append(cache_from_source(py_file, True)) + if self.optimize: + bytecode_files.append(cache_from_source(py_file, False)) return bytecode_files - # -- External interface -------------------------------------------- # (called by outsiders) diff --git a/distutils2/command/register.py b/distutils2/command/register.py index 79ec7b3..091918c 100644 --- a/distutils2/command/register.py +++ b/distutils2/command/register.py @@ -178,7 +178,7 @@ Your selection [default 1]: ''') 'will be faster.\n(the login will be stored in %s)', get_pypirc_path()) choice = 'X' - while choice.lower() not in 'yn': + while choice.lower() not in ('y', 'n'): choice = input('Save your login (y/N)?') if not choice: choice = 'n' diff --git a/distutils2/command/test.py b/distutils2/command/test.py index da5d141..09af3b6 100644 --- a/distutils2/command/test.py +++ b/distutils2/command/test.py @@ -56,7 +56,7 @@ class test(Command): prev_syspath = sys.path[:] try: # build release - build = self.get_reinitialized_command('build') + build = self.reinitialize_command('build') self.run_command('build') sys.path.insert(0, build.build_lib) |
