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

Sort imports for more consistent diff (ruff/isort) #4392

Merged
merged 2 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# don't import any costly modules
import sys
import os

import sys

report_url = (
"https://github.com/pypa/setuptools/issues/new?"
Expand Down
1 change: 0 additions & 1 deletion conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import pytest


pytest_plugins = 'setuptools.tests.fixtures'


Expand Down
76 changes: 35 additions & 41 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,68 +22,66 @@

from __future__ import annotations

from abc import ABC
import sys
from abc import ABC

if sys.version_info < (3, 8): # noqa: UP036 # Check for unsupported versions
raise RuntimeError("Python 3.8 or later is required")

import os
import _imp
import collections
import email.parser
import errno
import functools
import importlib
import importlib.abc
import importlib.machinery
import inspect
import io
import time
import ntpath
import operator
import os
import pkgutil
import platform
import plistlib
import posixpath
import re
import stat
import tempfile
import textwrap
import time
import types
import warnings
import zipfile
import zipimport
from pkgutil import get_importer
from typing import (
TYPE_CHECKING,
Any,
BinaryIO,
Literal,
Callable,
Dict,
Iterable,
Iterator,
Literal,
Mapping,
MutableSequence,
NamedTuple,
NoReturn,
Tuple,
Union,
TYPE_CHECKING,
Protocol,
Callable,
Iterable,
Tuple,
TypeVar,
Union,
overload,
)
import zipfile
import zipimport
import warnings
import stat
import functools
import pkgutil
import operator
import platform
import collections
import plistlib
import email.parser
import errno
import tempfile
import textwrap
import inspect
import ntpath
import posixpath
import importlib
import importlib.abc
import importlib.machinery
from pkgutil import get_importer

import _imp

sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip
# workaround for #4476
sys.modules.pop('backports', None)

# capture these to bypass sandboxing
from os import utime
from os import open as os_open
from os.path import isdir, split
from os import open as os_open, utime # isort: skip
from os.path import isdir, split # isort: skip
Comment on lines +83 to +84
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is not automated


try:
from os import mkdir, rename, unlink
Expand All @@ -93,20 +91,16 @@
# no write support, probably under GAE
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question that doesn't affect this PR: What's GAE ?

Copy link
Contributor

@abravalheri abravalheri Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Google App Engine? I don't know... the change is from 2009, before setuptools moved to Github and unfortunatelly all references to issues/PR have been messed up.

Copy link
Contributor Author

@Avasam Avasam Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WRITE_SUPPORT = False

from jaraco.text import (
yield_lines,
drop_comment,
join_continuation,
)
import packaging.markers
import packaging.requirements
import packaging.specifiers
import packaging.utils
import packaging.version
from jaraco.text import drop_comment, join_continuation, yield_lines
from platformdirs import user_cache_dir as _user_cache_dir

if TYPE_CHECKING:
from _typeshed import BytesPath, StrPath, StrOrBytesPath
from _typeshed import BytesPath, StrOrBytesPath, StrPath
from typing_extensions import Self, TypeAlias

warnings.warn(
Expand Down
5 changes: 3 additions & 2 deletions pkg_resources/tests/test_find_distributions.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from pathlib import Path
import shutil
from pathlib import Path

import pytest
import pkg_resources

import pkg_resources

TESTS_DATA_DIR = Path(__file__).parent / 'data'

Expand Down
23 changes: 9 additions & 14 deletions pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
from __future__ import annotations

import builtins
import sys
import tempfile
import os
import zipfile
import datetime
import os
import plistlib
import subprocess
import stat
import distutils.dist
import distutils.command.install_egg_info

import subprocess
import sys
import tempfile
import zipfile
from unittest import mock

from pkg_resources import (
DistInfoDistribution,
Distribution,
EggInfoDistribution,
)

import pytest

import pkg_resources
from pkg_resources import DistInfoDistribution, Distribution, EggInfoDistribution

import distutils.command.install_egg_info
import distutils.dist


class EggRemover(str):
Expand Down
18 changes: 9 additions & 9 deletions pkg_resources/tests/test_resources.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import itertools
import os
import sys
import string
import platform
import itertools
import string
import sys

import pytest
from packaging.specifiers import SpecifierSet

import pkg_resources
from pkg_resources import (
parse_requirements,
VersionConflict,
parse_version,
Distribution,
EntryPoint,
Requirement,
safe_version,
safe_name,
VersionConflict,
WorkingSet,
parse_requirements,
parse_version,
safe_name,
safe_version,
)


Expand Down Expand Up @@ -862,8 +862,8 @@ def test_path_order(self, symlinked_tmpdir):
(subpkg / '__init__.py').write_text(vers_str % number, encoding='utf-8')

with pytest.warns(DeprecationWarning, match="pkg_resources.declare_namespace"):
import nspkg.subpkg
import nspkg
import nspkg.subpkg
expected = [str(site.realpath() / 'nspkg') for site in site_dirs]
assert nspkg.__path__ == expected
assert nspkg.subpkg.__version__ == 1
2 changes: 1 addition & 1 deletion pkg_resources/tests/test_working_set.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
import inspect
import re
import textwrap
import functools

import pytest

Expand Down
11 changes: 11 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ extend-select = [
"ANN2", # missing-return-type-*
"FA", # flake8-future-annotations
"F404", # late-future-import
"I", # isort
"PYI", # flake8-pyi
"UP", # pyupgrade
"TRY",
Expand Down Expand Up @@ -56,6 +57,16 @@ ignore = [
"setuptools/__init__.py" = ["E402"]
"pkg_resources/__init__.py" = ["E402"]

[lint.isort]
combine-as-imports = true
split-on-trailing-comma = false
# Force Ruff/isort to always import setuptools before distutils in tests as long as distutils_hack is supported
# This also ensures _distutils_hack is imported before distutils
# https://github.com/pypa/setuptools/issues/4137
section-order = ["future", "standard-library", "eager", "third-party", "first-party", "local-folder", "delayed"]
sections.eager = ["_distutils_hack"]
sections.delayed = ["distutils"]

[lint.flake8-annotations]
ignore-fully-untyped = true

Expand Down
10 changes: 5 additions & 5 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,30 @@

from __future__ import annotations

from abc import ABC, abstractmethod
import functools
import os
import re
import sys
from abc import ABC, abstractmethod
from typing import TYPE_CHECKING, TypeVar, overload


sys.path.extend(((vendor_path := os.path.join(os.path.dirname(os.path.dirname(__file__)), 'setuptools', '_vendor')) not in sys.path) * [vendor_path]) # fmt: skip
# workaround for #4476
sys.modules.pop('backports', None)

import _distutils_hack.override # noqa: F401
import distutils.core
from distutils.errors import DistutilsOptionError

from . import logging, monkey
from .version import __version__ as __version__
from .depends import Require
from .discovery import PackageFinder, PEP420PackageFinder
from .dist import Distribution
from .extension import Extension
from .version import __version__ as __version__
from .warnings import SetuptoolsDeprecationWarning

import distutils.core
from distutils.errors import DistutilsOptionError

__all__ = [
'setup',
'Distribution',
Expand Down
7 changes: 4 additions & 3 deletions setuptools/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@
from email.message import Message
from tempfile import NamedTemporaryFile

from distutils.util import rfc822_escape

from . import _normalization, _reqs
from packaging.markers import Marker
from packaging.requirements import Requirement
from packaging.utils import canonicalize_name, canonicalize_version
from packaging.version import Version

from . import _normalization, _reqs
from .warnings import SetuptoolsDeprecationWarning

from distutils.util import rfc822_escape


def get_metadata_version(self):
mv = getattr(self, 'metadata_version', None)
Expand Down
9 changes: 5 additions & 4 deletions setuptools/_entry_points.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import functools
import operator
import itertools
import operator

from .errors import OptionError
from jaraco.text import yield_lines
from jaraco.functools import pass_none
from jaraco.text import yield_lines
from more_itertools import consume

from ._importlib import metadata
from ._itertools import ensure_unique
from more_itertools import consume
from .errors import OptionError


def ensure_valid(ep):
Expand Down
6 changes: 2 additions & 4 deletions setuptools/_imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
from the deprecated imp module.
"""

import os
import importlib.util
import importlib.machinery
import importlib.util
import os
import tokenize

from importlib.util import module_from_spec


PY_SOURCE = 1
PY_COMPILED = 2
C_EXTENSION = 3
Expand Down
1 change: 0 additions & 1 deletion setuptools/_importlib.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys


if sys.version_info < (3, 10):
import importlib_metadata as metadata # pragma: no cover
else:
Expand Down
3 changes: 1 addition & 2 deletions setuptools/_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import contextlib
import os
import sys
from typing import Union, TYPE_CHECKING
from typing import TYPE_CHECKING, Union

if TYPE_CHECKING:
from typing_extensions import TypeAlias


from more_itertools import unique_everseen


if sys.version_info >= (3, 9):
StrPath: TypeAlias = Union[str, os.PathLike[str]] # Same as _typeshed.StrPath
else:
Expand Down
3 changes: 2 additions & 1 deletion setuptools/_reqs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from __future__ import annotations

from functools import lru_cache
from typing import Callable, Iterable, Iterator, TypeVar, Union, overload, TYPE_CHECKING
from typing import TYPE_CHECKING, Callable, Iterable, Iterator, TypeVar, Union, overload

import jaraco.text as text
from packaging.requirements import Requirement

Expand Down
Loading
Loading