nk-python-style 0.1.0__tar.gz → 0.2.0__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.
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/PKG-INFO +4 -9
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/README.md +2 -6
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/cli.py +1 -4
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/comment_checks.py +3 -10
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/ruff.toml +1 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/PKG-INFO +4 -9
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/SOURCES.txt +1 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/requires.txt +0 -2
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/pyproject.toml +2 -5
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/tests/test_cli.py +17 -0
- nk_python_style-0.2.0/tests/test_ruff_config.py +61 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/tests/test_rules.py +3 -4
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/__init__.py +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/__main__.py +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/ast_checks.py +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/model.py +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/ruff_runner.py +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python/structure_checks.py +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/dependency_links.txt +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/entry_points.txt +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/top_level.txt +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/setup.cfg +0 -0
- {nk_python_style-0.1.0 → nk_python_style-0.2.0}/tests/test_summary.py +0 -0
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nk-python-style
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Python formatter and linter following the repository's conventions
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
7
|
Requires-Dist: ruff<1,>=0.16
|
|
8
|
-
|
|
9
|
-
Requires-Dist: lingua-language-detector<3,>=2.2; extra == "comments"
|
|
8
|
+
Requires-Dist: lingua-language-detector<3,>=2.2
|
|
10
9
|
|
|
11
10
|
# Python : linter et formatter
|
|
12
11
|
|
|
@@ -20,11 +19,7 @@ Depuis ce dépôt :
|
|
|
20
19
|
python -m pip install -e ./python
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
python -m pip install -e "./python[comments]"
|
|
27
|
-
```
|
|
22
|
+
L'installation inclut Ruff et Lingua. La détection de la langue des commentaires est toujours active.
|
|
28
23
|
|
|
29
24
|
Depuis un autre projet, une installation non éditable fonctionne aussi : `python -m pip install <chemin-vers-ce-dépôt>/python`. La commande `nk-python` est ensuite disponible dans le même environnement Python. On peut également utiliser `python -m nk_python`.
|
|
30
25
|
|
|
@@ -52,7 +47,7 @@ La sortie de `check` commence par un résumé : fichiers analysés, nombre de wa
|
|
|
52
47
|
| `PY004` | Cinq paramètres maximum ; `self` ou `cls` est exclu pour les méthodes. |
|
|
53
48
|
| `PY005` | Commentaire de fin de ligne interdit, sauf directive d'outil. |
|
|
54
49
|
| `PY006` | Commentaire dans une fonction interdit, sauf directive d'outil ; utiliser une docstring ou clarifier le code. |
|
|
55
|
-
| `PY007` | Commentaire qui semble non anglais
|
|
50
|
+
| `PY007` | Commentaire qui semble non anglais. Les textes trop courts ou ambigus sont ignorés. |
|
|
56
51
|
| `PY008` | Huit fichiers `.py`/`.pyi` directs maximum dans un dossier parcouru. |
|
|
57
52
|
|
|
58
53
|
Ruff vérifie en plus les erreurs Python (`E4`, `E7`, `E9`, `F`), l'ordre des imports (`I`), les erreurs fréquentes (`B`), certaines modernisations sûres (`UP`) et la variable créée uniquement pour être retournée (`RET504`). Sa configuration est fournie par l'outil, donc les mêmes règles s'appliquent depuis un autre projet. Le formatter impose une indentation de quatre espaces, des guillemets doubles et des fins de ligne LF. Les règles C++ propres aux accolades, `#include`, modules et initialiseurs désignés ne s'appliquent pas à Python.
|
|
@@ -10,11 +10,7 @@ Depuis ce dépôt :
|
|
|
10
10
|
python -m pip install -e ./python
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
```bash
|
|
16
|
-
python -m pip install -e "./python[comments]"
|
|
17
|
-
```
|
|
13
|
+
L'installation inclut Ruff et Lingua. La détection de la langue des commentaires est toujours active.
|
|
18
14
|
|
|
19
15
|
Depuis un autre projet, une installation non éditable fonctionne aussi : `python -m pip install <chemin-vers-ce-dépôt>/python`. La commande `nk-python` est ensuite disponible dans le même environnement Python. On peut également utiliser `python -m nk_python`.
|
|
20
16
|
|
|
@@ -42,7 +38,7 @@ La sortie de `check` commence par un résumé : fichiers analysés, nombre de wa
|
|
|
42
38
|
| `PY004` | Cinq paramètres maximum ; `self` ou `cls` est exclu pour les méthodes. |
|
|
43
39
|
| `PY005` | Commentaire de fin de ligne interdit, sauf directive d'outil. |
|
|
44
40
|
| `PY006` | Commentaire dans une fonction interdit, sauf directive d'outil ; utiliser une docstring ou clarifier le code. |
|
|
45
|
-
| `PY007` | Commentaire qui semble non anglais
|
|
41
|
+
| `PY007` | Commentaire qui semble non anglais. Les textes trop courts ou ambigus sont ignorés. |
|
|
46
42
|
| `PY008` | Huit fichiers `.py`/`.pyi` directs maximum dans un dossier parcouru. |
|
|
47
43
|
|
|
48
44
|
Ruff vérifie en plus les erreurs Python (`E4`, `E7`, `E9`, `F`), l'ordre des imports (`I`), les erreurs fréquentes (`B`), certaines modernisations sûres (`UP`) et la variable créée uniquement pour être retournée (`RET504`). Sa configuration est fournie par l'outil, donc les mêmes règles s'appliquent depuis un autre projet. Le formatter impose une indentation de quatre espaces, des guillemets doubles et des fins de ligne LF. Les règles C++ propres aux accolades, `#include`, modules et initialiseurs désignés ne s'appliquent pas à Python.
|
|
@@ -7,7 +7,7 @@ import sys
|
|
|
7
7
|
from pathlib import Path
|
|
8
8
|
|
|
9
9
|
from .ast_checks import check_source
|
|
10
|
-
from .comment_checks import
|
|
10
|
+
from .comment_checks import check_comments
|
|
11
11
|
from .model import Issue
|
|
12
12
|
from .ruff_runner import run_ruff
|
|
13
13
|
from .structure_checks import discover
|
|
@@ -70,9 +70,6 @@ def _check(files: list[Path], structure_issues: list[Issue]) -> int:
|
|
|
70
70
|
print(lint_text, end="")
|
|
71
71
|
for issue in sorted(issues):
|
|
72
72
|
print(issue)
|
|
73
|
-
if not LANGUAGE_AVAILABLE:
|
|
74
|
-
print("Comment language check skipped (install nk-python-style[comments] to enable it).")
|
|
75
|
-
|
|
76
73
|
print("\n=== Formatter: corrections available via 'format' ===")
|
|
77
74
|
print(import_text, end="")
|
|
78
75
|
print(format_text, end="")
|
|
@@ -1,19 +1,14 @@
|
|
|
1
|
-
"""Token-based comment placement and
|
|
1
|
+
"""Token-based comment placement and language checks."""
|
|
2
2
|
|
|
3
3
|
import io
|
|
4
4
|
import re
|
|
5
5
|
import tokenize
|
|
6
6
|
from pathlib import Path
|
|
7
7
|
|
|
8
|
-
from
|
|
8
|
+
from lingua import Language, LanguageDetectorBuilder
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
from lingua import Language, LanguageDetectorBuilder
|
|
12
|
-
except ImportError:
|
|
13
|
-
Language = None
|
|
14
|
-
LanguageDetectorBuilder = None
|
|
10
|
+
from .model import Issue
|
|
15
11
|
|
|
16
|
-
LANGUAGE_AVAILABLE = LanguageDetectorBuilder is not None
|
|
17
12
|
_detector = None
|
|
18
13
|
_DIRECTIVE = re.compile(
|
|
19
14
|
r"^(?:!|coding[:=]|noqa\b|type:\s*ignore\b|pyright:\s*ignore\b|"
|
|
@@ -52,8 +47,6 @@ def check_comments(path: Path, source: str, functions: list[tuple[int, int]]) ->
|
|
|
52
47
|
|
|
53
48
|
|
|
54
49
|
def _comment_language(comment: str) -> str | None:
|
|
55
|
-
if not LANGUAGE_AVAILABLE:
|
|
56
|
-
return None
|
|
57
50
|
words = [word for word in _WORD.findall(comment) if _natural_word(word)]
|
|
58
51
|
if len(words) < 3 or len(" ".join(words)) < 20:
|
|
59
52
|
return None
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nk-python-style
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Python formatter and linter following the repository's conventions
|
|
5
5
|
Requires-Python: >=3.10
|
|
6
6
|
Description-Content-Type: text/markdown
|
|
7
7
|
Requires-Dist: ruff<1,>=0.16
|
|
8
|
-
|
|
9
|
-
Requires-Dist: lingua-language-detector<3,>=2.2; extra == "comments"
|
|
8
|
+
Requires-Dist: lingua-language-detector<3,>=2.2
|
|
10
9
|
|
|
11
10
|
# Python : linter et formatter
|
|
12
11
|
|
|
@@ -20,11 +19,7 @@ Depuis ce dépôt :
|
|
|
20
19
|
python -m pip install -e ./python
|
|
21
20
|
```
|
|
22
21
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
```bash
|
|
26
|
-
python -m pip install -e "./python[comments]"
|
|
27
|
-
```
|
|
22
|
+
L'installation inclut Ruff et Lingua. La détection de la langue des commentaires est toujours active.
|
|
28
23
|
|
|
29
24
|
Depuis un autre projet, une installation non éditable fonctionne aussi : `python -m pip install <chemin-vers-ce-dépôt>/python`. La commande `nk-python` est ensuite disponible dans le même environnement Python. On peut également utiliser `python -m nk_python`.
|
|
30
25
|
|
|
@@ -52,7 +47,7 @@ La sortie de `check` commence par un résumé : fichiers analysés, nombre de wa
|
|
|
52
47
|
| `PY004` | Cinq paramètres maximum ; `self` ou `cls` est exclu pour les méthodes. |
|
|
53
48
|
| `PY005` | Commentaire de fin de ligne interdit, sauf directive d'outil. |
|
|
54
49
|
| `PY006` | Commentaire dans une fonction interdit, sauf directive d'outil ; utiliser une docstring ou clarifier le code. |
|
|
55
|
-
| `PY007` | Commentaire qui semble non anglais
|
|
50
|
+
| `PY007` | Commentaire qui semble non anglais. Les textes trop courts ou ambigus sont ignorés. |
|
|
56
51
|
| `PY008` | Huit fichiers `.py`/`.pyi` directs maximum dans un dossier parcouru. |
|
|
57
52
|
|
|
58
53
|
Ruff vérifie en plus les erreurs Python (`E4`, `E7`, `E9`, `F`), l'ordre des imports (`I`), les erreurs fréquentes (`B`), certaines modernisations sûres (`UP`) et la variable créée uniquement pour être retournée (`RET504`). Sa configuration est fournie par l'outil, donc les mêmes règles s'appliquent depuis un autre projet. Le formatter impose une indentation de quatre espaces, des guillemets doubles et des fins de ligne LF. Les règles C++ propres aux accolades, `#include`, modules et initialiseurs désignés ne s'appliquent pas à Python.
|
|
@@ -4,14 +4,11 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nk-python-style"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0"
|
|
8
8
|
description = "Python formatter and linter following the repository's conventions"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.10"
|
|
11
|
-
dependencies = ["ruff>=0.16,<1"]
|
|
12
|
-
|
|
13
|
-
[project.optional-dependencies]
|
|
14
|
-
comments = ["lingua-language-detector>=2.2,<3"]
|
|
11
|
+
dependencies = ["ruff>=0.16,<1", "lingua-language-detector>=2.2,<3"]
|
|
15
12
|
|
|
16
13
|
[project.scripts]
|
|
17
14
|
nk-python = "nk_python.cli:main"
|
|
@@ -6,6 +6,23 @@ from pathlib import Path
|
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
class CliTests(unittest.TestCase):
|
|
9
|
+
def test_check_reports_non_english_comments(self):
|
|
10
|
+
with tempfile.TemporaryDirectory() as temp:
|
|
11
|
+
path = Path(temp) / "sample.py"
|
|
12
|
+
source = "# Cette fonction calcule la valeur finale pour chaque entrée.\nvalue = 1\n"
|
|
13
|
+
path.write_text(source, encoding="utf-8")
|
|
14
|
+
checked = subprocess.run(
|
|
15
|
+
[sys.executable, "-m", "nk_python", "check", str(path)],
|
|
16
|
+
capture_output=True,
|
|
17
|
+
text=True,
|
|
18
|
+
check=False,
|
|
19
|
+
)
|
|
20
|
+
self.assertEqual(checked.returncode, 1, checked.stderr + checked.stdout)
|
|
21
|
+
self.assertIn("PY007", checked.stdout)
|
|
22
|
+
self.assertIn("Linter: 1 warnings", checked.stdout)
|
|
23
|
+
self.assertNotIn("All checks passed!", checked.stdout)
|
|
24
|
+
self.assertEqual(path.read_text(encoding="utf-8"), source)
|
|
25
|
+
|
|
9
26
|
def test_check_separates_linter_diagnostics_and_formatter_corrections(self):
|
|
10
27
|
with tempfile.TemporaryDirectory() as temp:
|
|
11
28
|
path = Path(temp) / "sample.py"
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import subprocess
|
|
2
|
+
import sys
|
|
3
|
+
import tempfile
|
|
4
|
+
import unittest
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class RuffConfigurationTests(unittest.TestCase):
|
|
9
|
+
def check_source(self, source):
|
|
10
|
+
with tempfile.TemporaryDirectory() as temp:
|
|
11
|
+
root = Path(temp)
|
|
12
|
+
path = root / "sample.py"
|
|
13
|
+
path.write_text(source, encoding="utf-8", newline="\n")
|
|
14
|
+
checked = subprocess.run(
|
|
15
|
+
[sys.executable, "-m", "nk_python", "check", str(path)],
|
|
16
|
+
cwd=root,
|
|
17
|
+
capture_output=True,
|
|
18
|
+
text=True,
|
|
19
|
+
check=False,
|
|
20
|
+
)
|
|
21
|
+
self.assertEqual(path.read_bytes(), source.encode("utf-8"))
|
|
22
|
+
return checked.returncode, checked.stdout + checked.stderr
|
|
23
|
+
|
|
24
|
+
def test_check_ignores_only_the_disabled_rules(self):
|
|
25
|
+
source = (
|
|
26
|
+
"import warnings\n\n\n"
|
|
27
|
+
"def factory():\n return object()\n\n\n"
|
|
28
|
+
"def with_default(value=factory()):\n return value\n\n\n"
|
|
29
|
+
"def repeated():\n return 1\n\n\n"
|
|
30
|
+
"def repeated():\n return 2\n\n\n"
|
|
31
|
+
'warnings.warn("example")\n'
|
|
32
|
+
"pairs = zip([1], [2])\n"
|
|
33
|
+
)
|
|
34
|
+
status, output = self.check_source(source)
|
|
35
|
+
self.assertEqual(status, 0, output)
|
|
36
|
+
self.assertIn("All checks passed!", output)
|
|
37
|
+
for rule in ("B008", "B028", "B905", "F811"):
|
|
38
|
+
with self.subTest(rule=rule):
|
|
39
|
+
self.assertNotIn(rule, output)
|
|
40
|
+
|
|
41
|
+
def test_check_preserves_other_rules(self):
|
|
42
|
+
source = (
|
|
43
|
+
"import os\nfrom typing import List\n\n"
|
|
44
|
+
"missing_name\n"
|
|
45
|
+
"42\n"
|
|
46
|
+
"for unused in range(2):\n"
|
|
47
|
+
' print("example")\n'
|
|
48
|
+
"callbacks = []\n"
|
|
49
|
+
"for value in range(2):\n"
|
|
50
|
+
" callbacks.append(lambda: value)\n"
|
|
51
|
+
"identity = lambda value: value\n"
|
|
52
|
+
)
|
|
53
|
+
status, output = self.check_source(source)
|
|
54
|
+
self.assertEqual(status, 1, output)
|
|
55
|
+
for rule in ("F821", "B023", "F401", "B018", "B007", "UP035", "E731"):
|
|
56
|
+
with self.subTest(rule=rule):
|
|
57
|
+
self.assertRegex(output, rf": {rule}\b")
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
if __name__ == "__main__":
|
|
61
|
+
unittest.main()
|
|
@@ -3,7 +3,7 @@ import unittest
|
|
|
3
3
|
from pathlib import Path
|
|
4
4
|
|
|
5
5
|
from nk_python.ast_checks import check_source
|
|
6
|
-
from nk_python.comment_checks import
|
|
6
|
+
from nk_python.comment_checks import check_comments
|
|
7
7
|
from nk_python.structure_checks import discover
|
|
8
8
|
|
|
9
9
|
|
|
@@ -43,9 +43,8 @@ class RuleTests(unittest.TestCase):
|
|
|
43
43
|
|
|
44
44
|
def test_inline_comment_and_language(self):
|
|
45
45
|
self.assertIn("PY005", codes("value = 1 # a comment next to code\n"))
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
self.assertNotIn("PY007", codes("# This function computes the final value for every input.\nvalue = 1\n"))
|
|
46
|
+
self.assertIn("PY007", codes("# Cette fonction calcule la valeur finale pour chaque entrée.\nvalue = 1\n"))
|
|
47
|
+
self.assertNotIn("PY007", codes("# This function computes the final value for every input.\nvalue = 1\n"))
|
|
49
48
|
|
|
50
49
|
def test_trailing_comment_stays_in_function_scope(self):
|
|
51
50
|
source = "def item():\n return 1\n # trailing inside function\n# outside function\n"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nk_python_style-0.1.0 → nk_python_style-0.2.0}/nk_python_style.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|