Skip to content

Commit

Permalink
Sort imports for more consistent diff
Browse files Browse the repository at this point in the history
  • Loading branch information
Avasam committed May 23, 2024
1 parent 52d7324 commit 52a5043
Show file tree
Hide file tree
Showing 119 changed files with 535 additions and 586 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.1.8
rev: v0.4.5
hooks:
- id: ruff
- id: ruff-format
2 changes: 1 addition & 1 deletion _distutils_hack/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# don't import any costly modules
import sys
import os
import sys


def warn_distutils_present():
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
86 changes: 43 additions & 43 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,62 +22,60 @@

import sys

if sys.version_info < (3, 8):
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,
Callable,
Dict,
Iterable,
List,
Mapping,
MutableSequence,
NamedTuple,
NoReturn,
Optional,
Protocol,
Sequence,
Set,
Tuple,
Type,
Union,
TYPE_CHECKING,
List,
Protocol,
Callable,
Dict,
Iterable,
Optional,
TypeVar,
Union,
)
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

# 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

try:
from os import mkdir, rename, unlink
Expand All @@ -88,14 +86,16 @@
WRITE_SUPPORT = False

from pkg_resources.extern.jaraco.text import (
yield_lines,
drop_comment,
join_continuation,
yield_lines,
)
from pkg_resources.extern.packaging import (
markers as _packaging_markers,
requirements as _packaging_requirements,
utils as _packaging_utils,
version as _packaging_version,
)
from pkg_resources.extern.packaging import markers as _packaging_markers
from pkg_resources.extern.packaging import requirements as _packaging_requirements
from pkg_resources.extern.packaging import utils as _packaging_utils
from pkg_resources.extern.packaging import version as _packaging_version
from pkg_resources.extern.platformdirs import user_cache_dir as _user_cache_dir

if TYPE_CHECKING:
Expand Down Expand Up @@ -2680,7 +2680,7 @@ def parse_map(
_data = data.items()
else:
_data = split_sections(data)
maps: Dict[str, Dict[str, "EntryPoint"]] = {}
maps: Dict[str, Dict[str, EntryPoint]] = {}
for group, lines in _data:
if group is None:
if not lines:
Expand Down
2 changes: 1 addition & 1 deletion pkg_resources/extern/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from importlib.machinery import ModuleSpec
import importlib.util
import sys
from importlib.machinery import ModuleSpec
from types import ModuleType
from typing import Iterable, Optional, Sequence

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
22 changes: 8 additions & 14 deletions pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
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 typing import List

from unittest import mock

from pkg_resources import (
DistInfoDistribution,
Distribution,
EggInfoDistribution,
)

import pytest

import distutils.command.install_egg_info
import distutils.dist
import pkg_resources
from pkg_resources import DistInfoDistribution, Distribution, EggInfoDistribution


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

import pytest
from pkg_resources.extern.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,
)
from pkg_resources.extern.packaging.specifiers import SpecifierSet


# from Python 3.6 docs. Available from itertools on Python 3.10
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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ testing = [
"pytest-mypy",
"pytest-enabler >= 2.2",
# workaround for pypa/setuptools#3921
'pytest-ruff >= 0.2.1; sys_platform != "cygwin"',
'pytest-ruff >= 0.3.2; sys_platform != "cygwin"',

# local
"virtualenv>=13.0.0",
Expand Down
47 changes: 27 additions & 20 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
exclude = [
"**/_vendor",
"setuptools/_distutils",
"setuptools/config/_validate_pyproject",
]

[lint]
extend-select = [
"C901",
"W",

# local
"UP", # pyupgrade
"YTT", # flake8-2020
"I", # isort
"UP", # pyupgrade
"YTT", # flake8-2020
]
ignore = [
"UP015", # redundant-open-modes, explicit is preferred
"UP030", # temporarily disabled
"UP031", # temporarily disabled
"UP032", # temporarily disabled
"UP038", # Using `X | Y` in `isinstance` call is slower and more verbose https://github.com/astral-sh/ruff/issues/7871

# https://docs.astral.sh/ruff/formatter/#conflicting-lint-rules
"W191",
"E111",
Expand All @@ -24,26 +37,20 @@ ignore = [
"ISC001",
"ISC002",
]
extend-ignore = [
"UP015", # redundant-open-modes, explicit is preferred
"UP030", # temporarily disabled
"UP031", # temporarily disabled
"UP032", # temporarily disabled
"UP036", # temporarily disabled
]
exclude = [
"**/_vendor",
"setuptools/_distutils",
"setuptools/config/_validate_pyproject",
]

[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
known-third-party = ["setuptools"]
known-first-party = ["distutils"]
# Once support is dropped, move distutils to first-party as setuptools repo now owns it
# known-first-party = ["distutils"]

[format]
exclude = [
"**/_vendor",
"setuptools/_distutils",
"setuptools/config/_validate_pyproject",
]
# Enable preview, required for quote-style = "preserve"
# Enable preview to get hugged parenthesis unwrapping
preview = true
# https://docs.astral.sh/ruff/settings/#format-quote-style
quote-style = "preserve"
3 changes: 1 addition & 2 deletions setuptools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
import distutils.core
from distutils.errors import DistutilsOptionError

from . import logging, monkey
from . import version as _version_module
from . import logging, monkey, version as _version_module
from .depends import Require
from .discovery import PackageFinder, PEP420PackageFinder
from .dist import Distribution
Expand Down
2 changes: 1 addition & 1 deletion setuptools/_core_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from email import message_from_file
from email.message import Message
from tempfile import NamedTemporaryFile
from typing import Optional, List
from typing import List, Optional

from distutils.util import rfc822_escape

Expand Down
8 changes: 4 additions & 4 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
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
Loading

0 comments on commit 52a5043

Please sign in to comment.