plain.code 0.1.0__py3-none-any.whl

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.
plain/code/README.md ADDED
File without changes
plain/code/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ from .cli import cli
2
+
3
+ __all__ = ["cli"]
plain/code/cli.py ADDED
@@ -0,0 +1,68 @@
1
+ import subprocess
2
+ import sys
3
+ from pathlib import Path
4
+
5
+ import click
6
+ import tomllib
7
+
8
+ from plain.cli.print import print_event
9
+
10
+ DEFAULT_RUFF_CONFIG = Path(__file__).parent / "ruff_defaults.toml"
11
+
12
+
13
+ @click.group()
14
+ def cli():
15
+ """Standard code formatting and linting."""
16
+ pass
17
+
18
+
19
+ @cli.command()
20
+ @click.argument("path", default=".")
21
+ def check(path):
22
+ """Check the given path for formatting or linting issues."""
23
+ ruff_args = ["--config", str(DEFAULT_RUFF_CONFIG)]
24
+
25
+ for e in get_code_config().get("exclude", []):
26
+ ruff_args.extend(["--exclude", e])
27
+
28
+ print_event("Ruff check")
29
+ result = subprocess.run(["ruff", "check", path, *ruff_args])
30
+
31
+ if result.returncode != 0:
32
+ sys.exit(result.returncode)
33
+
34
+ print_event("Ruff format check")
35
+ result = subprocess.run(["ruff", "format", path, "--check", *ruff_args])
36
+
37
+ if result.returncode != 0:
38
+ sys.exit(result.returncode)
39
+
40
+
41
+ @cli.command()
42
+ @click.argument("path", default=".")
43
+ def fix(path):
44
+ """Lint and format the given path."""
45
+ ruff_args = ["--config", str(DEFAULT_RUFF_CONFIG)]
46
+
47
+ for e in get_code_config().get("exclude", []):
48
+ ruff_args.extend(["--exclude", e])
49
+
50
+ print_event("Ruff check")
51
+ result = subprocess.run(["ruff", "check", path, "--fix", *ruff_args])
52
+
53
+ if result.returncode != 0:
54
+ sys.exit(result.returncode)
55
+
56
+ print_event("Ruff format")
57
+ result = subprocess.run(["ruff", "format", path, *ruff_args])
58
+
59
+ if result.returncode != 0:
60
+ sys.exit(result.returncode)
61
+
62
+
63
+ def get_code_config():
64
+ pyproject = Path("pyproject.toml")
65
+ if not pyproject.exists():
66
+ return {}
67
+ with pyproject.open("rb") as f:
68
+ return tomllib.load(f).get("tool", {}).get("plain", {}).get("code", {})
@@ -0,0 +1,21 @@
1
+ target-version = "py310"
2
+ ignore = [
3
+ "E501", # Never enforce `E501` (line length violations)
4
+ "S101", # pytest use of assert
5
+ "ISC001", # Implicit string concatenation
6
+ ]
7
+ extend-select = [
8
+ "I", # isort
9
+ # # "C90", # mccabe
10
+ # # "N", # pep8-naming
11
+ "UP", # pyupgrade
12
+ # "S", # bandit
13
+ # # "B", # bugbear
14
+ "C4", # flake8-comprehensions
15
+ # # "DTZ", # flake8-datetimez
16
+ "ISC", # flake8-implicit-str-concat
17
+ # # "G", # flake8-logging-format
18
+ # # "T20", # print
19
+ "PT", # pytest
20
+ "B006", # mutable-argument-default
21
+ ]
@@ -0,0 +1,28 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2023, Dropseed, LLC
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions are met:
7
+
8
+ 1. Redistributions of source code must retain the above copyright notice, this
9
+ list of conditions and the following disclaimer.
10
+
11
+ 2. Redistributions in binary form must reproduce the above copyright notice,
12
+ this list of conditions and the following disclaimer in the documentation
13
+ and/or other materials provided with the distribution.
14
+
15
+ 3. Neither the name of the copyright holder nor the names of its
16
+ contributors may be used to endorse or promote products derived from
17
+ this software without specific prior written permission.
18
+
19
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,14 @@
1
+ Metadata-Version: 2.1
2
+ Name: plain.code
3
+ Version: 0.1.0
4
+ Summary: Code formatting and linting for Plain.
5
+ Author: Dave Gaeddert
6
+ Author-email: dave.gaeddert@dropseed.dev
7
+ Requires-Python: >=3.8,<4.0
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.8
10
+ Classifier: Programming Language :: Python :: 3.9
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: ruff (>=0.1.0,<0.2.0)
@@ -0,0 +1,9 @@
1
+ plain/code/README.md,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ plain/code/__init__.py,sha256=9ByBOIdM8DebChjNz-RH2atdz4vWe8somlwNEsbhwh4,40
3
+ plain/code/cli.py,sha256=UQs_0W_51ZNAdmtghL6ncHJJ3jcR1CsC0J2pP6hEiTI,1739
4
+ plain/code/ruff_defaults.toml,sha256=NLXDuNNH3LO6UwUMM_m2nxJuq7PD4aDuV3TECCmTbbg,574
5
+ plain_code-0.1.0.dist-info/LICENSE,sha256=cvKM3OlqHx3ijD6e34zsSUkPvzl-ya3Dd63A6EHL94U,1500
6
+ plain_code-0.1.0.dist-info/METADATA,sha256=ClyxyVzX4i0MaFuYlenTq3Yn2K-vwzvjs-JxBAjGdIw,531
7
+ plain_code-0.1.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
8
+ plain_code-0.1.0.dist-info/entry_points.txt,sha256=-W1bnbnSqG2MZXkcTEPSpKfQbYPSQdwayzvI6evpMjs,56
9
+ plain_code-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 1.9.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,4 @@
1
+ [plain.cli]
2
+ code=plain.code:cli
3
+ fix=plain.code.cli:fix
4
+