Skip to content

Commit ecaaf92

Browse files
authored
feat: add packaging setup (#9)
1 parent bfc928c commit ecaaf92

File tree

3 files changed

+50
-6
lines changed

3 files changed

+50
-6
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,21 @@ An unfinished prototype of a recorder of Python programs that produces [CodeTrac
88

99
### Usage
1010

11-
you can currently use it directly with
11+
Install the package with `pip` or `uv`:
12+
13+
```bash
14+
pip install codetracer-python-recorder
15+
```
16+
17+
Then invoke the recorder as a command line tool:
18+
19+
```bash
20+
codetracer-record <path to python file>
21+
# produces several trace json files in the current directory
22+
# or in the folder of `$CODETRACER_DB_TRACE_PATH` if such an env var is defined
23+
```
24+
25+
During development you can also run it directly with
1226

1327
```bash
1428
python trace.py <path to python file>

pyproject.toml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
[build-system]
2+
requires = ["setuptools>=61"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[project]
6+
name = "codetracer-python-recorder"
7+
version = "0.1.0"
8+
description = "Prototype recorder of Python programs producing CodeTracer traces"
9+
authors = [{name = "Metacraft Labs Ltd"}]
10+
license = {text = "MIT"}
11+
readme = "README.md"
12+
requires-python = ">=3.8"
13+
classifiers = [
14+
"License :: OSI Approved :: MIT License",
15+
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python :: 3 :: Only",
17+
]
18+
19+
[tool.setuptools]
20+
py-modules = ["trace"]
21+
package-dir = {"" = "src"}
22+
23+
[project.scripts]
24+
codetracer-record = "trace:main"

src/trace.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,17 +200,23 @@ def local_trace(frame: types.FrameType, event: str, arg: Any):
200200
return tracer
201201

202202

203-
if __name__ == "__main__":
204-
if len(sys.argv) < 2:
205-
raise SystemExit("Usage: trace.py <program.py>")
203+
def main(argv: List[str] | None = None) -> None:
204+
"""Entry point for the command line interface."""
206205

207-
program_path = sys.argv[1]
206+
if len(argv) < 1:
207+
raise SystemExit("Usage: codetracer-record <program.py>")
208+
209+
program_path = argv[0]
208210
tracer = trace_program(program_path)
209211

210-
meta = {"workdir": os.getcwd(), "program": sys.argv[0], "args": sys.argv[1:]}
212+
meta = {"workdir": os.getcwd(), "program": sys.argv[0], "args": argv}
211213
with open("trace_metadata.json", "w") as f:
212214
json.dump(meta, f, indent=2)
213215
with open("trace_paths.json", "w") as f:
214216
json.dump(tracer.paths, f, indent=2)
215217
with open("trace.json", "w") as f:
216218
json.dump(tracer.events, f, indent=2)
219+
220+
221+
if __name__ == "__main__": # pragma: no cover - CLI passthrough
222+
main(sys.argv[1:])

0 commit comments

Comments
 (0)