Skip to content

Commit fb9b466

Browse files
committed
Merge branch 'main' of https://github.com/pypa/distutils into add-mingw-support
2 parents 651a512 + e0787fa commit fb9b466

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+202
-309
lines changed

conftest.py

+13-40
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33
import platform
44
import pathlib
5+
import logging
56

67
import pytest
78
import path
@@ -36,39 +37,20 @@ def needs_zlib():
3637
pytest.importorskip('zlib')
3738

3839

39-
# from jaraco.collections
40-
class Everything:
41-
def __contains__(self, other):
42-
return True
43-
44-
45-
class SavedLogs(list):
46-
def render(self, *levels):
47-
return [
48-
msg % args for level, msg, args in self if level in (levels or Everything())
49-
]
50-
51-
52-
@pytest.fixture
53-
def logs(monkeypatch):
54-
from distutils import log
55-
56-
logs = SavedLogs()
57-
log_levels = log.DEBUG, log.INFO, log.WARN, log.ERROR, log.FATAL
58-
59-
def _log(self, level, msg, args):
60-
self.logs.append((level, msg, args))
40+
@pytest.fixture(autouse=True)
41+
def log_everything():
42+
"""
43+
For tests, set the level on the logger to log everything.
44+
"""
45+
logging.getLogger('distutils').setLevel(0)
6146

62-
def save_log(self, level, msg, args):
63-
if level not in log_levels:
64-
raise ValueError(f'invalid log level {level}')
65-
if not isinstance(msg, str):
66-
raise TypeError(f'msg should be str, not {type(msg).__name__!r}')
67-
logs.append((level, msg, args))
6847

69-
monkeypatch.setattr(log.Log, '_log', save_log)
70-
monkeypatch.setattr(log._global_log, 'threshold', log.FATAL)
71-
return logs
48+
@pytest.fixture(autouse=True)
49+
def capture_log_at_info(caplog):
50+
"""
51+
By default, capture logs at INFO and greater.
52+
"""
53+
caplog.set_level(logging.INFO)
7254

7355

7456
def _save_cwd():
@@ -111,15 +93,6 @@ def temp_cwd(tmp_path):
11193
yield
11294

11395

114-
@pytest.fixture
115-
def threshold_warn():
116-
from distutils.log import set_threshold, WARN
117-
118-
orig = set_threshold(WARN)
119-
yield
120-
set_threshold(orig)
121-
122-
12396
@pytest.fixture
12497
def pypirc(request, save_env, distutils_managed_tempdir):
12598
from distutils.core import PyPIRCCommand

distutils/_log.py

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import logging
2+
3+
4+
log = logging.getLogger()

distutils/_msvccompiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
LinkError,
3131
)
3232
from .ccompiler import CCompiler, gen_lib_options
33-
from . import log
33+
from ._log import log
3434
from .util import get_platform
3535

3636
from itertools import count

distutils/archive_util.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from .errors import DistutilsExecError
1717
from .spawn import spawn
1818
from .dir_util import mkpath
19-
from . import log
19+
from ._log import log
2020

2121
try:
2222
from pwd import getpwnam

distutils/bcppcompiler.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from .ccompiler import CCompiler, gen_preprocess_options
2626
from .file_util import write_file
2727
from .dep_util import newer
28-
from . import log
28+
from ._log import log
2929

3030

3131
warnings.warn(
@@ -210,7 +210,7 @@ def link( # noqa: C901
210210
)
211211

212212
if runtime_library_dirs:
213-
log.warn(
213+
log.warning(
214214
"I don't know what to do with 'runtime_library_dirs': %s",
215215
str(runtime_library_dirs),
216216
)

distutils/ccompiler.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from .dir_util import mkpath
2020
from .dep_util import newer_group
2121
from .util import split_quoted, execute, is_mingw
22-
from . import log
22+
from ._log import log
2323

2424

2525
class CCompiler:

distutils/cmd.py

+7-8
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
import sys
88
import os
99
import re
10+
import logging
1011

1112
from .errors import DistutilsOptionError
12-
from . import util, dir_util, file_util, archive_util, dep_util, log
13+
from . import util, dir_util, file_util, archive_util, dep_util
14+
from ._log import log
1315

1416

1517
class Command:
@@ -156,14 +158,14 @@ def dump_options(self, header=None, indent=""):
156158

157159
if header is None:
158160
header = "command options for '%s':" % self.get_command_name()
159-
self.announce(indent + header, level=log.INFO)
161+
self.announce(indent + header, level=logging.INFO)
160162
indent = indent + " "
161163
for (option, _, _) in self.user_options:
162164
option = option.translate(longopt_xlate)
163165
if option[-1] == "=":
164166
option = option[:-1]
165167
value = getattr(self, option)
166-
self.announce(indent + "{} = {}".format(option, value), level=log.INFO)
168+
self.announce(indent + "{} = {}".format(option, value), level=logging.INFO)
167169

168170
def run(self):
169171
"""A command's raison d'etre: carry out the action it exists to
@@ -179,10 +181,7 @@ def run(self):
179181
"abstract method -- subclass %s must override" % self.__class__
180182
)
181183

182-
def announce(self, msg, level=1):
183-
"""If the current verbosity level is of greater than or equal to
184-
'level' print 'msg' to stdout.
185-
"""
184+
def announce(self, msg, level=logging.DEBUG):
186185
log.log(level, msg)
187186

188187
def debug_print(self, msg):
@@ -334,7 +333,7 @@ def get_sub_commands(self):
334333
# -- External world manipulation -----------------------------------
335334

336335
def warn(self, msg):
337-
log.warn("warning: %s: %s\n", self.get_command_name(), msg)
336+
log.warning("warning: %s: %s\n", self.get_command_name(), msg)
338337

339338
def execute(self, func, args, msg=None, level=1):
340339
util.execute(func, args, msg, dry_run=self.dry_run)

distutils/command/bdist_dumb.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..dir_util import remove_tree, ensure_relative
1111
from ..errors import DistutilsPlatformError
1212
from ..sysconfig import get_python_version
13-
from distutils import log
13+
from distutils._log import log
1414

1515

1616
class bdist_dumb(Command):

distutils/command/bdist_rpm.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
DistutilsExecError,
1818
)
1919
from ..sysconfig import get_python_version
20-
from distutils import log
20+
from distutils._log import log
2121

2222

2323
class bdist_rpm(Command):

distutils/command/build_clib.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from ..core import Command
1919
from ..errors import DistutilsSetupError
2020
from ..sysconfig import customize_compiler
21-
from distutils import log
21+
from distutils._log import log
2222

2323

2424
def show_compilers():

distutils/command/build_ext.py

+6-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
from ..dep_util import newer_group
2323
from ..extension import Extension
2424
from ..util import get_platform, is_mingw
25-
from distutils import log
25+
from distutils._log import log
2626
from . import py37compat
2727

2828
from site import USER_BASE
@@ -377,7 +377,7 @@ def check_extensions_list(self, extensions): # noqa: C901
377377

378378
ext_name, build_info = ext
379379

380-
log.warn(
380+
log.warning(
381381
"old-style (ext_name, build_info) tuple found in "
382382
"ext_modules for extension '%s' "
383383
"-- please convert to Extension instance",
@@ -417,7 +417,9 @@ def check_extensions_list(self, extensions): # noqa: C901
417417
# Medium-easy stuff: same syntax/semantics, different names.
418418
ext.runtime_library_dirs = build_info.get('rpath')
419419
if 'def_file' in build_info:
420-
log.warn("'def_file' element of build info dict " "no longer supported")
420+
log.warning(
421+
"'def_file' element of build info dict " "no longer supported"
422+
)
421423

422424
# Non-trivial stuff: 'macros' split into 'define_macros'
423425
# and 'undef_macros'.
@@ -601,7 +603,7 @@ def swig_sources(self, sources, extension):
601603
# the temp dir.
602604

603605
if self.swig_cpp:
604-
log.warn("--swig-cpp is deprecated - use --swig-opts=-c++")
606+
log.warning("--swig-cpp is deprecated - use --swig-opts=-c++")
605607

606608
if (
607609
self.swig_cpp

distutils/command/build_py.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..core import Command
1111
from ..errors import DistutilsOptionError, DistutilsFileError
1212
from ..util import convert_path
13-
from distutils import log
13+
from distutils._log import log
1414

1515

1616
class build_py(Command):
@@ -212,7 +212,7 @@ def check_package(self, package, package_dir):
212212

213213
def check_module(self, module, module_file):
214214
if not os.path.isfile(module_file):
215-
log.warn("file %s (for module %s) not found", module_file, module)
215+
log.warning("file %s (for module %s) not found", module_file, module)
216216
return False
217217
else:
218218
return True

distutils/command/build_scripts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from ..core import Command
1010
from ..dep_util import newer
1111
from ..util import convert_path
12-
from distutils import log
12+
from distutils._log import log
1313
import tokenize
1414

1515
shebang_pattern = re.compile('^#!.*python[0-9.]*([ \t].*)?$')

distutils/command/clean.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
from ..core import Command
99
from ..dir_util import remove_tree
10-
from distutils import log
10+
from distutils._log import log
1111

1212

1313
class clean(Command):
@@ -64,7 +64,7 @@ def run(self):
6464
if os.path.exists(directory):
6565
remove_tree(directory, dry_run=self.dry_run)
6666
else:
67-
log.warn("'%s' does not exist -- can't clean it", directory)
67+
log.warning("'%s' does not exist -- can't clean it", directory)
6868

6969
# just for the heck of it, try to remove the base build directory:
7070
# we might have emptied it right now, but if not we don't care

distutils/command/config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from ..core import Command
1616
from ..errors import DistutilsExecError
1717
from ..sysconfig import customize_compiler
18-
from distutils import log
18+
from distutils._log import log
1919

2020
LANG_EXT = {"c": ".c", "c++": ".cxx"}
2121

distutils/command/install.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import sysconfig
99
import itertools
1010

11-
from distutils import log
11+
from distutils._log import log
1212
from ..core import Command
1313
from ..debug import DEBUG
1414
from ..sysconfig import get_config_vars
@@ -644,7 +644,7 @@ def handle_extra_path(self):
644644
self.extra_path = self.distribution.extra_path
645645

646646
if self.extra_path is not None:
647-
log.warn(
647+
log.warning(
648648
"Distribution option extra_path is deprecated. "
649649
"See issue27919 for details."
650650
)

distutils/command/install_egg_info.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
import re
1111

1212
from ..cmd import Command
13-
from distutils import log, dir_util
13+
from .. import dir_util
14+
from .._log import log
1415

1516

1617
class install_egg_info(Command):

distutils/command/install_scripts.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import os
99
from ..core import Command
10-
from distutils import log
10+
from distutils._log import log
1111
from stat import ST_MODE
1212

1313

distutils/command/register.py

+9-7
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77

88
import getpass
99
import io
10+
import logging
1011
import urllib.parse
1112
import urllib.request
1213
from warnings import warn
1314

1415
from ..core import PyPIRCCommand
15-
from distutils import log
16+
from distutils._log import log
1617

1718

1819
class register(PyPIRCCommand):
@@ -153,7 +154,7 @@ def send_metadata(self): # noqa: C901
153154
3. have the server generate a new password for you (and email it to you), or
154155
4. quit
155156
Your selection [default 1]: ''',
156-
log.INFO,
157+
logging.INFO,
157158
)
158159
choice = input()
159160
if not choice:
@@ -174,7 +175,7 @@ def send_metadata(self): # noqa: C901
174175
auth.add_password(self.realm, host, username, password)
175176
# send the info to the server and report the result
176177
code, result = self.post_to_server(self.build_post_data('submit'), auth)
177-
self.announce('Server response ({}): {}'.format(code, result), log.INFO)
178+
self.announce('Server response ({}): {}'.format(code, result), logging.INFO)
178179

179180
# possibly save the login
180181
if code == 200:
@@ -188,11 +189,11 @@ def send_metadata(self): # noqa: C901
188189
'I can store your PyPI login so future '
189190
'submissions will be faster.'
190191
),
191-
log.INFO,
192+
logging.INFO,
192193
)
193194
self.announce(
194195
'(the login will be stored in %s)' % self._get_rc_file(),
195-
log.INFO,
196+
logging.INFO,
196197
)
197198
choice = 'X'
198199
while choice.lower() not in 'yn':
@@ -265,7 +266,8 @@ def post_to_server(self, data, auth=None): # noqa: C901
265266
'''Post a query to the server, and return a string response.'''
266267
if 'name' in data:
267268
self.announce(
268-
'Registering {} to {}'.format(data['name'], self.repository), log.INFO
269+
'Registering {} to {}'.format(data['name'], self.repository),
270+
logging.INFO,
269271
)
270272
# Build up the MIME payload for the urllib2 POST data
271273
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
@@ -315,5 +317,5 @@ def post_to_server(self, data, auth=None): # noqa: C901
315317
result = 200, 'OK'
316318
if self.show_response:
317319
msg = '\n'.join(('-' * 75, data, '-' * 75))
318-
self.announce(msg, log.INFO)
320+
self.announce(msg, logging.INFO)
319321
return result

0 commit comments

Comments
 (0)