Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with distutils at e0787fa #3674

Merged
merged 33 commits into from Nov 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b953665
Remove docstring in distutils
jaraco Oct 4, 2022
a3fcf97
Prefer partition for splitting a string.
jaraco Oct 4, 2022
bf3e726
Remove readme
jaraco Oct 4, 2022
74090e3
Prefer relative imports for better portability.
jaraco Oct 4, 2022
b9cd85a
No need to save 'threshold' on the instance.
jaraco Oct 4, 2022
886dcda
Use monkeypatch to set log and threshold.
jaraco Oct 4, 2022
21f2f14
Extract fixture for capturing logs in _util modules.
jaraco Oct 4, 2022
a1e48e7
Expand 'logs' fixture to support features needed by LoggingSilencer.
jaraco Oct 4, 2022
e615a4d
Consolidate fixture for capturing logs. Removes LoggingSilencer.
jaraco Oct 4, 2022
ce8692d
Prefer capsys to test.support.captured*
jaraco Oct 5, 2022
d0bfcdb
Fix broken test
jaraco Oct 5, 2022
45295fc
Prefer caplog to mocking the logging interface.
jaraco Oct 5, 2022
27217ad
or maybe not
jaraco Oct 29, 2022
060fec6
Remove setting of dll_libraries in Mingw32CCompiler. One call superse…
jaraco Oct 29, 2022
ff69195
Short circuit when MSC version is not found.
jaraco Oct 29, 2022
855475e
Prefer partition to find.
jaraco Oct 29, 2022
3868aad
Work with ints uniformally.
jaraco Oct 29, 2022
347eba0
Replace if/else with a lookup.
jaraco Oct 29, 2022
a8ebe3f
Move lookup out of the function
jaraco Oct 29, 2022
15266db
Prefer regex search to string manipulation.
jaraco Oct 29, 2022
c5f0b27
Use RangeMap to define the ranges in one place.
jaraco Oct 29, 2022
6c39b50
Use try/except when assigning msc_ver.
jaraco Oct 29, 2022
b37f867
👹 Feed the hobgoblins (delint).
jaraco Oct 29, 2022
e414cdf
Re-paste RangeMap with newlines restored (unsure what made them disap…
jaraco Oct 29, 2022
01ce88b
Pin pytest to <7.2. Workaround for pypa/distutils#186.
jaraco Oct 29, 2022
85df0b2
In TempdirManager, use pathlib and more_itertools to more simply writ…
jaraco Oct 29, 2022
f95d384
Rewrite init/for/append loop as comprehension and if/else as tertiary…
jaraco Nov 3, 2022
74652ca
Replace bespoke logging facility with logging module, available since…
jaraco Oct 5, 2022
8e5842a
Avoid use of the distutils.log module.
jaraco Oct 5, 2022
d763948
Log to the root logger, as that's the one Setuptools patches/validates.
jaraco Oct 6, 2022
e0787fa
Merge pull request #183 from pypa/debt/logging
jaraco Nov 13, 2022
9b8a6ef
Merge https://github.com/pypa/distutils into distutils-e0787fa
jaraco Nov 13, 2022
e034926
Update changelog.
jaraco Nov 13, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3674.change.rst
@@ -0,0 +1 @@
Sync with pypa/distutils@e0787fa, including pypa/distutils#183 updating distutils to use the Python logging framework.
11 changes: 0 additions & 11 deletions setuptools/_distutils/README

This file was deleted.

12 changes: 1 addition & 11 deletions setuptools/_distutils/__init__.py
@@ -1,17 +1,7 @@
"""distutils

The main package for the Python Module Distribution Utilities. Normally
used from a setup script as

from distutils.core import setup

setup (...)
"""

import sys
import importlib

__version__ = sys.version[: sys.version.index(' ')]
__version__, _, _ = sys.version.partition(' ')


try:
Expand Down
138 changes: 138 additions & 0 deletions setuptools/_distutils/_collections.py
@@ -1,5 +1,7 @@
import collections
import functools
import itertools
import operator


# from jaraco.collections 3.5.1
Expand Down Expand Up @@ -54,3 +56,139 @@ def __contains__(self, other):

def __len__(self):
return len(list(iter(self)))


# from jaraco.collections 3.7
class RangeMap(dict):
"""
A dictionary-like object that uses the keys as bounds for a range.
Inclusion of the value for that range is determined by the
key_match_comparator, which defaults to less-than-or-equal.
A value is returned for a key if it is the first key that matches in
the sorted list of keys.

One may supply keyword parameters to be passed to the sort function used
to sort keys (i.e. key, reverse) as sort_params.

Let's create a map that maps 1-3 -> 'a', 4-6 -> 'b'

>>> r = RangeMap({3: 'a', 6: 'b'}) # boy, that was easy
>>> r[1], r[2], r[3], r[4], r[5], r[6]
('a', 'a', 'a', 'b', 'b', 'b')

Even float values should work so long as the comparison operator
supports it.

>>> r[4.5]
'b'

But you'll notice that the way rangemap is defined, it must be open-ended
on one side.

>>> r[0]
'a'
>>> r[-1]
'a'

One can close the open-end of the RangeMap by using undefined_value

>>> r = RangeMap({0: RangeMap.undefined_value, 3: 'a', 6: 'b'})
>>> r[0]
Traceback (most recent call last):
...
KeyError: 0

One can get the first or last elements in the range by using RangeMap.Item

>>> last_item = RangeMap.Item(-1)
>>> r[last_item]
'b'

.last_item is a shortcut for Item(-1)

>>> r[RangeMap.last_item]
'b'

Sometimes it's useful to find the bounds for a RangeMap

>>> r.bounds()
(0, 6)

RangeMap supports .get(key, default)

>>> r.get(0, 'not found')
'not found'

>>> r.get(7, 'not found')
'not found'

One often wishes to define the ranges by their left-most values,
which requires use of sort params and a key_match_comparator.

>>> r = RangeMap({1: 'a', 4: 'b'},
... sort_params=dict(reverse=True),
... key_match_comparator=operator.ge)
>>> r[1], r[2], r[3], r[4], r[5], r[6]
('a', 'a', 'a', 'b', 'b', 'b')

That wasn't nearly as easy as before, so an alternate constructor
is provided:

>>> r = RangeMap.left({1: 'a', 4: 'b', 7: RangeMap.undefined_value})
>>> r[1], r[2], r[3], r[4], r[5], r[6]
('a', 'a', 'a', 'b', 'b', 'b')

"""

def __init__(self, source, sort_params={}, key_match_comparator=operator.le):
dict.__init__(self, source)
self.sort_params = sort_params
self.match = key_match_comparator

@classmethod
def left(cls, source):
return cls(
source, sort_params=dict(reverse=True), key_match_comparator=operator.ge
)

def __getitem__(self, item):
sorted_keys = sorted(self.keys(), **self.sort_params)
if isinstance(item, RangeMap.Item):
result = self.__getitem__(sorted_keys[item])
else:
key = self._find_first_match_(sorted_keys, item)
result = dict.__getitem__(self, key)
if result is RangeMap.undefined_value:
raise KeyError(key)
return result

def get(self, key, default=None):
"""
Return the value for key if key is in the dictionary, else default.
If default is not given, it defaults to None, so that this method
never raises a KeyError.
"""
try:
return self[key]
except KeyError:
return default

def _find_first_match_(self, keys, item):
is_match = functools.partial(self.match, item)
matches = list(filter(is_match, keys))
if matches:
return matches[0]
raise KeyError(item)

def bounds(self):
sorted_keys = sorted(self.keys(), **self.sort_params)
return (sorted_keys[RangeMap.first_item], sorted_keys[RangeMap.last_item])

# some special values for the RangeMap
undefined_value = type(str('RangeValueUndefined'), (), {})()

class Item(int):
"RangeMap Item"

first_item = Item(0)
last_item = Item(-1)
4 changes: 4 additions & 0 deletions setuptools/_distutils/_log.py
@@ -0,0 +1,4 @@
import logging


log = logging.getLogger()
8 changes: 4 additions & 4 deletions setuptools/_distutils/_msvccompiler.py
Expand Up @@ -22,16 +22,16 @@
with contextlib.suppress(ImportError):
import winreg

from distutils.errors import (
from .errors import (
DistutilsExecError,
DistutilsPlatformError,
CompileError,
LibError,
LinkError,
)
from distutils.ccompiler import CCompiler, gen_lib_options
from distutils import log
from distutils.util import get_platform
from .ccompiler import CCompiler, gen_lib_options
from ._log import log
from .util import get_platform

from itertools import count

Expand Down
8 changes: 4 additions & 4 deletions setuptools/_distutils/archive_util.py
Expand Up @@ -13,10 +13,10 @@
zipfile = None


from distutils.errors import DistutilsExecError
from distutils.spawn import spawn
from distutils.dir_util import mkpath
from distutils import log
from .errors import DistutilsExecError
from .spawn import spawn
from .dir_util import mkpath
from ._log import log

try:
from pwd import getpwnam
Expand Down
12 changes: 6 additions & 6 deletions setuptools/_distutils/bcppcompiler.py
Expand Up @@ -15,17 +15,17 @@
import os
import warnings

from distutils.errors import (
from .errors import (
DistutilsExecError,
CompileError,
LibError,
LinkError,
UnknownFileError,
)
from distutils.ccompiler import CCompiler, gen_preprocess_options
from distutils.file_util import write_file
from distutils.dep_util import newer
from distutils import log
from .ccompiler import CCompiler, gen_preprocess_options
from .file_util import write_file
from .dep_util import newer
from ._log import log


warnings.warn(
Expand Down Expand Up @@ -210,7 +210,7 @@ def link( # noqa: C901
)

if runtime_library_dirs:
log.warn(
log.warning(
"I don't know what to do with 'runtime_library_dirs': %s",
str(runtime_library_dirs),
)
Expand Down
14 changes: 7 additions & 7 deletions setuptools/_distutils/ccompiler.py
Expand Up @@ -7,19 +7,19 @@
import os
import re

from distutils.errors import (
from .errors import (
CompileError,
LinkError,
UnknownFileError,
DistutilsPlatformError,
DistutilsModuleError,
)
from distutils.spawn import spawn
from distutils.file_util import move_file
from distutils.dir_util import mkpath
from distutils.dep_util import newer_group
from distutils.util import split_quoted, execute
from distutils import log
from .spawn import spawn
from .file_util import move_file
from .dir_util import mkpath
from .dep_util import newer_group
from .util import split_quoted, execute
from ._log import log


class CCompiler:
Expand Down
19 changes: 9 additions & 10 deletions setuptools/_distutils/cmd.py
Expand Up @@ -7,9 +7,11 @@
import sys
import os
import re
from distutils.errors import DistutilsOptionError
from distutils import util, dir_util, file_util, archive_util, dep_util
from distutils import log
import logging

from .errors import DistutilsOptionError
from . import util, dir_util, file_util, archive_util, dep_util
from ._log import log


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

if header is None:
header = "command options for '%s':" % self.get_command_name()
self.announce(indent + header, level=log.INFO)
self.announce(indent + header, level=logging.INFO)
indent = indent + " "
for (option, _, _) in self.user_options:
option = option.translate(longopt_xlate)
if option[-1] == "=":
option = option[:-1]
value = getattr(self, option)
self.announce(indent + "{} = {}".format(option, value), level=log.INFO)
self.announce(indent + "{} = {}".format(option, value), level=logging.INFO)

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

def announce(self, msg, level=1):
"""If the current verbosity level is of greater than or equal to
'level' print 'msg' to stdout.
"""
def announce(self, msg, level=logging.DEBUG):
log.log(level, msg)

def debug_print(self, msg):
Expand Down Expand Up @@ -334,7 +333,7 @@ def get_sub_commands(self):
# -- External world manipulation -----------------------------------

def warn(self, msg):
log.warn("warning: %s: %s\n", self.get_command_name(), msg)
log.warning("warning: %s: %s\n", self.get_command_name(), msg)

def execute(self, func, args, msg=None, level=1):
util.execute(func, args, msg, dry_run=self.dry_run)
Expand Down
8 changes: 4 additions & 4 deletions setuptools/_distutils/command/bdist.py
Expand Up @@ -6,14 +6,14 @@
import os
import warnings

from distutils.core import Command
from distutils.errors import DistutilsPlatformError, DistutilsOptionError
from distutils.util import get_platform
from ..core import Command
from ..errors import DistutilsPlatformError, DistutilsOptionError
from ..util import get_platform


def show_formats():
"""Print list of available formats (arguments to "--format" option)."""
from distutils.fancy_getopt import FancyGetopt
from ..fancy_getopt import FancyGetopt

formats = []
for format in bdist.format_commands:
Expand Down
12 changes: 6 additions & 6 deletions setuptools/_distutils/command/bdist_dumb.py
Expand Up @@ -5,12 +5,12 @@
$exec_prefix)."""

import os
from distutils.core import Command
from distutils.util import get_platform
from distutils.dir_util import remove_tree, ensure_relative
from distutils.errors import DistutilsPlatformError
from distutils.sysconfig import get_python_version
from distutils import log
from ..core import Command
from ..util import get_platform
from ..dir_util import remove_tree, ensure_relative
from ..errors import DistutilsPlatformError
from ..sysconfig import get_python_version
from distutils._log import log


class bdist_dumb(Command):
Expand Down
12 changes: 6 additions & 6 deletions setuptools/_distutils/command/bdist_rpm.py
Expand Up @@ -7,17 +7,17 @@
import sys
import os

from distutils.core import Command
from distutils.debug import DEBUG
from distutils.file_util import write_file
from distutils.errors import (
from ..core import Command
from ..debug import DEBUG
from ..file_util import write_file
from ..errors import (
DistutilsOptionError,
DistutilsPlatformError,
DistutilsFileError,
DistutilsExecError,
)
from distutils.sysconfig import get_python_version
from distutils import log
from ..sysconfig import get_python_version
from distutils._log import log


class bdist_rpm(Command):
Expand Down