codelaw 0.2.0__py3-none-win_amd64.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.
codelaw/__init__.py ADDED
@@ -0,0 +1,141 @@
1
+ """codelaw on PyPI: the Python API over the bundled binary (SR-PACKAGES decision 5).
2
+
3
+ Each call runs the binary this wheel installed and returns its ``--format json``
4
+ report unchanged, so the results are the binary's results (L6 decision 5).
5
+ """
6
+
7
+ from __future__ import annotations
8
+
9
+ import json
10
+ import os
11
+ import site
12
+ import subprocess
13
+ import sys
14
+ import sysconfig
15
+ from importlib import metadata
16
+ from collections.abc import Sequence
17
+ from typing import Any
18
+
19
+ __all__ = ["binary_path", "check", "fix", "format", "rules_for"]
20
+
21
+
22
+ def binary_path() -> str:
23
+ """The absolute path of the codelaw binary installed with this package."""
24
+ override = os.environ.get("CODELAW_BINARY")
25
+ if override:
26
+ return override
27
+ exe = "codelaw.exe" if sys.platform == "win32" else "codelaw"
28
+ # The file list this distribution installed: never another `codelaw` on the
29
+ # same bin folder (an npm -g shim, say).
30
+ try:
31
+ for f in metadata.files("codelaw") or ():
32
+ if f.name == exe and f.parent.name in ("bin", "Scripts", "scripts"):
33
+ path = str(f.locate())
34
+ if os.path.isfile(path):
35
+ return path
36
+ except metadata.PackageNotFoundError:
37
+ pass
38
+ schemes = [sysconfig.get_default_scheme()]
39
+ if sys.platform == "win32":
40
+ schemes.append("nt_user")
41
+ elif sys.platform == "darwin" and sys._framework: # type: ignore[attr-defined]
42
+ schemes.append("osx_framework_user")
43
+ else:
44
+ schemes.append("posix_user")
45
+ for scheme in schemes:
46
+ candidate = os.path.join(sysconfig.get_path("scripts", scheme), exe)
47
+ if os.path.isfile(candidate):
48
+ return candidate
49
+ # pip --target / an unusual layout: <prefix>/bin beside this package's site-packages.
50
+ here = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
51
+ for parent in (here, os.path.dirname(here), os.path.dirname(os.path.dirname(here))):
52
+ for sub in ("bin", "Scripts"):
53
+ candidate = os.path.join(parent, sub, exe)
54
+ if os.path.isfile(candidate):
55
+ return candidate
56
+ raise FileNotFoundError("codelaw: the binary this package installs is missing; reinstall codelaw")
57
+
58
+
59
+ def environment() -> dict[str, str]:
60
+ """The binary's environment: this interpreter's site-packages, so it finds the
61
+ codelaw-rules-* packs installed beside this package (SR-RULE-PACKS decision 4)."""
62
+ paths = list(site.getsitepackages())
63
+ user = site.getusersitepackages()
64
+ if isinstance(user, str) and os.path.isdir(user):
65
+ paths.append(user)
66
+ env = dict(os.environ)
67
+ env["CODELAW_SITE_PACKAGES"] = os.pathsep.join(paths)
68
+ return env
69
+
70
+
71
+ def _run(args: list[str]) -> dict[str, Any]:
72
+ r = subprocess.run([binary_path(), *args], capture_output=True, text=True, encoding="utf-8", env=environment())
73
+ # 0: clean, 1: diagnostics over the threshold; 2: the run could not start.
74
+ if r.returncode not in (0, 1):
75
+ raise RuntimeError(f"codelaw {args[0]} failed (exit {r.returncode}): {r.stderr.strip()}")
76
+ return json.loads(r.stdout)
77
+
78
+
79
+ def _common(lang: Sequence[str] | None, rule: Sequence[str] | None, threads: int | None, no_cache: bool) -> list[str]:
80
+ a: list[str] = []
81
+ if lang:
82
+ a += ["--lang", ",".join(lang)]
83
+ if rule:
84
+ a += ["--rule", ",".join(rule)]
85
+ if threads is not None:
86
+ a += ["--threads", str(threads)]
87
+ if no_cache:
88
+ a.append("--no-cache")
89
+ return a
90
+
91
+
92
+ def check(
93
+ paths: Sequence[str] = (),
94
+ *,
95
+ lang: Sequence[str] | None = None,
96
+ rule: Sequence[str] | None = None,
97
+ threads: int | None = None,
98
+ no_cache: bool = False,
99
+ ) -> dict[str, Any]:
100
+ """``codelaw check --format json``; returns the report."""
101
+ return _run(["check", "--format", "json", *_common(lang, rule, threads, no_cache), "--", *paths])
102
+
103
+
104
+ def fix(
105
+ paths: Sequence[str] = (),
106
+ *,
107
+ unsafe: bool = False,
108
+ dry_run: bool = False,
109
+ lang: Sequence[str] | None = None,
110
+ rule: Sequence[str] | None = None,
111
+ threads: int | None = None,
112
+ no_cache: bool = False,
113
+ ) -> dict[str, Any]:
114
+ """``codelaw fix --format json``; returns the report."""
115
+ a = ["fix", "--format", "json", *_common(lang, rule, threads, no_cache)]
116
+ if unsafe:
117
+ a.append("--unsafe")
118
+ if dry_run:
119
+ a.append("--dry-run")
120
+ return _run([*a, "--", *paths])
121
+
122
+
123
+ def format(
124
+ paths: Sequence[str] = (),
125
+ *,
126
+ check: bool = False,
127
+ lang: Sequence[str] | None = None,
128
+ rule: Sequence[str] | None = None,
129
+ threads: int | None = None,
130
+ no_cache: bool = False,
131
+ ) -> dict[str, Any]:
132
+ """``codelaw format --format json`` (``check``: write nothing); returns the report."""
133
+ a = ["format", "--format", "json", *_common(lang, rule, threads, no_cache)]
134
+ if check:
135
+ a.append("--check")
136
+ return _run([*a, "--", *paths])
137
+
138
+
139
+ def rules_for(path: str) -> dict[str, Any]:
140
+ """``codelaw rules --for <path> --format json``; returns the rules that apply to the file."""
141
+ return _run(["rules", "--for", path, "--format", "json"])
codelaw/__main__.py ADDED
@@ -0,0 +1,20 @@
1
+ """``python -m codelaw``: run the binary with this interpreter's site-packages,
2
+ so it finds the codelaw-rules-* packs installed beside it."""
3
+
4
+ import os
5
+ import subprocess
6
+ import sys
7
+
8
+ from codelaw import binary_path, environment
9
+
10
+
11
+ def main() -> int:
12
+ bin_ = binary_path()
13
+ if sys.platform == "win32":
14
+ return subprocess.run([bin_, *sys.argv[1:]], env=environment()).returncode
15
+ os.execve(bin_, [bin_, *sys.argv[1:]], environment())
16
+ return 2 # unreachable
17
+
18
+
19
+ if __name__ == "__main__":
20
+ sys.exit(main())
codelaw/py.typed ADDED
File without changes
Binary file
@@ -0,0 +1,84 @@
1
+ Metadata-Version: 2.4
2
+ Name: codelaw
3
+ Version: 0.2.0
4
+ Classifier: Development Status :: 3 - Alpha
5
+ Classifier: Environment :: Console
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Programming Language :: Rust
8
+ Classifier: Topic :: Software Development :: Quality Assurance
9
+ License-File: LICENSE
10
+ Summary: A linter and formatter whose rules are Markdown files
11
+ License-Expression: MIT
12
+ Requires-Python: >=3.11
13
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
14
+ Project-URL: Repository, https://github.com/arpitarya/codelaw
15
+
16
+ # codelaw
17
+
18
+ A linter and formatter whose rules are Markdown files — for JavaScript,
19
+ TypeScript, Python, JSON, YAML, TOML, Markdown, CSS and HTML, alone or mixed.
20
+
21
+ **One engine, two registries, identical output.** The same native binary ships
22
+ as `codelaw` on npm and on PyPI; neither needs the other.
23
+
24
+ ## Install
25
+
26
+ | your repo | engine | rules for its languages |
27
+ |---|---|---|
28
+ | Node | `npm i -D codelaw` | `npx codelaw init` adds the `@codelaw/rules-*` packs |
29
+ | Python | `uv add --dev codelaw` or `pip install codelaw` | `codelaw init` adds the `codelaw-rules-*` packs |
30
+
31
+ `codelaw` installed alone lints nothing until a rule pack is installed — it
32
+ says so (`codelaw/no-rules`).
33
+
34
+ **Rule packs** — each registry carries the packs its users install:
35
+
36
+ <!-- docs-sync:registries -->
37
+
38
+ | registry | named | packs |
39
+ |---|---|---|
40
+ | npm | `@codelaw/rules-<name>` | `js` · `ts` · `react` · `node` · `stencil` · `html` · `css` · `data` · `tanstack-query` · `redux-toolkit` |
41
+ | PyPI | `codelaw-rules-<name>` | `js` · `react` · `html` · `css` · `python` · `data` |
42
+
43
+ <!-- /docs-sync:registries -->
44
+
45
+ ## Use
46
+
47
+ ```bash
48
+ codelaw check # lint the project
49
+ codelaw fix # apply the safe fixes
50
+ codelaw check --format json
51
+ ```
52
+
53
+ **Programmatic API** — runs the bundled binary and returns its JSON report:
54
+
55
+ ```js
56
+ import { check, fix, format, rulesFor } from "codelaw";
57
+ const report = check(["src"]);
58
+ const rules = rulesFor("src/app.ts");
59
+ ```
60
+
61
+ ```python
62
+ import codelaw
63
+ report = codelaw.check(["src"])
64
+ rules = codelaw.rules_for("app/main.py")
65
+ ```
66
+
67
+ | npm | Python | what it returns |
68
+ |---|---|---|
69
+ | `check(paths, options)` | `check(paths, …)` | `codelaw check --format json` |
70
+ | `fix(paths, options)` | `fix(paths, …)` | `codelaw fix --format json`; `unsafe`, `dryRun` / `dry_run` |
71
+ | `format(paths, options)` | `format(paths, …)` | `codelaw format --format json`; `check` writes nothing |
72
+ | `rulesFor(path)` | `rules_for(path)` | the rules that apply to one file, as `codelaw rules --for` lists them |
73
+ | `binaryPath()`, `platformKey()` | `binary_path()` | the bundled binary, and the platform key it was chosen by |
74
+
75
+ ## Platforms
76
+
77
+ macOS arm64 and x64 · Linux x64 and arm64, glibc and musl · Windows x64 and
78
+ arm64. Any other platform fails with an error naming these — codelaw never
79
+ compiles from source at install time.
80
+
81
+ ## Licence
82
+
83
+ MIT — <https://github.com/arpitarya/codelaw>
84
+
@@ -0,0 +1,9 @@
1
+ codelaw/__init__.py,sha256=Il5UHow86oQHj4gsDr3acyB_hDNrlit981j3yZ4H0os,5183
2
+ codelaw/__main__.py,sha256=08N9wWTtc78DiYj5BibVK7K1RGFfIfvRiYz29wXbITM,545
3
+ codelaw/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ codelaw-0.2.0.data/scripts/codelaw.exe,sha256=7U4eSRSnXz_7dL6g5Vt1_PLY6nWChgY-2NANHiltCQI,31650304
5
+ codelaw-0.2.0.dist-info/METADATA,sha256=kdP506TJa_QZSPOj56FhJCuqacpZ451ZDvuLf2LS-FQ,3018
6
+ codelaw-0.2.0.dist-info/WHEEL,sha256=8Aej0W0a6Cz6apA3IzJrTnxLRVLAt-w0Oh8SA3Con_c,94
7
+ codelaw-0.2.0.dist-info/licenses/LICENSE,sha256=zTmq9OahL66ocAprU1NqLgC0pnoZX9h_cQ3HfgBt1Kw,1120
8
+ codelaw-0.2.0.dist-info/sboms/codelaw-cli.cyclonedx.json,sha256=XQ9sH9c18hCXPuUrtB0Jech_Y2hHjMsNCojUZZqUYJc,416246
9
+ codelaw-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.15.0)
3
+ Root-Is-Purelib: false
4
+ Tag: py3-none-win_amd64
@@ -0,0 +1,23 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Arpit Arya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
23
+ SPDX-License-Identifier: MIT