I added some tests in 2105ab8553b7 and found no bug, but it turns out
that the doctest is not actually run. While converting the doctest to
unittest style, I stumbled upon this bug again and this time applied the
code patch provided by Filip Gruszczyński.
The contents of this attribute are an implementation detail, as
documented for #9442, so we should not parse it, to support non-CPython
VMs with distutils2 in the future.
Unfortunately, one use comes directly from PEP 345, so an edit will have
to be agreed before fixing the code (see comment in p7g.markers).
Other remaining uses are found in p7g.compiler and could be replaced by
the platform module (which also parses sys.version, but then it wouldn’t
be my fault :)
- Change the fixers used in tests to something not provided by lib2to3
- Test conversion of doctests in text files
- Factor out test boilerplate into a common method
This fixes a regression from distutils, where “setup.py --help-commands”
prints out commands grouped by topic (i.e. building vs. installing),
which is more useful than using sorted.
pysetup create, the setup.cfg creation helper, used to convert
package_data (from an existing setup.py) into extra_files, the
replacement for MANIFEST.in, but these files are only present in sdists,
not installed: they don’t have the same use case at all, so converting
one into the other did not work.
Even though the resources system obsoletes data_files and package_data
(see bug discussion), package_data still exists to allow compatibility
with distutils and thus an easier transition. In setup.py, the values
are lists of glob patterns, so the setup.cfg syntax needed a way to
express multiple values too.
Doc for this option will be added later as part of the big packaging doc
patches. For now, the test serves as example.
Reported by Erik Bray.
Logging replaces verbose arguments. I haven’t fixed the example in
Doc/install/install.rst because I have major fixes and changes to the
oc under way and will fix or remove that example as part of that task.
- 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