noxpy 0.1.0a1__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.
- noxpy/__init__.py +25 -0
- noxpy/__main__.py +165 -0
- noxpy/_native/cpython/noxpy_shim.c +568 -0
- noxpy/_native/include/nox_host.h +77 -0
- noxpy/_native/include/noxpy_abi.h +163 -0
- noxpy/audit.py +190 -0
- noxpy/build.py +604 -0
- noxpy/codegen.py +283 -0
- noxpy/config.py +220 -0
- noxpy/doctor.py +145 -0
- noxpy/errors.py +46 -0
- noxpy/ir.py +272 -0
- noxpy-0.1.0a1.dist-info/METADATA +121 -0
- noxpy-0.1.0a1.dist-info/RECORD +18 -0
- noxpy-0.1.0a1.dist-info/WHEEL +5 -0
- noxpy-0.1.0a1.dist-info/entry_points.txt +2 -0
- noxpy-0.1.0a1.dist-info/licenses/LICENSE +21 -0
- noxpy-0.1.0a1.dist-info/top_level.txt +1 -0
noxpy/__init__.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""NoxPy — Native Python extensions written in Nox."""
|
|
2
|
+
|
|
3
|
+
from .config import NoxPyProjectConfig, load_pyproject
|
|
4
|
+
from .errors import NoxPyError
|
|
5
|
+
from .ir import (
|
|
6
|
+
ExportedFunctionIR,
|
|
7
|
+
ModuleIR,
|
|
8
|
+
ParamIR,
|
|
9
|
+
SourceSpan,
|
|
10
|
+
parse_upstream_metadata_json,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__version__ = "0.1.0a1"
|
|
14
|
+
|
|
15
|
+
__all__ = [
|
|
16
|
+
"__version__",
|
|
17
|
+
"ExportedFunctionIR",
|
|
18
|
+
"ModuleIR",
|
|
19
|
+
"NoxPyError",
|
|
20
|
+
"NoxPyProjectConfig",
|
|
21
|
+
"ParamIR",
|
|
22
|
+
"SourceSpan",
|
|
23
|
+
"load_pyproject",
|
|
24
|
+
"parse_upstream_metadata_json",
|
|
25
|
+
]
|
noxpy/__main__.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Thin CLI entry point for `python -m noxpy` (`AGENTS.md` §15.4)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import json
|
|
7
|
+
import sys
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from .build import build_project_wheel, develop_install, scaffold_project
|
|
11
|
+
from .codegen import generate_c_adapter, generate_pyi
|
|
12
|
+
from .config import load_pyproject
|
|
13
|
+
from .doctor import collect_doctor_report
|
|
14
|
+
from .errors import NoxPyError
|
|
15
|
+
from .ir import parse_upstream_metadata_json
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _cmd_doctor(args: argparse.Namespace) -> int:
|
|
19
|
+
report = collect_doctor_report()
|
|
20
|
+
if args.json:
|
|
21
|
+
sys.stdout.write(json.dumps(report, indent=2) + "\n")
|
|
22
|
+
else:
|
|
23
|
+
py = report["python"]
|
|
24
|
+
nx = report["noxc"]
|
|
25
|
+
p315t = report["python_315t"]
|
|
26
|
+
print(f"Python: {py['version']} ({py['executable']}) abi3t_headers={py['abi3t_header_ready']}")
|
|
27
|
+
print(f"PythonT: found={p315t['found']} ({p315t['probe']})")
|
|
28
|
+
print(f"noxc: found={nx['found']} version={nx['version']} path={nx['path']}")
|
|
29
|
+
print(f"clang: found={report['clang']['found']} ({report['clang']['version']})")
|
|
30
|
+
print(f"rtk: found={report['rtk']['found']} ({report['rtk']['version']})")
|
|
31
|
+
print(
|
|
32
|
+
f"Phase: {report['phase_gate']['current_phase']} "
|
|
33
|
+
f"(phase0_exit_ready={report['phase_gate']['phase0_exit_ready']}, "
|
|
34
|
+
f"phase1_ready={report['phase_gate']['phase1_ready']})"
|
|
35
|
+
)
|
|
36
|
+
return 0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _cmd_check(args: argparse.Namespace) -> int:
|
|
40
|
+
pyproject_path = Path(args.pyproject).resolve()
|
|
41
|
+
cfg = load_pyproject(pyproject_path)
|
|
42
|
+
ir = None
|
|
43
|
+
if args.ir:
|
|
44
|
+
raw = json.loads(Path(args.ir).read_text(encoding="utf-8"))
|
|
45
|
+
ir = parse_upstream_metadata_json(
|
|
46
|
+
raw,
|
|
47
|
+
expected_module_name=cfg.module_name,
|
|
48
|
+
abi=cfg.abi,
|
|
49
|
+
free_threaded=cfg.free_threaded,
|
|
50
|
+
)
|
|
51
|
+
elif getattr(args, "inspect", False):
|
|
52
|
+
from .build import inspect_module_ir
|
|
53
|
+
|
|
54
|
+
ir = inspect_module_ir(pyproject_path.parent, cfg)
|
|
55
|
+
|
|
56
|
+
if args.json:
|
|
57
|
+
out: dict[str, object] = {
|
|
58
|
+
"status": "ok",
|
|
59
|
+
"distribution": cfg.distribution_name,
|
|
60
|
+
"module": cfg.module_name,
|
|
61
|
+
"abi": cfg.abi,
|
|
62
|
+
"free_threaded": cfg.free_threaded,
|
|
63
|
+
}
|
|
64
|
+
if ir is not None:
|
|
65
|
+
out["exported_functions"] = [f.name for f in ir.functions]
|
|
66
|
+
sys.stdout.write(json.dumps(out, indent=2) + "\n")
|
|
67
|
+
else:
|
|
68
|
+
print(f"OK: {cfg.distribution_name} ({cfg.module_name}, {cfg.abi})")
|
|
69
|
+
return 0
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def _cmd_generate_stubs(args: argparse.Namespace) -> int:
|
|
73
|
+
raw = json.loads(Path(args.ir).read_text(encoding="utf-8"))
|
|
74
|
+
ir = parse_upstream_metadata_json(raw)
|
|
75
|
+
sys.stdout.write(generate_pyi(ir))
|
|
76
|
+
if args.emit_c:
|
|
77
|
+
sys.stdout.write("\n/* --- C ADAPTER --- */\n")
|
|
78
|
+
sys.stdout.write(generate_c_adapter(ir))
|
|
79
|
+
return 0
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def _cmd_build(args: argparse.Namespace) -> int:
|
|
83
|
+
proj = Path(args.project).resolve()
|
|
84
|
+
out_dir = Path(args.out_dir).resolve() if args.out_dir else (proj / "dist")
|
|
85
|
+
res = build_project_wheel(proj, out_dir, release=bool(args.release))
|
|
86
|
+
if args.json:
|
|
87
|
+
sys.stdout.write(json.dumps(res.to_dict(), indent=2) + "\n")
|
|
88
|
+
else:
|
|
89
|
+
print(f"Built wheel: {res.wheel_path}")
|
|
90
|
+
print(f"Tags: {', '.join(res.tags)}")
|
|
91
|
+
print(f"SHA-256: {res.wheel_sha256}")
|
|
92
|
+
print(f"Exports: {', '.join(res.exported_functions)}")
|
|
93
|
+
return 0
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _cmd_develop(args: argparse.Namespace) -> int:
|
|
97
|
+
res = develop_install(args.project, python_exe=args.python, release=bool(args.release))
|
|
98
|
+
if args.json:
|
|
99
|
+
sys.stdout.write(json.dumps(res.to_dict(), indent=2) + "\n")
|
|
100
|
+
else:
|
|
101
|
+
print(f"Installed {res.module_name} ({', '.join(res.exported_functions)})")
|
|
102
|
+
return 0
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _cmd_new(args: argparse.Namespace) -> int:
|
|
106
|
+
dest = scaffold_project(args.name, args.dir)
|
|
107
|
+
if args.json:
|
|
108
|
+
sys.stdout.write(json.dumps({"status": "ok", "path": str(dest), "name": args.name}, indent=2) + "\n")
|
|
109
|
+
else:
|
|
110
|
+
print(f"Created NoxPy project at {dest}")
|
|
111
|
+
return 0
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def main(argv: list[str] | None = None) -> int:
|
|
115
|
+
parser = argparse.ArgumentParser(prog="noxpy")
|
|
116
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
117
|
+
|
|
118
|
+
p_doc = sub.add_parser("doctor", help="Inspect toolchain, CPython 3.15/3.15t, and readiness.")
|
|
119
|
+
p_doc.add_argument("--json", action="store_true")
|
|
120
|
+
p_doc.set_defaults(func=_cmd_doctor)
|
|
121
|
+
|
|
122
|
+
p_chk = sub.add_parser("check", help="Validate pyproject.toml and optional UR-007 IR JSON manifest.")
|
|
123
|
+
p_chk.add_argument("pyproject", nargs="?", default="pyproject.toml")
|
|
124
|
+
p_chk.add_argument("--ir", help="Path to UR-007 JSON metadata manifest.")
|
|
125
|
+
p_chk.add_argument("--inspect", action="store_true", help="Invoke noxc expand --json on source.")
|
|
126
|
+
p_chk.add_argument("--json", action="store_true")
|
|
127
|
+
p_chk.set_defaults(func=_cmd_check)
|
|
128
|
+
|
|
129
|
+
p_stubs = sub.add_parser("generate-stubs", help="Generate deterministic .pyi from UR-007 IR JSON.")
|
|
130
|
+
p_stubs.add_argument("--ir", required=True, help="Path to UR-007 JSON metadata manifest.")
|
|
131
|
+
p_stubs.add_argument("--emit-c", action="store_true", help="Also print generated abi3t C adapter.")
|
|
132
|
+
p_stubs.set_defaults(func=_cmd_generate_stubs)
|
|
133
|
+
|
|
134
|
+
p_bld = sub.add_parser("build", help="Compile Nox extension and package audited cp315-abi3.abi3t wheel.")
|
|
135
|
+
p_bld.add_argument("project", nargs="?", default=".", help="Project directory containing pyproject.toml.")
|
|
136
|
+
p_bld.add_argument("--out-dir", "-o", help="Output wheel directory (defaults to <project>/dist).")
|
|
137
|
+
p_bld.add_argument("--release", action="store_true", help="Enable noxc --release optimization.")
|
|
138
|
+
p_bld.add_argument("--json", action="store_true")
|
|
139
|
+
p_bld.set_defaults(func=_cmd_build)
|
|
140
|
+
|
|
141
|
+
p_dev = sub.add_parser("develop", help="Build and install extension into active or --python virtualenv.")
|
|
142
|
+
p_dev.add_argument("project", nargs="?", default=".", help="Project directory containing pyproject.toml.")
|
|
143
|
+
p_dev.add_argument("--python", help="Target virtualenv Python interpreter.")
|
|
144
|
+
p_dev.add_argument("--release", action="store_true")
|
|
145
|
+
p_dev.add_argument("--json", action="store_true")
|
|
146
|
+
p_dev.set_defaults(func=_cmd_develop)
|
|
147
|
+
|
|
148
|
+
p_new = sub.add_parser("new", help="Scaffold a new Phase 1 NoxPy extension project.")
|
|
149
|
+
p_new.add_argument("name", help="Distribution/module identifier (e.g. fastmath).")
|
|
150
|
+
p_new.add_argument("--dir", help="Target directory (defaults to ./<name>).")
|
|
151
|
+
p_new.add_argument("--json", action="store_true")
|
|
152
|
+
p_new.set_defaults(func=_cmd_new)
|
|
153
|
+
|
|
154
|
+
args = parser.parse_args(argv)
|
|
155
|
+
try:
|
|
156
|
+
return int(args.func(args))
|
|
157
|
+
except NoxPyError as exc:
|
|
158
|
+
sys.stderr.write(f"error: {exc}\n")
|
|
159
|
+
if exc.hint:
|
|
160
|
+
sys.stderr.write(f"hint: {exc.hint}\n")
|
|
161
|
+
return 1
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
if __name__ == "__main__":
|
|
165
|
+
raise SystemExit(main())
|