Skip to content

Commit

Permalink
Black and iSort
Browse files Browse the repository at this point in the history
  • Loading branch information
rickprice committed Nov 8, 2024
1 parent 7fe9953 commit ca754ab
Show file tree
Hide file tree
Showing 28 changed files with 456 additions and 418 deletions.
18 changes: 7 additions & 11 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,21 @@
"""Extensions to the 'distutils' for large or complex distributions"""

import distutils.core
import functools
import os
import re

import _distutils_hack.override # noqa: F401

import distutils.core
from distutils.errors import DistutilsOptionError
from distutils.util import convert_path as _convert_path

from .warnings import SetuptoolsDeprecationWarning

import _distutils_hack.override # noqa: F401
import setuptools.version
from setuptools.extension import Extension
from setuptools.dist import Distribution
from setuptools.depends import Require
from setuptools.discovery import PackageFinder, PEP420PackageFinder
from . import monkey
from . import logging
from setuptools.dist import Distribution
from setuptools.extension import Extension

from . import logging, monkey
from .warnings import SetuptoolsDeprecationWarning

__all__ = [
'setup',
Expand Down Expand Up @@ -257,7 +253,7 @@ def convert_path(pathname):
Its direct usage by 3rd-party packages is considered improper and the function
may be removed in the future.
""",
due_date=(2023, 12, 13) # initial deprecation 2022-03-25, see #3201
due_date=(2023, 12, 13), # initial deprecation 2022-03-25, see #3201
)
return _convert_path(pathname)

Expand Down
22 changes: 8 additions & 14 deletions setuptools/_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import functools
import operator
import itertools
import operator

from .errors import OptionError
from .extern.jaraco.text import yield_lines
from .extern.jaraco.functools import pass_none
from ._importlib import metadata
from ._itertools import ensure_unique
from .errors import OptionError
from .extern.jaraco.functools import pass_none
from .extern.jaraco.text import yield_lines
from .extern.more_itertools import consume


Expand Down Expand Up @@ -54,8 +54,8 @@ def load(eps):
Given a Distribution.entry_points, produce EntryPoints.
"""
groups = itertools.chain.from_iterable(
load_group(value, group)
for group, value in eps.items())
load_group(value, group) for group, value in eps.items()
)
return validate(metadata.EntryPoints(groups))


Expand All @@ -81,14 +81,8 @@ def render(eps: metadata.EntryPoints):
by_group = operator.attrgetter('group')
groups = itertools.groupby(sorted(eps, key=by_group), by_group)

return '\n'.join(
f'[{group}]\n{render_items(items)}\n'
for group, items in groups
)
return '\n'.join(f'[{group}]\n{render_items(items)}\n' for group, items in groups)


def render_items(eps):
return '\n'.join(
f'{ep.name} = {ep.value}'
for ep in sorted(eps)
)
return '\n'.join(f'{ep.name} = {ep.value}' for ep in sorted(eps))
24 changes: 14 additions & 10 deletions setuptools/_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,11 @@
from the deprecated imp module.
"""

import os
import importlib.util
import importlib.machinery

import importlib.util
import os
from importlib.util import module_from_spec


PY_SOURCE = 1
PY_COMPILED = 2
C_EXTENSION = 3
Expand All @@ -20,8 +18,8 @@
def find_spec(module, paths):
finder = (
importlib.machinery.PathFinder().find_spec
if isinstance(paths, list) else
importlib.util.find_spec
if isinstance(paths, list)
else importlib.util.find_spec
)
return finder(module, paths)

Expand All @@ -37,13 +35,19 @@ def find_module(module, paths=None):
kind = -1
file = None
static = isinstance(spec.loader, type)
if spec.origin == 'frozen' or static and issubclass(
spec.loader, importlib.machinery.FrozenImporter):
if (
spec.origin == 'frozen'
or static
and issubclass(spec.loader, importlib.machinery.FrozenImporter)
):
kind = PY_FROZEN
path = None # imp compabilty
suffix = mode = '' # imp compatibility
elif spec.origin == 'built-in' or static and issubclass(
spec.loader, importlib.machinery.BuiltinImporter):
elif (
spec.origin == 'built-in'
or static
and issubclass(spec.loader, importlib.machinery.BuiltinImporter)
):
kind = C_BUILTIN
path = None # imp compabilty
suffix = mode = '' # imp compatibility
Expand Down
3 changes: 2 additions & 1 deletion setuptools/_importlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def disable_importlib_metadata_finder(metadata):
This problem is likely to be solved by installing an updated version of
`importlib-metadata`.
""",
see_url="https://github.com/python/importlib_metadata/issues/396"
see_url="https://github.com/python/importlib_metadata/issues/396",
) # Ensure a descriptive message is shown.
raise # This exception can be suppressed by _distutils_hack

Expand All @@ -39,6 +39,7 @@ def disable_importlib_metadata_finder(metadata):

if sys.version_info < (3, 10):
from setuptools.extern import importlib_metadata as metadata

disable_importlib_metadata_finder(metadata)
else:
import importlib.metadata as metadata # noqa: F401
Expand Down
1 change: 1 addition & 0 deletions setuptools/_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Helpers for normalization as expected in wheel/sdist/module file names
and core metadata
"""

import re
from pathlib import Path
from typing import Union
Expand Down
6 changes: 2 additions & 4 deletions setuptools/_reqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@ def parse_strings(strs: _StrOrIter) -> Iterator[str]:


@overload
def parse(strs: _StrOrIter) -> Iterator[Requirement]:
...
def parse(strs: _StrOrIter) -> Iterator[Requirement]: ...


@overload
def parse(strs: _StrOrIter, parser: Callable[[str], _T]) -> Iterator[_T]:
...
def parse(strs: _StrOrIter, parser: Callable[[str], _T]) -> Iterator[_T]: ...


def parse(strs, parser=Requirement):
Expand Down
39 changes: 21 additions & 18 deletions setuptools/archive_util.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,23 @@
"""Utilities for extracting common archive formats"""

import zipfile
import tarfile
import contextlib
import os
import shutil
import posixpath
import contextlib
import shutil
import tarfile
import zipfile
from distutils.errors import DistutilsError

from ._path import ensure_directory

__all__ = [
"unpack_archive", "unpack_zipfile", "unpack_tarfile", "default_filter",
"UnrecognizedFormat", "extraction_drivers", "unpack_directory",
"unpack_archive",
"unpack_zipfile",
"unpack_tarfile",
"default_filter",
"UnrecognizedFormat",
"extraction_drivers",
"unpack_directory",
]


Expand All @@ -25,9 +30,7 @@ def default_filter(src, dst):
return dst


def unpack_archive(
filename, extract_dir, progress_filter=default_filter,
drivers=None):
def unpack_archive(filename, extract_dir, progress_filter=default_filter, drivers=None):
"""Unpack `filename` to `extract_dir`, or raise ``UnrecognizedFormat``
`progress_filter` is a function taking two arguments: a source path
Expand Down Expand Up @@ -56,13 +59,11 @@ def unpack_archive(
else:
return
else:
raise UnrecognizedFormat(
"Not a recognized archive type: %s" % filename
)
raise UnrecognizedFormat("Not a recognized archive type: %s" % filename)


def unpack_directory(filename, extract_dir, progress_filter=default_filter):
""""Unpack" a directory, using the same interface as for archives
""" "Unpack" a directory, using the same interface as for archives
Raises ``UnrecognizedFormat`` if `filename` is not a directory
"""
Expand Down Expand Up @@ -136,17 +137,17 @@ def _unpack_zipfile_obj(zipfile_obj, extract_dir, progress_filter=default_filter
def _resolve_tar_file_or_dir(tar_obj, tar_member_obj):
"""Resolve any links and extract link targets as normal files."""
while tar_member_obj is not None and (
tar_member_obj.islnk() or tar_member_obj.issym()):
tar_member_obj.islnk() or tar_member_obj.issym()
):
linkpath = tar_member_obj.linkname
if tar_member_obj.issym():
base = posixpath.dirname(tar_member_obj.name)
linkpath = posixpath.join(base, linkpath)
linkpath = posixpath.normpath(linkpath)
tar_member_obj = tar_obj._getmember(linkpath)

is_file_or_dir = (
tar_member_obj is not None and
(tar_member_obj.isfile() or tar_member_obj.isdir())
is_file_or_dir = tar_member_obj is not None and (
tar_member_obj.isfile() or tar_member_obj.isdir()
)
if is_file_or_dir:
return tar_member_obj
Expand Down Expand Up @@ -198,7 +199,9 @@ def unpack_tarfile(filename, extract_dir, progress_filter=default_filter):
) from e

for member, final_dst in _iter_open_tar(
tarobj, extract_dir, progress_filter,
tarobj,
extract_dir,
progress_filter,
):
try:
# XXX Ugh
Expand Down
Loading

0 comments on commit ca754ab

Please sign in to comment.