Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3f2ba3b

Browse files
committed
Branch merge
2 parents 2495c6a + 4d15546 commit 3f2ba3b

35 files changed

Lines changed: 144 additions & 294 deletions

Doc/install/install.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,8 @@ Additionally, there's a ``global`` section for options that affect every command
842842
Sections consist of one or more lines containing a single option specified as
843843
``option = value``.
844844

845+
.. XXX use dry-run in the next example or use a pysetup option as example
846+
845847
For example, here's a complete configuration file that forces all commands to
846848
run quietly by default::
847849

Doc/install/pysetup.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Getting a list of all pysetup actions and global options::
149149
list: List installed projects
150150
graph: Display a graph
151151
create: Create a project
152-
generate-setup: Generate a backward-comptatible setup.py
152+
generate-setup: Generate a backward-compatible setup.py
153153

154154
To get more help on an action, use:
155155

Doc/library/packaging.compiler.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ function. Compiler types provided by Packaging are listed in
1515
Public functions
1616
----------------
1717

18-
.. function:: new_compiler(plat=None, compiler=None, verbose=0, dry_run=0, force=0)
18+
.. function:: new_compiler(plat=None, compiler=None, dry_run=False, force=False)
1919

2020
Factory function to generate an instance of some
2121
:class:`~.ccompiler.CCompiler` subclass for the requested platform or
@@ -165,7 +165,7 @@ link steps needed to build a single project. Methods are provided to set
165165
options for the compiler --- macro definitions, include directories, link path,
166166
libraries and the like.
167167

168-
.. class:: CCompiler([verbose=0, dry_run=0, force=0])
168+
.. class:: CCompiler(dry_run=False, force=False)
169169

170170
The abstract base class :class:`CCompiler` defines the interface that must be
171171
implemented by real compiler classes. The class also has some utility
@@ -180,11 +180,11 @@ libraries and the like.
180180
per-compilation or per-link basis.
181181

182182
The constructor for each subclass creates an instance of the Compiler object.
183-
Flags are *verbose* (show verbose output), *dry_run* (don't actually execute
183+
Flags are *dry_run* (don't actually execute
184184
the steps) and *force* (rebuild everything, regardless of dependencies). All
185-
of these flags default to ``0`` (off). Note that you probably don't want to
185+
of these flags default to ``False`` (off). Note that you probably don't want to
186186
instantiate :class:`CCompiler` or one of its subclasses directly - use the
187-
:func:`packaging.CCompiler.new_compiler` factory function instead.
187+
:func:`new_compiler` factory function instead.
188188

189189
The following methods allow you to manually alter compiler options for the
190190
instance of the Compiler class.

Doc/library/packaging.util.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ This module contains various helpers for the other modules.
9090
Search the path for a given executable name.
9191

9292

93-
.. function:: execute(func, args[, msg=None, verbose=0, dry_run=0])
93+
.. function:: execute(func, args, msg=None, dry_run=False)
9494

9595
Perform some action that affects the outside world (for instance, writing to
9696
the filesystem). Such actions are special because they are disabled by the
@@ -117,7 +117,8 @@ This module contains various helpers for the other modules.
117117
:exc:`ValueError` if *val* is anything else.
118118

119119

120-
.. function:: byte_compile(py_files[, optimize=0, force=0, prefix=None, base_dir=None, verbose=1, dry_run=0, direct=None])
120+
.. function:: byte_compile(py_files, optimize=0, force=0, prefix=None, \
121+
base_dir=None, dry_run=0, direct=None)
121122

122123
Byte-compile a collection of Python source files to either :file:`.pyc` or
123124
:file:`.pyo` files in a :file:`__pycache__` subdirectory (see :pep:`3147`),
@@ -131,6 +132,9 @@ This module contains various helpers for the other modules.
131132
* ``1`` - normal optimization (like ``python -O``)
132133
* ``2`` - extra optimization (like ``python -OO``)
133134

135+
This function is independent from the running Python's :option:`-O` or
136+
:option:`-B` options; it is fully controlled by the parameters passed in.
137+
134138
If *force* is true, all files are recompiled regardless of timestamps.
135139

136140
The source filename encoded in each :term:`bytecode` file defaults to the filenames
@@ -149,6 +153,3 @@ This module contains various helpers for the other modules.
149153
figure out to use direct compilation or not (see the source for details).
150154
The *direct* flag is used by the script generated in indirect mode; unless
151155
you know what you're doing, leave it set to ``None``.
152-
153-
This function is independent from the running Python's :option:`-O` or
154-
:option:`-B` options; it is fully controlled by the parameters passed in.

Doc/packaging/setupcfg.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ needs to have its options defined in a dedicated section. Here's an example::
779779
extra_compile_args =
780780
-fPIC -O2
781781
-DGECODE_VERSION=$(./gecode_version) -- sys.platform != 'win32'
782-
/DGECODE_VERSION='win32' -- sys.platform == 'win32'
782+
/DGECODE_VERSION=win32 -- sys.platform == 'win32'
783783

784784
The section name must start with ``extension:``; the right-hand part is used as
785785
the full name (including a parent package, if any) of the extension. Whitespace

Doc/whatsnew/3.3.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ Other issues
596596
paths. In previous versions, it did. See changeset for doc changes in
597597
various files. Contributed by Carl Meyer with editions by Éric Araujo.
598598
599-
.. Issue #10998: -Q command-line flags are related artifacts have been
599+
.. Issue #10998: the -Q command-line flag and related artifacts have been
600600
removed. Code checking sys.flags.division_warning will need updating.
601601
Contributed by Éric Araujo.
602602

Lib/packaging/command/build_ext.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import re
55
import sys
66
import site
7-
import logging
87
import sysconfig
98

109
from packaging.util import get_platform
@@ -288,14 +287,9 @@ def run(self):
288287
self.libraries.extend(build_clib.get_library_names() or [])
289288
self.library_dirs.append(build_clib.build_clib)
290289

291-
# Temporary kludge until we remove the verbose arguments and use
292-
# logging everywhere
293-
verbose = logger.getEffectiveLevel() >= logging.DEBUG
294-
295290
# Setup the CCompiler object that we'll use to do all the
296291
# compiling and linking
297292
self.compiler_obj = new_compiler(compiler=self.compiler,
298-
verbose=verbose,
299293
dry_run=self.dry_run,
300294
force=self.force)
301295

Lib/packaging/command/build_py.py

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class build_py(Command, Mixin2to3):
1818

1919
description = "build pure Python modules (copy to build directory)"
2020

21-
# The options for controlling byte compilations are two independent sets;
21+
# The options for controlling byte compilation are two independent sets;
2222
# more info in install_lib or the reST docs
2323

2424
user_options = [
@@ -113,7 +113,8 @@ def run(self):
113113
self.run_2to3(self._updated_files, self._doctests_2to3,
114114
self.use_2to3_fixers)
115115

116-
self.byte_compile(self.get_outputs(include_bytecode=False))
116+
self.byte_compile(self.get_outputs(include_bytecode=False),
117+
prefix=self.build_lib)
117118

118119
# -- Top-level worker functions ------------------------------------
119120

@@ -335,11 +336,9 @@ def get_outputs(self, include_bytecode=True):
335336
outputs.append(filename)
336337
if include_bytecode:
337338
if self.compile:
338-
outputs.append(imp.cache_from_source(filename,
339-
debug_override=True))
340-
if self.optimize > 0:
341-
outputs.append(imp.cache_from_source(filename,
342-
debug_override=False))
339+
outputs.append(imp.cache_from_source(filename, True))
340+
if self.optimize:
341+
outputs.append(imp.cache_from_source(filename, False))
343342

344343
outputs += [
345344
os.path.join(build_dir, filename)
@@ -391,19 +390,3 @@ def build_packages(self):
391390
for package_, module, module_file in modules:
392391
assert package == package_
393392
self.build_module(module, module_file, package)
394-
395-
def byte_compile(self, files):
396-
from packaging.util import byte_compile # FIXME use compileall
397-
prefix = self.build_lib
398-
if prefix[-1] != os.sep:
399-
prefix = prefix + os.sep
400-
401-
# XXX this code is essentially the same as the 'byte_compile()
402-
# method of the "install_lib" command, except for the determination
403-
# of the 'prefix' string. Hmmm.
404-
if self.compile:
405-
byte_compile(files, optimize=0,
406-
force=self.force, prefix=prefix, dry_run=self.dry_run)
407-
if self.optimize > 0:
408-
byte_compile(files, optimize=self.optimize,
409-
force=self.force, prefix=prefix, dry_run=self.dry_run)

Lib/packaging/command/cmd.py

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class Command:
1212
"""Abstract base class for defining command classes, the "worker bees"
13-
of the Packaging. A useful analogy for command classes is to think of
13+
of Packaging. A useful analogy for command classes is to think of
1414
them as subroutines with local variables called "options". The options
1515
are "declared" in 'initialize_options()' and "defined" (given their
1616
final values, aka "finalized") in 'finalize_options()', both of which
@@ -351,7 +351,7 @@ def get_sub_commands(self):
351351
def execute(self, func, args, msg=None, level=1):
352352
util.execute(func, args, msg, dry_run=self.dry_run)
353353

354-
def mkpath(self, name, mode=0o777, dry_run=None, verbose=0):
354+
def mkpath(self, name, mode=0o777, dry_run=None):
355355
if dry_run is None:
356356
dry_run = self.dry_run
357357
name = os.path.normpath(name)
@@ -367,9 +367,11 @@ def mkpath(self, name, mode=0o777, dry_run=None, verbose=0):
367367

368368
def copy_file(self, infile, outfile,
369369
preserve_mode=True, preserve_times=True, link=None, level=1):
370-
"""Copy a file respecting verbose, dry-run and force flags. (The
371-
former two default to whatever is in the Distribution object, and
372-
the latter defaults to false for commands that don't define it.)"""
370+
"""Copy a file respecting dry-run and force flags.
371+
372+
(dry-run defaults to whatever is in the Distribution object, and
373+
force to false for commands that don't define it.)
374+
"""
373375
if self.dry_run:
374376
# XXX add a comment
375377
return
@@ -380,20 +382,21 @@ def copy_file(self, infile, outfile,
380382

381383
def copy_tree(self, infile, outfile, preserve_mode=True,
382384
preserve_times=True, preserve_symlinks=False, level=1):
383-
"""Copy an entire directory tree respecting verbose, dry-run,
385+
"""Copy an entire directory tree respecting dry-run
384386
and force flags.
385387
"""
386388
if self.dry_run:
387-
return # see if we want to display something
388-
389+
# XXX should not return but let copy_tree log and decide to execute
390+
# or not based on its dry_run argument
391+
return
389392

390393
return util.copy_tree(infile, outfile, preserve_mode, preserve_times,
391394
preserve_symlinks, not self.force, dry_run=self.dry_run)
392395

393396
def move_file(self, src, dst, level=1):
394397
"""Move a file respecting the dry-run flag."""
395398
if self.dry_run:
396-
return # XXX log ?
399+
return # XXX same thing
397400
return move(src, dst)
398401

399402
def spawn(self, cmd, search_path=True, level=1):
@@ -439,3 +442,20 @@ def make_file(self, infiles, outfile, func, args,
439442
# Otherwise, print the "skip" message
440443
else:
441444
logger.debug(skip_msg)
445+
446+
def byte_compile(self, files, prefix=None):
447+
"""Byte-compile files to pyc and/or pyo files.
448+
449+
This method requires that the calling class define compile and
450+
optimize options, like build_py and install_lib. It also
451+
automatically respects the force and dry-run options.
452+
453+
prefix, if given, is a string that will be stripped off the
454+
filenames encoded in bytecode files.
455+
"""
456+
if self.compile:
457+
util.byte_compile(files, optimize=False, prefix=prefix,
458+
force=self.force, dry_run=self.dry_run)
459+
if self.optimize:
460+
util.byte_compile(files, optimize=self.optimize, prefix=prefix,
461+
force=self.force, dry_run=self.dry_run)

Lib/packaging/command/install_lib.py

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import os
44
import imp
5-
import logging
65

76
from packaging import logger
87
from packaging.command.cmd import Command
@@ -21,7 +20,7 @@ class install_lib(Command):
2120

2221
description = "install all modules (extensions and pure Python)"
2322

24-
# The options for controlling byte compilations are two independent sets:
23+
# The options for controlling byte compilation are two independent sets:
2524
# 'compile' is strictly boolean, and only decides whether to
2625
# generate .pyc files. 'optimize' is three-way (0, 1, or 2), and
2726
# decides both whether to generate .pyo files and what level of
@@ -84,9 +83,14 @@ def run(self):
8483
# having a build directory!)
8584
outfiles = self.install()
8685

87-
# (Optionally) compile .py to .pyc
86+
# (Optionally) compile .py to .pyc and/or .pyo
8887
if outfiles is not None and self.distribution.has_pure_modules():
89-
self.byte_compile(outfiles)
88+
# XXX comment from distutils: "This [prefix stripping] is far from
89+
# complete, but it should at least generate usable bytecode in RPM
90+
# distributions." -> need to find exact requirements for
91+
# byte-compiled files and fix it
92+
install_root = self.get_finalized_command('install_dist').root
93+
self.byte_compile(outfiles, prefix=install_root)
9094

9195
# -- Top-level worker functions ------------------------------------
9296
# (called from 'run()')
@@ -108,28 +112,6 @@ def install(self):
108112
return
109113
return outfiles
110114

111-
def byte_compile(self, files):
112-
from packaging.util import byte_compile # FIXME use compileall
113-
114-
# Get the "--root" directory supplied to the "install_dist" command,
115-
# and use it as a prefix to strip off the purported filename
116-
# encoded in bytecode files. This is far from complete, but it
117-
# should at least generate usable bytecode in RPM distributions.
118-
install_root = self.get_finalized_command('install_dist').root
119-
120-
# Temporary kludge until we remove the verbose arguments and use
121-
# logging everywhere
122-
verbose = logger.getEffectiveLevel() >= logging.DEBUG
123-
124-
if self.compile:
125-
byte_compile(files, optimize=0,
126-
force=self.force, prefix=install_root,
127-
verbose=verbose, dry_run=self.dry_run)
128-
if self.optimize > 0:
129-
byte_compile(files, optimize=self.optimize,
130-
force=self.force, prefix=install_root,
131-
verbose=verbose, dry_run=self.dry_run)
132-
133115
# -- Utility methods -----------------------------------------------
134116

135117
def _mutate_outputs(self, has_any, build_cmd, cmd_option, output_dir):
@@ -157,11 +139,9 @@ def _bytecode_filenames(self, py_filenames):
157139
if ext != PYTHON_SOURCE_EXTENSION:
158140
continue
159141
if self.compile:
160-
bytecode_files.append(imp.cache_from_source(
161-
py_file, debug_override=True))
162-
if self.optimize > 0:
163-
bytecode_files.append(imp.cache_from_source(
164-
py_file, debug_override=False))
142+
bytecode_files.append(imp.cache_from_source(py_file, True))
143+
if self.optimize:
144+
bytecode_files.append(imp.cache_from_source(py_file, False))
165145

166146
return bytecode_files
167147

0 commit comments

Comments
 (0)