From 24bc16f515fdb3bdf74a62cac0d40413eeb186fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Tue, 7 Oct 2025 22:38:06 +0200 Subject: [PATCH] Remove the `setuptools` plugin --- README.md | 7 --- docs/configuration/setuptools_integration.md | 27 --------- isort/setuptools_commands.py | 63 -------------------- pyproject.toml | 7 --- tests/unit/test_importable.py | 1 - tests/unit/test_setuptools_command.py | 32 ---------- uv.lock | 32 +--------- 7 files changed, 2 insertions(+), 167 deletions(-) delete mode 100644 docs/configuration/setuptools_integration.md delete mode 100644 isort/setuptools_commands.py delete mode 100644 tests/unit/test_setuptools_command.py diff --git a/README.md b/README.md index b0da18ca2..2bb857855 100644 --- a/README.md +++ b/README.md @@ -275,13 +275,6 @@ pre-commit script to check Python code before committing. [More info here.](https://pycqa.github.io/isort/docs/configuration/git_hook.html) -## Setuptools integration - -Upon installation, isort enables a `setuptools` command that checks -Python files declared by your project. - -[More info here.](https://pycqa.github.io/isort/docs/configuration/setuptools_integration.html) - ## Spread the word [![Imports: isort](https://img.shields.io/badge/%20imports-isort-%231674b1?style=flat&labelColor=ef8336)](https://pycqa.github.io/isort/) diff --git a/docs/configuration/setuptools_integration.md b/docs/configuration/setuptools_integration.md deleted file mode 100644 index ca2dbe568..000000000 --- a/docs/configuration/setuptools_integration.md +++ /dev/null @@ -1,27 +0,0 @@ -# Setuptools integration - -Upon installation, isort enables a `setuptools` command that checks -Python files declared by your project. - -Running `python setup.py isort` on the command line will check the files -listed in your `py_modules` and `packages`. If any warning is found, the -command will exit with an error code: - -```bash -$ python setup.py isort -``` - -Also, to allow users to be able to use the command without having to -install isort themselves, add isort to the setup\_requires of your -`setup()` like so: - -```python -setup( - name="project", - packages=["project"], - - setup_requires=[ - "isort" - ] -) -``` diff --git a/isort/setuptools_commands.py b/isort/setuptools_commands.py deleted file mode 100644 index 3e6cc2ea9..000000000 --- a/isort/setuptools_commands.py +++ /dev/null @@ -1,63 +0,0 @@ -import glob -import os -import sys -from collections.abc import Iterator -from typing import Any -from warnings import warn - -import setuptools - -from . import api -from .settings import DEFAULT_CONFIG - - -class ISortCommand(setuptools.Command): - """The :class:`ISortCommand` class is used by setuptools to perform - imports checks on registered modules. - """ - - description = "Run isort on modules registered in setuptools" - # Potentially unused variable - check if can be safely removed - user_options: list[Any] = [] # type: ignore[misc] - - def initialize_options(self) -> None: - default_settings = vars(DEFAULT_CONFIG).copy() - for key, value in default_settings.items(): - setattr(self, key, value) - - def finalize_options(self) -> None: - """Get options from config files.""" - self.arguments: dict[str, Any] = {} # skipcq: PYL-W0201 - self.arguments["settings_path"] = os.getcwd() - - def distribution_files(self) -> Iterator[str]: - """Find distribution packages.""" - # This is verbatim from flake8 - if self.distribution.packages: # pragma: no cover - package_dirs = self.distribution.package_dir or {} - for package in self.distribution.packages: - pkg_dir = package - if package in package_dirs: - pkg_dir = package_dirs[package] - elif "" in package_dirs: # pragma: no cover - pkg_dir = package_dirs[""] + os.path.sep + pkg_dir - yield pkg_dir.replace(".", os.path.sep) - - if self.distribution.py_modules: - for filename in self.distribution.py_modules: - yield f"{filename}.py" - # Don't miss the setup.py file itself - yield "setup.py" - - def run(self) -> None: - arguments = self.arguments - wrong_sorted_files = False - for path in self.distribution_files(): - for python_file in glob.iglob(os.path.join(path, "*.py")): - try: - if not api.check_file(python_file, **arguments): - wrong_sorted_files = True # pragma: no cover - except OSError as error: # pragma: no cover - warn(f"Unable to parse file {python_file} due to {error}", stacklevel=2) - if wrong_sorted_files: - sys.exit(1) # pragma: no cover diff --git a/pyproject.toml b/pyproject.toml index 2c5f17215..f6ba3c319 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,12 +53,8 @@ local_scheme = "no-local-version" isort = "isort.main:main" isort-identify-imports = "isort.main:identify_imports_main" -[project.entry-points."distutils.commands"] -isort = "isort.setuptools_commands:ISortCommand" - [project.optional-dependencies] colors = ["colorama"] -plugins = ["setuptools"] [tool.coverage.paths] source = [ @@ -126,13 +122,11 @@ dev = [ "pytest>=8.4.2", "pytest-benchmark>=5.1.0", "ruff>=0.13.3", - "setuptools>=75.8.0", "stdlibs>=2024.10.21.16", "toml>=0.10.2", "tox>=4.30.3", "tox-uv>=1.28.0", "types-colorama>=0.4.2", - "types-setuptools>=70.0.0.20240523", "types-toml>=0.1.3", "uv>=0.8.23", ] @@ -200,7 +194,6 @@ lint.mccabe.max-complexity = 91 # Default is 10 "isort/hooks.py" = [ "S603" ] "isort/output.py" = [ "PLC0206" ] "isort/settings.py" = [ "PLC0414", "S603", "S607" ] -"isort/setuptools_commands.py" = [ "RUF012" ] "tests/*" = [ "RUF001", "S" ] "tests/unit/example_crlf_file.py" = [ "F401" ] diff --git a/tests/unit/test_importable.py b/tests/unit/test_importable.py index 67da5e022..a72e1a876 100644 --- a/tests/unit/test_importable.py +++ b/tests/unit/test_importable.py @@ -23,7 +23,6 @@ def test_importable(): import isort.profiles import isort.sections import isort.settings - import isort.setuptools_commands import isort.sorting import isort.stdlibs import isort.stdlibs.all diff --git a/tests/unit/test_setuptools_command.py b/tests/unit/test_setuptools_command.py deleted file mode 100644 index 2ca79d6c0..000000000 --- a/tests/unit/test_setuptools_command.py +++ /dev/null @@ -1,32 +0,0 @@ -from setuptools.dist import Distribution - -from isort import setuptools_commands - - -def test_isort_command_smoke(src_dir): - """A basic smoke test for the setuptools_commands command""" - - command = setuptools_commands.ISortCommand(Distribution()) - command.distribution.packages = ["isort"] - command.distribution.package_dir = {"isort": src_dir} - command.initialize_options() - command.finalize_options() - try: - command.run() - except SystemExit: - pass - - command.distribution.package_dir = {"": "isort"} - command.distribution.py_modules = ["one", "two"] - command.initialize_options() - command.finalize_options() - command.run() - - command.distribution.packages = ["not_a_file"] - command.distribution.package_dir = {"not_a_file": src_dir} - command.initialize_options() - command.finalize_options() - try: - command.run() - except SystemExit: - pass diff --git a/uv.lock b/uv.lock index a972c2691..9a1235db9 100644 --- a/uv.lock +++ b/uv.lock @@ -748,9 +748,6 @@ source = { editable = "." } colors = [ { name = "colorama" }, ] -plugins = [ - { name = "setuptools" }, -] [package.dev-dependencies] dev = [ @@ -776,23 +773,18 @@ dev = [ { name = "pytest" }, { name = "pytest-benchmark" }, { name = "ruff" }, - { name = "setuptools" }, { name = "stdlibs" }, { name = "toml" }, { name = "tox" }, { name = "tox-uv" }, { name = "types-colorama" }, - { name = "types-setuptools" }, { name = "types-toml" }, { name = "uv" }, ] [package.metadata] -requires-dist = [ - { name = "colorama", marker = "extra == 'colors'" }, - { name = "setuptools", marker = "extra == 'plugins'" }, -] -provides-extras = ["colors", "plugins"] +requires-dist = [{ name = "colorama", marker = "extra == 'colors'" }] +provides-extras = ["colors"] [package.metadata.requires-dev] dev = [ @@ -818,13 +810,11 @@ dev = [ { name = "pytest", specifier = ">=8.4.2" }, { name = "pytest-benchmark", specifier = ">=5.1.0" }, { name = "ruff", specifier = ">=0.13.3" }, - { name = "setuptools", specifier = ">=75.8.0" }, { name = "stdlibs", specifier = ">=2024.10.21.16" }, { name = "toml", specifier = ">=0.10.2" }, { name = "tox", specifier = ">=4.30.3" }, { name = "tox-uv", specifier = ">=1.28.0" }, { name = "types-colorama", specifier = ">=0.4.2" }, - { name = "types-setuptools", specifier = ">=70.0.0.20240523" }, { name = "types-toml", specifier = ">=0.1.3" }, { name = "uv", specifier = ">=0.8.23" }, ] @@ -1646,15 +1636,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/54/24/b4293291fa1dd830f353d2cb163295742fa87f179fcc8a20a306a81978b7/SecretStorage-3.3.3-py3-none-any.whl", hash = "sha256:f356e6628222568e3af06f2eba8df495efa13b3b63081dafd4f7d9a7b7bc9f99", size = 15221, upload-time = "2022-08-13T16:22:44.457Z" }, ] -[[package]] -name = "setuptools" -version = "75.8.0" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/92/ec/089608b791d210aec4e7f97488e67ab0d33add3efccb83a056cbafe3a2a6/setuptools-75.8.0.tar.gz", hash = "sha256:c5afc8f407c626b8313a86e10311dd3f661c6cd9c09d4bf8c15c0e11f9f2b0e6", size = 1343222, upload-time = "2025-01-08T18:28:23.98Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/69/8a/b9dc7678803429e4a3bc9ba462fa3dd9066824d3c607490235c6a796be5a/setuptools-75.8.0-py3-none-any.whl", hash = "sha256:e3982f444617239225d675215d51f6ba05f845d4eec313da4418fdbb56fb27e3", size = 1228782, upload-time = "2025-01-08T18:28:20.912Z" }, -] - [[package]] name = "shellingham" version = "1.5.4" @@ -1903,15 +1884,6 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/0f/b3/ca41df24db5eb99b00d97f89d7674a90cb6b3134c52fb8121b6d8d30f15c/types_python_dateutil-2.9.0.20241206-py3-none-any.whl", hash = "sha256:e248a4bc70a486d3e3ec84d0dc30eec3a5f979d6e7ee4123ae043eedbb987f53", size = 14384, upload-time = "2024-12-06T02:56:39.412Z" }, ] -[[package]] -name = "types-setuptools" -version = "75.8.0.20250110" -source = { registry = "https://pypi.org/simple" } -sdist = { url = "https://files.pythonhosted.org/packages/f7/42/5713e90d4f9683f2301d900f33e4fc2405ad8ac224dda30f6cb7f4cd215b/types_setuptools-75.8.0.20250110.tar.gz", hash = "sha256:96f7ec8bbd6e0a54ea180d66ad68ad7a1d7954e7281a710ea2de75e355545271", size = 48185, upload-time = "2025-01-10T02:45:52.085Z" } -wheels = [ - { url = "https://files.pythonhosted.org/packages/cf/a3/dbfd106751b11c728cec21cc62cbfe7ff7391b935c4b6e8f0bdc2e6fd541/types_setuptools-75.8.0.20250110-py3-none-any.whl", hash = "sha256:a9f12980bbf9bcdc23ecd80755789085bad6bfce4060c2275bc2b4ca9f2bc480", size = 71521, upload-time = "2025-01-10T02:45:49.873Z" }, -] - [[package]] name = "types-toml" version = "0.10.8.20240310"