Skip to content

Run pycln as a pre-commit hook in CI #8304

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

Merged
merged 4 commits into from
Jul 18, 2022
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
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
repos:
- repo: https://github.com/hadialqattan/pycln
rev: v2.0.2 # must match requirements-tests.txt
hooks:
- id: pycln
args: [--all, stubs, stdlib, tests, scripts]
- repo: https://github.com/psf/black
rev: 22.6.0 # must match requirements-tests.txt
hooks:
Expand Down
8 changes: 5 additions & 3 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 `black` and `isort`) to fix any formatting issues.
changes to your PR (using `pycln`, `black` and `isort`) 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 @@ -82,17 +82,19 @@ terminal to install all non-pytype requirements:

## Code formatting

The code is formatted using `black` and `isort`.
The code is formatted using `black` and `isort`. Unused imports are also
auto-removed using `pycln`.

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 `black` and `isort` manually...
you're free to do so. Either run `pycln`, `black` and `isort` manually...

```
pycln --all .
isort .
black .
```
Expand Down
1 change: 1 addition & 0 deletions requirements-tests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@ flake8-pyi==22.5.1
# must match .pre-commit-config.yaml
isort==5.10.1
tomli==1.2.2
pycln==2.0.2
packaging==21.3
termcolor
1 change: 0 additions & 1 deletion stdlib/tokenize.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
from _typeshed import StrOrBytesPath
from builtins import open as _builtin_open
from collections.abc import Callable, Generator, Iterable, Sequence
from re import Pattern
from token import *
Expand Down
1 change: 0 additions & 1 deletion stdlib/unittest/loader.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import unittest.case
import unittest.result
import unittest.suite
from collections.abc import Callable, Sequence
from re import Pattern
Expand Down
4 changes: 3 additions & 1 deletion stubs/aiofiles/aiofiles/os.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ from os import stat_result
from typing import Any, overload
from typing_extensions import TypeAlias

from . import ospath as path
from . import ospath

path = ospath

_FdOrAnyPath: TypeAlias = int | StrOrBytesPath

Expand Down