python-linters 0.1.5__tar.gz → 0.1.6__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- python_linters-0.1.6/.gitignore +161 -0
- {python_linters-0.1.5 → python_linters-0.1.6}/PKG-INFO +32 -36
- {python_linters-0.1.5 → python_linters-0.1.6}/README.md +20 -19
- python_linters-0.1.6/pyproject.toml +40 -0
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/add_noqa.py +8 -6
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/config_files.py +0 -2
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/extending_ruff_toml.py +3 -3
- python_linters-0.1.6/python_linters/fix_code.py +25 -0
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/getting_to_be_linted_folders.py +2 -11
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/pyrightconfig.json +5 -1
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/ruff.toml +6 -6
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/ruff_rule_categories.py +4 -2
- python_linters-0.1.6/python_linters/ruff_rules.txt +1182 -0
- python_linters-0.1.6/python_linters/run_linters.py +49 -0
- python_linters-0.1.6/python_linters/utils.py +72 -0
- python_linters-0.1.5/pyproject.toml +0 -30
- python_linters-0.1.5/python_linters/.flake8 +0 -32
- python_linters-0.1.5/python_linters/fix_code.py +0 -29
- python_linters-0.1.5/python_linters/ruff_rules.txt +0 -956
- python_linters-0.1.5/python_linters/run_linters.py +0 -44
- {python_linters-0.1.5 → python_linters-0.1.6}/LICENSE +0 -0
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/__init__.py +0 -0
- {python_linters-0.1.5 → python_linters-0.1.6}/python_linters/parse_rules.py +0 -0
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
_version.py
|
|
2
|
+
# Byte-compiled / optimized / DLL files
|
|
3
|
+
__pycache__/
|
|
4
|
+
*.py[cod]
|
|
5
|
+
*$py.class
|
|
6
|
+
|
|
7
|
+
# C extensions
|
|
8
|
+
*.so
|
|
9
|
+
|
|
10
|
+
# Distribution / packaging
|
|
11
|
+
.Python
|
|
12
|
+
build/
|
|
13
|
+
develop-eggs/
|
|
14
|
+
dist/
|
|
15
|
+
downloads/
|
|
16
|
+
eggs/
|
|
17
|
+
.eggs/
|
|
18
|
+
lib/
|
|
19
|
+
lib64/
|
|
20
|
+
parts/
|
|
21
|
+
sdist/
|
|
22
|
+
var/
|
|
23
|
+
wheels/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
#Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# poetry
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
103
|
+
#poetry.lock
|
|
104
|
+
|
|
105
|
+
# pdm
|
|
106
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
107
|
+
#pdm.lock
|
|
108
|
+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
|
|
109
|
+
# in version control.
|
|
110
|
+
# https://pdm.fming.dev/#use-with-ide
|
|
111
|
+
.pdm.toml
|
|
112
|
+
|
|
113
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
114
|
+
__pypackages__/
|
|
115
|
+
|
|
116
|
+
# Celery stuff
|
|
117
|
+
celerybeat-schedule
|
|
118
|
+
celerybeat.pid
|
|
119
|
+
|
|
120
|
+
# SageMath parsed files
|
|
121
|
+
*.sage.py
|
|
122
|
+
|
|
123
|
+
# Environments
|
|
124
|
+
.env
|
|
125
|
+
.venv
|
|
126
|
+
env/
|
|
127
|
+
venv/
|
|
128
|
+
ENV/
|
|
129
|
+
env.bak/
|
|
130
|
+
venv.bak/
|
|
131
|
+
|
|
132
|
+
# Spyder project settings
|
|
133
|
+
.spyderproject
|
|
134
|
+
.spyproject
|
|
135
|
+
|
|
136
|
+
# Rope project settings
|
|
137
|
+
.ropeproject
|
|
138
|
+
|
|
139
|
+
# mkdocs documentation
|
|
140
|
+
/site
|
|
141
|
+
|
|
142
|
+
# mypy
|
|
143
|
+
.mypy_cache/
|
|
144
|
+
.dmypy.json
|
|
145
|
+
dmypy.json
|
|
146
|
+
|
|
147
|
+
# Pyre type checker
|
|
148
|
+
.pyre/
|
|
149
|
+
|
|
150
|
+
# pytype static type analyzer
|
|
151
|
+
.pytype/
|
|
152
|
+
|
|
153
|
+
# Cython debug symbols
|
|
154
|
+
cython_debug/
|
|
155
|
+
|
|
156
|
+
# PyCharm
|
|
157
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
158
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
159
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
160
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
161
|
+
.idea/
|
|
@@ -1,31 +1,28 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: python-linters
|
|
3
|
-
Version: 0.1.
|
|
4
|
-
Summary: bundling config files for linters like ruff and
|
|
5
|
-
|
|
3
|
+
Version: 0.1.6
|
|
4
|
+
Summary: bundling config files for linters like ruff and pyright
|
|
5
|
+
Project-URL: repository, https://github.com/dertilo/python-linters
|
|
6
|
+
Author-email: Tilo Himmelsbach <dertilo@gmail.com>
|
|
6
7
|
License: MIT
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Requires-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
-
Requires-Dist: basedpyright (>=1.12.5,<2.0.0)
|
|
16
|
-
Requires-Dist: ruff (>=0.0.291)
|
|
17
|
-
Requires-Dist: toml (>=0.10.2,<0.11.0)
|
|
18
|
-
Project-URL: Repository, https://github.com/dertilo/python-linters
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: <4.0,>=3.10
|
|
10
|
+
Requires-Dist: basedpyright<2.0.0,>=1.12.5
|
|
11
|
+
Requires-Dist: json-with-comments<2.0.0,>=1.2.9
|
|
12
|
+
Requires-Dist: ruff>=0.0.291
|
|
13
|
+
Requires-Dist: toml<1.0.0,>=0.10.2
|
|
19
14
|
Description-Content-Type: text/markdown
|
|
20
15
|
|
|
21
16
|

|
|
22
17
|
[](https://opensource.org/licenses/MIT)
|
|
23
18
|
[](https://beartype.readthedocs.io)
|
|
24
19
|
# python-linters
|
|
25
|
-
- bundles ruff and basedpyright into a single poetry-script
|
|
26
|
-
-
|
|
20
|
+
- bundles ruff and ~~flake8~~ basedpyright into a single ~~poetry~~uv-script
|
|
21
|
+
- even though I liked some flake8-rules (especially from [wemake-python-styleguide](https://wemake-python-styleguide.readthedocs.io/en/latest/)) dropped it in favor of ruff for being too slow
|
|
22
|
+
- project independent linter configuration (via `ruff.toml`,~~`.flake8`~~`pyrightconfig.json`) -> one config to rule them all
|
|
23
|
+
- well one can still override the default config via `ruff_extensions.toml` and `pyrightconfig.json`
|
|
27
24
|
### use-cases:
|
|
28
|
-
1. interactively learning python code quality standards via ruff+
|
|
25
|
+
1. interactively learning python code quality standards via ruff+pyright, see [local development workflow](#2-local-development-workflow-before-pushing-to-ci-pipeline)
|
|
29
26
|
2. enforcing minimal quality-standards via a "lint-stage" in a ci-pipeline, see [setup for ci-pipeline](#3-setup-for-ci-pipeline)
|
|
30
27
|
## 0. motivation:
|
|
31
28
|
### Python is a Bicycle!
|
|
@@ -73,13 +70,12 @@ python-linters = { version = "<some-version-here>" }
|
|
|
73
70
|
],
|
|
74
71
|
```
|
|
75
72
|
### three scripts/commands that you can run locally
|
|
76
|
-
1. `
|
|
73
|
+
1. `uv run fixcode` to let black+isort+ruff "auto-fix" your code -> always have a `clean` git-repo before doing this (no uncommitted changes)
|
|
77
74
|
- [example output](#fixcode-example)
|
|
78
|
-
1. `
|
|
75
|
+
1. `uv run pythonlinter` -> to lint your code
|
|
79
76
|
- [example black is not happy](#pythonlinter-black-is-not-happy) -> if you ran `fixcode` black is guaranteed to be happy!
|
|
80
77
|
- [example ruff is not happy](#pythonlinter-ruff-is-not-happy)
|
|
81
|
-
|
|
82
|
-
1. `poetry run addnoqa` to let ruff insert rules-violation-comments to your code
|
|
78
|
+
1. `uv run addnoqa` to let ruff insert rules-violation-comments to your code
|
|
83
79
|
- [example](#addnoqa-example)
|
|
84
80
|
```mermaid
|
|
85
81
|
flowchart TD
|
|
@@ -89,9 +85,9 @@ classDef style2 fill:#ffffba
|
|
|
89
85
|
classDef style3 fill:#baffc9
|
|
90
86
|
classDef style4 fill:#bae1ff
|
|
91
87
|
op1["start: have a 'clean' repo"]:::style4 --> op2
|
|
92
|
-
op2[\"
|
|
88
|
+
op2[\"uv run fixcode\n refactor & git commit"/]:::style1 --> cond9{{"uv run pythonlinter"}}:::style0
|
|
93
89
|
cond9 --> | complains | cond47{{"ruff"}}:::style0
|
|
94
|
-
cond47 --> | complains | op51[\"
|
|
90
|
+
cond47 --> | complains | op51[\"uv run addnoqa"/]:::style1
|
|
95
91
|
op51 --> sub53[\"refactor your code \nOR\n keep/add noqa-comment"/]:::style1
|
|
96
92
|
sub53 --> op2
|
|
97
93
|
cond47 --> | is happy | cond58{{"pyright"}}:::style0
|
|
@@ -100,11 +96,11 @@ cond58 --> | is happy | sub66["git commit"]
|
|
|
100
96
|
sub66 --> sub80
|
|
101
97
|
cond9 --> | is happy | sub80["git push"]:::style3
|
|
102
98
|
```
|
|
103
|
-
- write-operations (changing your code): `
|
|
104
|
-
- read-only-operations: `
|
|
99
|
+
- write-operations (changing your code): `uv run fixcode`, `poerty run addnoqa`, `refactor your code`
|
|
100
|
+
- read-only-operations: `uv run pythonlinter`,`git commit`, `git push`
|
|
105
101
|
|
|
106
102
|
## 3. setup for ci-pipeline
|
|
107
|
-
* if you specified the packages in the `pyproject.toml` and you run just run `
|
|
103
|
+
* if you specified the packages in the `pyproject.toml` and you run just run `uv run pythonlinter` without any arguments than the `pyproject.toml` is getting parsed and specified packages are getting linted
|
|
108
104
|
```yaml
|
|
109
105
|
stages:
|
|
110
106
|
- lint # lint-stage!
|
|
@@ -132,7 +128,7 @@ linting:
|
|
|
132
128
|
### fixcode example
|
|
133
129
|
```commandline
|
|
134
130
|
cd <somehwere>/whisper-streaming
|
|
135
|
-
|
|
131
|
+
uv run fixcode
|
|
136
132
|
Fixing <somehwere>/whisper-streaming/whisper_streaming/post_asr_preparations.py
|
|
137
133
|
whisper_streaming/faster_whisper_inference/faster_whisper_inferencer.py:231:30: ARG005 Unused lambda argument: `x`
|
|
138
134
|
whisper_streaming/faster_whisper_inference/faster_whisper_inferencer.py:234:5: RET503 Missing explicit `return` at the end of function able to return non-`None` value
|
|
@@ -154,8 +150,8 @@ folders_to_be_linted=['whisper_streaming', 'tests']
|
|
|
154
150
|
- a missing return statement
|
|
155
151
|
- missing type annotations
|
|
156
152
|
```commandline
|
|
157
|
-
|
|
158
|
-
linter-order: black->ruff->
|
|
153
|
+
uv run pythonlinter
|
|
154
|
+
linter-order: black->ruff->pyright
|
|
159
155
|
|
|
160
156
|
...
|
|
161
157
|
|
|
@@ -171,7 +167,7 @@ python_linters.run_linters.LinterException: 💩 ruff is not happy! 💩
|
|
|
171
167
|
### addnoqa example
|
|
172
168
|
- only shows how many noqas it added (`3`) and how many files it left unchanged (`22`)
|
|
173
169
|
```commandline
|
|
174
|
-
|
|
170
|
+
uv run addnoqa
|
|
175
171
|
Added 3 noqa directives.
|
|
176
172
|
All done! ✨ 🍰 ✨
|
|
177
173
|
22 files would be left unchanged.
|
|
@@ -196,17 +192,17 @@ def foobar(x): # noqa: ANN001, ANN202
|
|
|
196
192
|
{
|
|
197
193
|
"label": "fixcode",
|
|
198
194
|
"type": "shell",
|
|
199
|
-
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) &&
|
|
195
|
+
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) && uv run fixcode"
|
|
200
196
|
},
|
|
201
197
|
{
|
|
202
198
|
"label": "addnoqa",
|
|
203
199
|
"type": "shell",
|
|
204
|
-
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) &&
|
|
200
|
+
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) && uv run addnoqa"
|
|
205
201
|
},
|
|
206
202
|
{
|
|
207
203
|
"label": "pythonlinter",
|
|
208
204
|
"type": "shell",
|
|
209
|
-
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) &&
|
|
205
|
+
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) && uv run pythonlinter"
|
|
210
206
|
}
|
|
211
207
|
]
|
|
212
208
|
}
|
|
@@ -215,4 +211,4 @@ def foobar(x): # noqa: ANN001, ANN202
|
|
|
215
211
|

|
|
216
212
|
## alternatives
|
|
217
213
|
- https://github.com/astral-sh/ruff-vscode
|
|
218
|
-
- https://plugins.jetbrains.com/plugin/20574-ruff
|
|
214
|
+
- https://plugins.jetbrains.com/plugin/20574-ruff
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
[](https://opensource.org/licenses/MIT)
|
|
3
3
|
[](https://beartype.readthedocs.io)
|
|
4
4
|
# python-linters
|
|
5
|
-
- bundles ruff and basedpyright into a single poetry-script
|
|
6
|
-
-
|
|
5
|
+
- bundles ruff and ~~flake8~~ basedpyright into a single ~~poetry~~uv-script
|
|
6
|
+
- even though I liked some flake8-rules (especially from [wemake-python-styleguide](https://wemake-python-styleguide.readthedocs.io/en/latest/)) dropped it in favor of ruff for being too slow
|
|
7
|
+
- project independent linter configuration (via `ruff.toml`,~~`.flake8`~~`pyrightconfig.json`) -> one config to rule them all
|
|
8
|
+
- well one can still override the default config via `ruff_extensions.toml` and `pyrightconfig.json`
|
|
7
9
|
### use-cases:
|
|
8
|
-
1. interactively learning python code quality standards via ruff+
|
|
10
|
+
1. interactively learning python code quality standards via ruff+pyright, see [local development workflow](#2-local-development-workflow-before-pushing-to-ci-pipeline)
|
|
9
11
|
2. enforcing minimal quality-standards via a "lint-stage" in a ci-pipeline, see [setup for ci-pipeline](#3-setup-for-ci-pipeline)
|
|
10
12
|
## 0. motivation:
|
|
11
13
|
### Python is a Bicycle!
|
|
@@ -53,13 +55,12 @@ python-linters = { version = "<some-version-here>" }
|
|
|
53
55
|
],
|
|
54
56
|
```
|
|
55
57
|
### three scripts/commands that you can run locally
|
|
56
|
-
1. `
|
|
58
|
+
1. `uv run fixcode` to let black+isort+ruff "auto-fix" your code -> always have a `clean` git-repo before doing this (no uncommitted changes)
|
|
57
59
|
- [example output](#fixcode-example)
|
|
58
|
-
1. `
|
|
60
|
+
1. `uv run pythonlinter` -> to lint your code
|
|
59
61
|
- [example black is not happy](#pythonlinter-black-is-not-happy) -> if you ran `fixcode` black is guaranteed to be happy!
|
|
60
62
|
- [example ruff is not happy](#pythonlinter-ruff-is-not-happy)
|
|
61
|
-
|
|
62
|
-
1. `poetry run addnoqa` to let ruff insert rules-violation-comments to your code
|
|
63
|
+
1. `uv run addnoqa` to let ruff insert rules-violation-comments to your code
|
|
63
64
|
- [example](#addnoqa-example)
|
|
64
65
|
```mermaid
|
|
65
66
|
flowchart TD
|
|
@@ -69,9 +70,9 @@ classDef style2 fill:#ffffba
|
|
|
69
70
|
classDef style3 fill:#baffc9
|
|
70
71
|
classDef style4 fill:#bae1ff
|
|
71
72
|
op1["start: have a 'clean' repo"]:::style4 --> op2
|
|
72
|
-
op2[\"
|
|
73
|
+
op2[\"uv run fixcode\n refactor & git commit"/]:::style1 --> cond9{{"uv run pythonlinter"}}:::style0
|
|
73
74
|
cond9 --> | complains | cond47{{"ruff"}}:::style0
|
|
74
|
-
cond47 --> | complains | op51[\"
|
|
75
|
+
cond47 --> | complains | op51[\"uv run addnoqa"/]:::style1
|
|
75
76
|
op51 --> sub53[\"refactor your code \nOR\n keep/add noqa-comment"/]:::style1
|
|
76
77
|
sub53 --> op2
|
|
77
78
|
cond47 --> | is happy | cond58{{"pyright"}}:::style0
|
|
@@ -80,11 +81,11 @@ cond58 --> | is happy | sub66["git commit"]
|
|
|
80
81
|
sub66 --> sub80
|
|
81
82
|
cond9 --> | is happy | sub80["git push"]:::style3
|
|
82
83
|
```
|
|
83
|
-
- write-operations (changing your code): `
|
|
84
|
-
- read-only-operations: `
|
|
84
|
+
- write-operations (changing your code): `uv run fixcode`, `poerty run addnoqa`, `refactor your code`
|
|
85
|
+
- read-only-operations: `uv run pythonlinter`,`git commit`, `git push`
|
|
85
86
|
|
|
86
87
|
## 3. setup for ci-pipeline
|
|
87
|
-
* if you specified the packages in the `pyproject.toml` and you run just run `
|
|
88
|
+
* if you specified the packages in the `pyproject.toml` and you run just run `uv run pythonlinter` without any arguments than the `pyproject.toml` is getting parsed and specified packages are getting linted
|
|
88
89
|
```yaml
|
|
89
90
|
stages:
|
|
90
91
|
- lint # lint-stage!
|
|
@@ -112,7 +113,7 @@ linting:
|
|
|
112
113
|
### fixcode example
|
|
113
114
|
```commandline
|
|
114
115
|
cd <somehwere>/whisper-streaming
|
|
115
|
-
|
|
116
|
+
uv run fixcode
|
|
116
117
|
Fixing <somehwere>/whisper-streaming/whisper_streaming/post_asr_preparations.py
|
|
117
118
|
whisper_streaming/faster_whisper_inference/faster_whisper_inferencer.py:231:30: ARG005 Unused lambda argument: `x`
|
|
118
119
|
whisper_streaming/faster_whisper_inference/faster_whisper_inferencer.py:234:5: RET503 Missing explicit `return` at the end of function able to return non-`None` value
|
|
@@ -134,8 +135,8 @@ folders_to_be_linted=['whisper_streaming', 'tests']
|
|
|
134
135
|
- a missing return statement
|
|
135
136
|
- missing type annotations
|
|
136
137
|
```commandline
|
|
137
|
-
|
|
138
|
-
linter-order: black->ruff->
|
|
138
|
+
uv run pythonlinter
|
|
139
|
+
linter-order: black->ruff->pyright
|
|
139
140
|
|
|
140
141
|
...
|
|
141
142
|
|
|
@@ -151,7 +152,7 @@ python_linters.run_linters.LinterException: 💩 ruff is not happy! 💩
|
|
|
151
152
|
### addnoqa example
|
|
152
153
|
- only shows how many noqas it added (`3`) and how many files it left unchanged (`22`)
|
|
153
154
|
```commandline
|
|
154
|
-
|
|
155
|
+
uv run addnoqa
|
|
155
156
|
Added 3 noqa directives.
|
|
156
157
|
All done! ✨ 🍰 ✨
|
|
157
158
|
22 files would be left unchanged.
|
|
@@ -176,17 +177,17 @@ def foobar(x): # noqa: ANN001, ANN202
|
|
|
176
177
|
{
|
|
177
178
|
"label": "fixcode",
|
|
178
179
|
"type": "shell",
|
|
179
|
-
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) &&
|
|
180
|
+
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) && uv run fixcode"
|
|
180
181
|
},
|
|
181
182
|
{
|
|
182
183
|
"label": "addnoqa",
|
|
183
184
|
"type": "shell",
|
|
184
|
-
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) &&
|
|
185
|
+
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) && uv run addnoqa"
|
|
185
186
|
},
|
|
186
187
|
{
|
|
187
188
|
"label": "pythonlinter",
|
|
188
189
|
"type": "shell",
|
|
189
|
-
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) &&
|
|
190
|
+
"command": "cd $(cd ${fileDirname} && git rev-parse --show-toplevel) && uv run pythonlinter"
|
|
190
191
|
}
|
|
191
192
|
]
|
|
192
193
|
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "python-linters"
|
|
3
|
+
description = "bundling config files for linters like ruff and pyright"
|
|
4
|
+
authors = [ { name = "Tilo Himmelsbach", email = "dertilo@gmail.com" } ]
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = {text = "MIT"}
|
|
7
|
+
requires-python = "<4.0,>=3.10"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"toml<1.0.0,>=0.10.2",
|
|
10
|
+
"ruff>=0.0.291",
|
|
11
|
+
"basedpyright<2.0.0,>=1.12.5",
|
|
12
|
+
"json-with-comments<2.0.0,>=1.2.9",
|
|
13
|
+
]
|
|
14
|
+
dynamic = [
|
|
15
|
+
"version"
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
[project.urls]
|
|
19
|
+
repository = "https://github.com/dertilo/python-linters"
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
pythonlinter = "python_linters.run_linters:main"
|
|
23
|
+
fixcode = "python_linters.fix_code:main"
|
|
24
|
+
addnoqa = "python_linters.add_noqa:main"
|
|
25
|
+
|
|
26
|
+
[build-system]
|
|
27
|
+
requires = ["hatchling", "hatch-vcs"]
|
|
28
|
+
build-backend = "hatchling.build"
|
|
29
|
+
|
|
30
|
+
[tool.hatch.version]
|
|
31
|
+
source = "vcs"
|
|
32
|
+
|
|
33
|
+
[tool.hatch.build.hooks.vcs]
|
|
34
|
+
version-file = "_version.py"
|
|
35
|
+
|
|
36
|
+
[tool.hatch.build.targets.sdist]
|
|
37
|
+
packages = ["python_linters"] # packages option is semantically equivalent to only-include
|
|
38
|
+
|
|
39
|
+
[tool.hatch.build.targets.wheel]
|
|
40
|
+
packages = ["python_linters"]
|
|
@@ -2,28 +2,30 @@ import os
|
|
|
2
2
|
|
|
3
3
|
from python_linters.extending_ruff_toml import create_extended_ruff_toml
|
|
4
4
|
from python_linters.getting_to_be_linted_folders import get_folders_to_be_linted
|
|
5
|
-
from python_linters.
|
|
5
|
+
from python_linters.utils import run_cmd, get_pyproject_dir
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
def main() -> None:
|
|
9
9
|
"""
|
|
10
10
|
expects to run from $ContentRoot$
|
|
11
11
|
"""
|
|
12
|
-
|
|
12
|
+
dirr = get_pyproject_dir()
|
|
13
|
+
folders_tobelinted = get_folders_to_be_linted(f"{dirr}/pyproject.toml")
|
|
14
|
+
|
|
13
15
|
BIG_NUMBER = 9
|
|
14
16
|
for k in range(
|
|
15
17
|
BIG_NUMBER,
|
|
16
18
|
): # theoretically could be necessary to run this loop as long as code changes!
|
|
17
19
|
print(f"addnoqa iteration: {k}")
|
|
18
20
|
run_cmd(
|
|
19
|
-
f"ruff check {' '.join(folders_tobelinted)} --config={create_extended_ruff_toml()} --add-noqa",
|
|
21
|
+
f"cd {dirr} && ruff check {' '.join(folders_tobelinted)} --config={create_extended_ruff_toml(str(dirr))} --add-noqa",
|
|
20
22
|
)
|
|
21
23
|
try:
|
|
22
|
-
run_cmd(f"ruff format --check {' '.join(folders_tobelinted)}")
|
|
24
|
+
run_cmd(f"cd {dirr} && ruff format --check {' '.join(folders_tobelinted)}")
|
|
23
25
|
break
|
|
24
26
|
except Exception:
|
|
25
|
-
run_cmd(f"ruff format {' '.join(folders_tobelinted)}")
|
|
26
|
-
run_cmd(f"fixcode {
|
|
27
|
+
run_cmd(f"cd {dirr} && ruff format {' '.join(folders_tobelinted)}")
|
|
28
|
+
run_cmd(f"fixcode {dirr}")
|
|
27
29
|
|
|
28
30
|
|
|
29
31
|
if __name__ == "__main__":
|
|
@@ -2,10 +2,8 @@ import pathlib
|
|
|
2
2
|
|
|
3
3
|
package_dir = str(pathlib.Path(__file__).parent.resolve())
|
|
4
4
|
|
|
5
|
-
FLAKE8_CONFIG_FILE = f"{package_dir}/.flake8"
|
|
6
5
|
RUFF_CONFIG_FILE = f"{package_dir}/ruff.toml"
|
|
7
6
|
PYRIGHT_CONFIG_FILE = f"{package_dir}/pyrightconfig.json"
|
|
8
7
|
|
|
9
|
-
assert pathlib.Path(FLAKE8_CONFIG_FILE).is_file()
|
|
10
8
|
assert pathlib.Path(RUFF_CONFIG_FILE).is_file()
|
|
11
9
|
assert pathlib.Path(PYRIGHT_CONFIG_FILE).is_file()
|
|
@@ -4,12 +4,12 @@ from pathlib import Path
|
|
|
4
4
|
from python_linters.config_files import RUFF_CONFIG_FILE
|
|
5
5
|
|
|
6
6
|
|
|
7
|
-
def create_extended_ruff_toml() -> str:
|
|
8
|
-
ruff_extension_file = Path("ruff_extension.toml")
|
|
7
|
+
def create_extended_ruff_toml(package_root:str) -> str:
|
|
8
|
+
ruff_extension_file = Path(f"{package_root}/ruff_extension.toml")
|
|
9
9
|
|
|
10
10
|
if ruff_extension_file.is_file():
|
|
11
11
|
fingerprint = f"{ruff_extension_file.stat().st_size}-{ruff_extension_file.stat().st_mtime}"
|
|
12
|
-
extended_ruff_toml_file = f"extended_ruff-{fingerprint}.toml"
|
|
12
|
+
extended_ruff_toml_file = f"{package_root}/extended_ruff-{fingerprint}.toml"
|
|
13
13
|
if not Path(extended_ruff_toml_file).is_file():
|
|
14
14
|
print(f"extending {RUFF_CONFIG_FILE} with {ruff_extension_file=}")
|
|
15
15
|
with Path(extended_ruff_toml_file).open("w", encoding="locale") as f:
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
from python_linters.extending_ruff_toml import create_extended_ruff_toml
|
|
2
|
+
from python_linters.getting_to_be_linted_folders import get_folders_to_be_linted
|
|
3
|
+
|
|
4
|
+
from python_linters.utils import run_cmd_ignore_errors, run_cmd, \
|
|
5
|
+
get_pyproject_dir
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main() -> None:
|
|
9
|
+
"""
|
|
10
|
+
$FilePath$ in pycharm
|
|
11
|
+
"""
|
|
12
|
+
dirr = get_pyproject_dir()
|
|
13
|
+
folders_to_be_linted = get_folders_to_be_linted(f"{dirr}/pyproject.toml")
|
|
14
|
+
folders = " ".join(folders_to_be_linted)
|
|
15
|
+
extended_ruff_toml = create_extended_ruff_toml(str(dirr))
|
|
16
|
+
run_cmd_ignore_errors(
|
|
17
|
+
f"cd {dirr} && ruff check {folders} --config={extended_ruff_toml} --fix",
|
|
18
|
+
)
|
|
19
|
+
run_cmd(f"cd {dirr} && ruff format {folders} --config={extended_ruff_toml}")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
if __name__ == "__main__":
|
|
25
|
+
main()
|
{python_linters-0.1.5 → python_linters-0.1.6}/python_linters/getting_to_be_linted_folders.py
RENAMED
|
@@ -35,17 +35,8 @@ def get_folders_to_be_linted(pyproject_toml: str) -> list[str]:
|
|
|
35
35
|
.get("python-linters", {})
|
|
36
36
|
.get("folders_to_be_linted", None)
|
|
37
37
|
)
|
|
38
|
-
if (
|
|
39
|
-
folders is None
|
|
40
|
-
and (packages := t.get("tool", {}).get("poetry", {}).get("packages", None))
|
|
41
|
-
is not None
|
|
42
|
-
):
|
|
43
|
-
folders = [p["include"] for p in packages]
|
|
44
|
-
if pathlib.Path(f"{pathlib.Path(pyproject_toml).parent}/tests").is_dir():
|
|
45
|
-
folders += ["tests"]
|
|
46
|
-
|
|
47
38
|
if folders is None:
|
|
48
|
-
|
|
49
|
-
|
|
39
|
+
folders = ["./"]
|
|
40
|
+
# raise PackagesOrFoldersToBeLintedAreNotProperlyDefined
|
|
50
41
|
print(f"found following {folders=}")
|
|
51
42
|
return folders
|
|
@@ -44,13 +44,12 @@ select = [
|
|
|
44
44
|
"YTT", # flake8-2020
|
|
45
45
|
"ANN", # flake8-annotations
|
|
46
46
|
"ASYNC", # flake8-async
|
|
47
|
-
"TRIO", # flake8-trio
|
|
48
47
|
"S", # flake8-bandit
|
|
49
48
|
"BLE", # flake8-blind-except
|
|
50
49
|
# excluded "FBT", # flake8-boolean-trap -> tilo: this one might be too strict/hard to refactor
|
|
51
50
|
"B", # flake8-bugbear
|
|
52
51
|
"A", # flake8-builtins
|
|
53
|
-
"COM", # flake8-commas
|
|
52
|
+
# "COM", # flake8-commas # may cause conflicts when used with the formatter: `COM812` -> recommended to be disabled
|
|
54
53
|
# excluded "CPY", # flake8-copyright -> tilo: who cares about copyright? chatGPT does not care!
|
|
55
54
|
"C4", # flake8-comprehensions
|
|
56
55
|
"DTZ", # flake8-datetimez
|
|
@@ -75,7 +74,7 @@ select = [
|
|
|
75
74
|
"SLOT", # flake8-slots
|
|
76
75
|
"SIM", # flake8-simplify
|
|
77
76
|
"TID", # flake8-tidy-imports
|
|
78
|
-
"
|
|
77
|
+
"TC", # flake8-type-checking
|
|
79
78
|
"INT", # flake8-gettext
|
|
80
79
|
"ARG", # flake8-unused-arguments
|
|
81
80
|
"PTH", # flake8-use-pathlib
|
|
@@ -92,19 +91,19 @@ select = [
|
|
|
92
91
|
"TRY", # tryceratops
|
|
93
92
|
"FLY", # flynt
|
|
94
93
|
"NPY", # NumPy-specific rules
|
|
94
|
+
"FAST", # FastAPI
|
|
95
95
|
# excluded "AIR", # Airflow -> we are not using airflow!
|
|
96
96
|
"PERF", # Perflint
|
|
97
97
|
"FURB", # refurb
|
|
98
|
+
# "DOC", # pydoclint # tilo: maybe somewhen!
|
|
98
99
|
"RUF", # Ruff-specific rules
|
|
99
100
|
]
|
|
100
101
|
# --------------- IGNORING specific rules --------------------------------------------------------
|
|
101
102
|
ignore = [
|
|
102
|
-
"
|
|
103
|
+
"TC001","TC002","TC003", # typing-import-only-first-party-import -> tilo: I need those types for runtime-type-validation! (beartype
|
|
103
104
|
"E501", # E501 line-too-long
|
|
104
105
|
"S101", # prohibits using any assert! -> TODO!
|
|
105
106
|
"W605", # Invalid escape sequence: `\ ` tilo: looks like false-positive to me! but not sure -> TODO!
|
|
106
|
-
"ANN101", # ANN101 Missing type annotation for `self` in method
|
|
107
|
-
"ANN102", # Missing type annotation for cls classmethod
|
|
108
107
|
"ANN401", # ANN401 disallows "Any"
|
|
109
108
|
"ANN204", # missing-return-type-special-method (ANN204) is very annoying especially for __enter__, __exit__ etc
|
|
110
109
|
"ANN002", # ANN002 *args
|
|
@@ -126,6 +125,7 @@ ignore = [
|
|
|
126
125
|
"RET506", # looks like a false-positive
|
|
127
126
|
"SLF001", # everybody knows about the _-conventin, if one still accesses "protected" attributes one has their reasons!
|
|
128
127
|
"FURB140", # starmap slower than comprehension in 3.12
|
|
128
|
+
"SIM115" # produces false-postives in lambdas
|
|
129
129
|
]
|
|
130
130
|
|
|
131
131
|
[lint.mccabe]
|