Skip to content

Commit

Permalink
Use ruff, not pycln, for removing unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jul 22, 2023
1 parent 464b71c commit 7a9ba8e
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 20 deletions.
7 changes: 0 additions & 7 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,6 @@ repos:
- id: check-merge-conflict
- id: mixed-line-ending
- id: check-case-conflict
- repo: https://github.com/hadialqattan/pycln
rev: v2.1.6 # must match requirements-tests.txt
hooks:
- id: pycln
args: [--config=pyproject.toml]
types: [file]
types_or: [python, pyi]
- repo: https://github.com/psf/black
rev: 23.7.0 # must match requirements-tests.txt
hooks:
Expand Down
9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ it takes a bit longer. For more details, read below.
Typeshed runs continuous integration (CI) on all pull requests. This means that
if you file a pull request (PR), our full test suite -- including our linter,
`flake8` -- is run on your PR. It also means that bots will automatically apply
changes to your PR (using `pycln`, `black`, `isort` and `ruff`) to fix any formatting issues.
changes to your PR (using `black`, `isort` and `ruff`) to fix any formatting issues.
This frees you up to ignore all local setup on your side, focus on the
code and rely on the CI to fix everything, or point you to the places that
need fixing.
Expand Down Expand Up @@ -84,19 +84,18 @@ terminal to install all non-pytype requirements:

## Code formatting

The code is formatted using `black` and `isort`. Unused imports are also
auto-removed using `pycln`, and various other autofixes are performed by `ruff`.
The code is formatted using `black` and `isort`. Various other autofixes are
also performed by `ruff`.

The repository is equipped with a [`pre-commit.ci`](https://pre-commit.ci/)
configuration file. This means that you don't *need* to do anything yourself to
run the code formatters. When you push a commit, a bot will run those for you
right away and add a commit to your PR.

That being said, if you *want* to run the checks locally when you commit,
you're free to do so. Either run `pycln`, `isort`, `black` and `ruff` manually...
you're free to do so. Either run `isort`, `black` and `ruff` manually...

```bash
$ pycln --config=pyproject.toml .
$ isort .
$ ruff .
$ black .
Expand Down
5 changes: 1 addition & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ exclude = [
# Only enable rules that have safe autofixes;
# only enable rules that are relevant to stubs
select = [
"F401", # Remove unused imports
"UP004", # Remove explicit `object` inheritance
"UP006", # PEP-585 autofixes
"UP007", # PEP-604 autofixes
Expand All @@ -95,9 +96,5 @@ select = [
"PYI032", # use `object`, not `Any`, as the second parameter to `__eq__`
]

[tool.pycln]
all = true
disable_all_dunder_policy = true

[tool.typeshed]
pyright_version = "1.1.318"
1 change: 0 additions & 1 deletion requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ flake8-pyi==23.6.0; python_version >= "3.8" # must match .pre-commit-confi
isort==5.12.0; python_version >= "3.8" # must match .pre-commit-config.yaml
mypy==1.4.1
pre-commit-hooks==4.4.0 # must match .pre-commit-config.yaml
pycln==2.1.6 # must match .pre-commit-config.yaml
pytype==2023.6.16; platform_system != "Windows" and python_version < "3.11"
ruff==0.0.278 # must match .pre-commit-config.yaml

Expand Down
2 changes: 0 additions & 2 deletions scripts/runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ def main() -> None:
pytype_result: subprocess.CompletedProcess[bytes] | None = None

# Run formatters first. Order matters.
print("\nRunning pycln...")
subprocess.run([sys.executable, "-m", "pycln", path, "--config=pyproject.toml"])
print("\nRunning ruff...")
subprocess.run([sys.executable, "-m", "ruff", path])
print("\nRunning isort...")
Expand Down
2 changes: 1 addition & 1 deletion tests/check_consistent.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# These type checkers and linters must have exact versions in the requirements file to ensure
# consistent CI runs.
linters = {"black", "flake8", "flake8-bugbear", "flake8-noqa", "flake8-pyi", "isort", "ruff", "mypy", "pycln", "pytype"}
linters = {"black", "flake8", "flake8-bugbear", "flake8-noqa", "flake8-pyi", "isort", "ruff", "mypy", "pytype"}


def assert_consistent_filetypes(
Expand Down

0 comments on commit 7a9ba8e

Please sign in to comment.