- 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)
Running with regrtest does not show spurious output or unrestored
sys.std* objects; sometimes running with make test is different, I’ll
watch the buildbots.
In addition, update the create module to use logging.
When an option is changed on a command object, calling ensure_finalized
for a second time will not run finalize_options again, because
ensure_finalized is a no-op the second time. By resetting the finalized
attribute, we can be sure that whatever computation takes place in
finalize_options will happen again.
(In test_command_clean, I removed two lines that were a no-op.)
This method was named reinitialize_command in distutils and accompanied
by a comment suggesting to change it to get_reinitialized_command.
Following that, I did the change for distutils2, but it proved
confusing: The Distribution object has an internal cache of command
objects, to make sure only one instance is ever used, and the name
get_reinitialized_command could suggest that the object returned was
independent of that cache, which it was not. I’m reverting the name
change to make code clearer.
The code I fixed to comply with PEP 3147 still had one bug: When run
under python -O, some paths for pyc files would be pyo, because I called
imp.cache_from_source without explicit debug_override argument in some
places, and under -O that would return .pyo (this is well explained in
the imp docs). Now all code (util.byte_compile, build_py, install_lib)
can create .pyo files according to options given by users,
without interference from the calling Python’s own optimize mode.
On a related topic, I also removed the code that prevented byte
compilation under python -B. The rationale is that packaging gives
control over the creation of pyc files to the user with its own explicit
option, and the behavior should not be changed if the calling Python
happens to run with -B for whatever reason. I will argue that this is a
bug fix and ask to be allowed to backport this change to distutils.
Finally, I moved one nugget of information about the --compile and
--optimize options from the source into the doc. It clears up a
misunderstanding that I (and maybe other people) had.
I’ve made more edits than the bug report suggested to make sure the
generated setup script is compatible with many Python versions; a
comment in the source explains that in detail.
The cfg_to_args function uses old 2.x idioms like codecs.open and
RawConfigParser.readfp because I want the setup.py generated by packaging and
distutils2 to be the same. Most users won’t see the deprecation warning and I
ignore it in the test suite.
Thanks to David Barnett for the report and original patch.
- Use os.makedirs (I had forgotten about it!)
- Let TempdirManager.write_file call os.path.join for us
- Remove custom command added by test_dist
- Use a skip instead of hiding a method with an underscore
- Address pyflakes warnings
I need this for some tests, and it makes code clearer. This commit also
changes some assertEqual calls to use (actual, expected) order and fix
some pyflakes warnings.
I want to replace custom byte-compiling function with calls to
compileall before 3.3b1, but in the short term it’s good to have this
fixed.
Adapted from the distutils patch by Jeff Ramnani. I tested with -B, -O
and -OO; test_util and test_mixin2to3 fail in -O mode because lib2to3
doesn’t support it.
The packaging.install.remove function (a.k.a. the uninstall feature)
takes a path argument to allow client code to use custom directories
instead of sys.path. The test used to give self.root_dir as path, which
corresponds to a prefix option, but prefix is not on sys.path, it’s only
the base directory used to compute the stdlib and site-packages
directory paths. The test now gives a valid site-packages path to the
function.
install_lib may be the name of a module, a command or an option, so I
find it clearer to use site_packages to refer to a string object
containing the path of the site-packages directory created in a
temporary directory during tests.
The goal of the regex is to catch a (alpha), b (beta), c or rc
(release candidate), so the existing pattern puzzled me. Tests were
OK before and after the change.
- minor cleanup in Metadata
- trigger creation of the sysconfig._CONFIG_VARS dict
- home_page is used over home-page: it’s not a compound word, it’s an
escaped space
Distutils2 is now synchronized with Packaging.
PEP 370 features and sys.dont_write_bytecode are always available
in 3.3; the distutils2 backport still has the conditionals.
I also renamed an internal misnamed method and fixed a few things
(“packaging2” name, stray print, unused import, fd leak).
This method was supposed to return only the file under the dist-info
directory, but it actually returned all installed files.
The tests didn’t catch this because they were flawed; I updated them.
Thanks to Nadeem Vawda and Jeremy Kloth for testing.
As a bonus, the removal of os.path.relpath use should also fix the
Windows buildbots.
The command without arguments already prints all installed distributions
found.
In addition, change “releases” for “projects” in the description of the
list action. Strictly speaking, one installed distribution satisfies
the requirement for a release (i.e. version) of a project, but as
currently only one release per project can be installed at a time, the
two are somewhat equivalent, and “project” is more understandable in
help texts (which call their argument “dist”, by the way..)
New tests were added in test_metadata and old tests inherited from
distutils were still in test_dist, so I moved them into test_metadata
(except for one which was more at home in test_run) and merged
duplicates.
I also added some skips to lure contributors <wink>, optimized the
Metadata.update method a trifle, and added notes about a number of
issues.
A note: The tests in test_dist used to dump the Metadata objects to a
file in the METADATA format and look for strings in its contents; I
updated them to use the mapping API of Metadata instead. For some
fields with special writing rules, I have added tests to ensure my
conversion did not lose anything.