Skip to content

Commit ef3ffe5

Browse files
committed
dev-env: Refactor the repository structure to add the Rust-based recorder
AGENTS.md: README.md: crates/codetracer-python-recorder/Cargo.toml: crates/codetracer-python-recorder/pyproject.toml: crates/codetracer-python-recorder/src/lib.rs: flake.nix: Signed-off-by: Tzanko Matev <[email protected]>
1 parent 42c1bd9 commit ef3ffe5

File tree

6 files changed

+110
-19
lines changed

6 files changed

+110
-19
lines changed

AGENTS.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
11
# Instructions for Codex
22

3-
To run the test suite, execute:
3+
This repository contains two related projects:
4+
5+
- codetracer-pure-python-recorder — the original pure-Python tracer.
6+
- codetracer-python-recorder — a Rust-backed Python module built with PyO3 and maturin.
7+
8+
To run the Python test suite for the pure-Python tracer, execute:
49

510
```
611
make test
712
```
813

914
The tester executes a number of sample programs in `tests/programs` and compares their outputs to the fixtures in `tests/fixtures`.
1015

16+
To build and locally develop-install the Rust-backed module:
17+
18+
```
19+
maturin develop -m crates/codetracer-python-recorder/Cargo.toml
20+
```
21+
1122
# Code quality guidelines
1223

1324
- Strive to achieve high code quality.
@@ -33,4 +44,4 @@ https://www.conventionalcommits.org/en/v1.0.0/
3344

3445
In the remaining lines, provide a short description of the implemented functionality.
3546
Provide sufficient details for the justification of each design decision if multiple
36-
approaches were considered.
47+
approaches were considered.

README.md

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,57 @@
1-
## codetracer-python-recorder
1+
## CodeTracer Recorders (Monorepo)
22

3-
An unfinished prototype of a recorder of Python programs that produces [CodeTracer](https://github.com/metacraft-labs/CodeTracer) traces.
3+
This repository now hosts two related projects:
44

5-
> [!WARNING]
6-
> Currently it is in a very early phase: we're welcoming contribution and discussion!
5+
- codetracer-pure-python-recorder — the existing pure-Python prototype that records [CodeTracer](https://github.com/metacraft-labs/CodeTracer) traces using sys.settrace.
6+
- codetracer-python-recorder — a new, Rust-backed Python extension module (PyO3) intended to provide a faster and more featureful recorder.
77

8+
> [!WARNING]
9+
> Both projects are early-stage prototypes. Contributions and discussion are welcome!
810
9-
### Usage
11+
### codetracer-pure-python-recorder
1012

11-
Install the package with `pip` or `uv`:
13+
Install from PyPI:
1214

1315
```bash
14-
pip install codetracer-python-recorder
16+
pip install codetracer-pure-python-recorder
1517
```
1618

17-
Then invoke the recorder as a command line tool:
19+
CLI usage:
1820

1921
```bash
2022
codetracer-record <path to python file>
2123
# produces several trace json files in the current directory
2224
# or in the folder of `$CODETRACER_DB_TRACE_PATH` if such an env var is defined
2325
```
2426

25-
During development you can also run it directly with
27+
During development you can also run it directly:
2628

2729
```bash
28-
python trace.py <path to python file>
30+
python src/trace.py <path to python file>
2931
# produces several trace json files in the current directory
3032
# or in the folder of `$CODETRACER_DB_TRACE_PATH` if such an env var is defined
3133
```
3234

33-
however you probably want to use it in combination with CodeTracer, which would be released soon.
35+
### codetracer-python-recorder (Rust-backed)
36+
37+
A separate Python module implemented in Rust with PyO3 and built via maturin lives under:
38+
crates/codetracer-python-recorder/
39+
40+
Basic workflow:
41+
42+
- Build/dev install the Rust module:
43+
- maturin develop -m crates/codetracer-python-recorder/Cargo.toml
44+
- Use in Python:
45+
- from codetracer_python_recorder import hello
46+
- hello()
3447

35-
## Future directions
48+
### Future directions
3649

3750
The current Python support is an unfinished prototype. We can finish it. In the future, it may be expanded to function in a way to similar to the more complete implementations, e.g. [Noir](https://github.com/blocksense-network/noir/tree/blocksense/tooling/tracer).
3851

3952
Currently it's very similar to our [Ruby tracer](https://github.com/metacraft-labs/ct-ruby-tracer)
4053

41-
### Current approach: sys.settrace API
54+
#### Current approach: sys.settrace API
4255

4356
Currently we're using the sys.settrace API: https://docs.python.org/3/library/sys.html#sys.settrace .
4457
This is very flexible and can function with probably multiple Python versions out of the box.
@@ -49,15 +62,15 @@ However, this is limited:
4962

5063
For other languages, we've used a more deeply integrated approach: patching the interpreter or VM itself (e.g. Noir).
5164

52-
### Patching the VM
65+
#### Patching the VM
5366

5467
This can be a good approach for Python as well: it can let us record more precisely subvalues, assignments and subexpressions and to let
5568
some CodeTracer features work in a deeper/better way.
5669

5770
One usually needs to add additional logic to places where new opcodes/lines are being ran, and to call entries/exits. Additionally
5871
tracking assignments can be a great addition, but it really depends on the interpreter internals.
5972

60-
### Filtering
73+
#### Filtering
6174

6275
It would be useful to have a way to record in detail only certain periods of the program, or certain functions or modules:
6376
we plan on expanding the [trace format](https://github.com/metacraft-labs/runtime_tracing/) and CodeTracer' support, so that this is possible. It would let one be able to record interesting
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "codetracer-python-recorder"
3+
version = "0.1.0"
4+
edition = "2021"
5+
license = "MIT"
6+
description = "Rust-backed Python module for CodeTracer recording (PyO3)"
7+
repository = "https://github.com/metacraft-labs/codetracer-python-recorder"
8+
9+
[lib]
10+
name = "codetracer_python_recorder"
11+
crate-type = ["cdylib"]
12+
13+
[dependencies]
14+
pyo3 = { version = "0.21", features = ["extension-module"] }
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[build-system]
2+
requires = ["maturin>=1.5,<2"]
3+
build-backend = "maturin"
4+
5+
[project]
6+
name = "codetracer-python-recorder"
7+
version = "0.1.0"
8+
description = "Rust-backed Python module for CodeTracer recording (PyO3)"
9+
authors = [{name = "Metacraft Labs Ltd"}]
10+
license = {text = "MIT"}
11+
requires-python = ">=3.8"
12+
classifiers = [
13+
"License :: OSI Approved :: MIT License",
14+
"Programming Language :: Python :: 3",
15+
"Programming Language :: Python :: 3 :: Only",
16+
"Programming Language :: Rust",
17+
]
18+
19+
[tool.maturin]
20+
# Build the PyO3 extension module
21+
bindings = "pyo3"
22+
# Use the library name as the Python import name: codetracer_python_recorder
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
use pyo3::prelude::*;
2+
3+
/// codetracer_python_recorder
4+
///
5+
/// Minimal placeholder for the Rust-backed recorder. This exposes a trivial
6+
/// function to verify the module builds and imports successfully.
7+
#[pyfunction]
8+
fn hello() -> PyResult<String> {
9+
Ok("Hello from codetracer-python-recorder (Rust)".to_string())
10+
}
11+
12+
#[pymodule]
13+
fn codetracer_python_recorder(_py: Python<'_>, m: &PyModule) -> PyResult<()> {
14+
m.add_function(wrap_pyfunction!(hello, m)?)?;
15+
Ok(())
16+
}

flake.nix

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
description = "Development environment for codetracer-python-recorder";
2+
description = "Development environment for CodeTracer recorders (pure-python and rust-backed)";
33

44
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.05";
55

@@ -12,7 +12,22 @@
1212
let pkgs = import nixpkgs { inherit system; };
1313
in {
1414
default = pkgs.mkShell {
15-
packages = with pkgs; [ bashInteractive python3 just git-lfs ];
15+
packages = with pkgs; [
16+
bashInteractive
17+
python3
18+
just
19+
git-lfs
20+
21+
# Rust toolchain for the Rust-backed Python module
22+
cargo
23+
rustc
24+
rustfmt
25+
clippy
26+
27+
# Build tooling for Python extensions
28+
maturin
29+
pkg-config
30+
];
1631
};
1732
});
1833
};

0 commit comments

Comments
 (0)