diff options
| author | Éric Araujo <merwok@netwok.org> | 2011-11-14 17:10:19 (GMT) |
|---|---|---|
| committer | Éric Araujo <merwok@netwok.org> | 2011-11-14 17:10:19 (GMT) |
| commit | f8361623f0e5ab6c6337afcccdb442f285590869 (patch) | |
| tree | 91b0d49055dc1046f4b570cc034473feab770205 /Lib/packaging/command/cmd.py | |
| parent | d5d4406c8ebbbdf8a8961fc119be22b15a1c40ad (diff) | |
| download | cpython-f8361623f0e5ab6c6337afcccdb442f285590869.zip cpython-f8361623f0e5ab6c6337afcccdb442f285590869.tar.gz cpython-f8361623f0e5ab6c6337afcccdb442f285590869.tar.bz2 | |
Clean up byte-compilation code in packaging (#11254 followup).
- Don't use keyword arguments for debug_override; I find it more
readable to have a comment explaining that True makes pyc and False
pyo than to write out the non-obvious (when you haven’t read the doc)
argument name
- Move duplicate code from build_py and install_lib into cmd
- Remove obsolete verbose argument of util.byte_compile
- Remove obsolete passing of -O/-OO to the Python process spawned by
util.byte_compile (I’ll remove the whole spawning later, after I write
more tests to check the contents of pyc and pyo files; now that
byte_compile does not depend on the value of __debug__ in the calling
Python, we can call py_compile or compileall directly)
Diffstat (limited to 'Lib/packaging/command/cmd.py')
| -rw-r--r-- | Lib/packaging/command/cmd.py | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/Lib/packaging/command/cmd.py b/Lib/packaging/command/cmd.py index a88df02..333b99d 100644 --- a/Lib/packaging/command/cmd.py +++ b/Lib/packaging/command/cmd.py @@ -10,7 +10,7 @@ from packaging.errors import PackagingOptionError 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 @@ -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) |
