Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 38d9271

Browse files
agentnocorpkossnocorp
authored andcommitted
fix(python): fix cyclic refs in Python (closes #21)
> Co-authored-by: Sasha Koss <[email protected]>:
1 parent 50da5d7 commit 38d9271

17 files changed

Lines changed: 580 additions & 16 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

examples/04-edge-cases/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
.venv/
3+
uv.lock
4+
*.egg-info/
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "genotype-test-cyclic-refs"
2+
out = "dist/py-latest"
3+
4+
[py]
5+
enabled = true
6+
version = "latest"
7+
8+
[py.manifest]
9+
name = "module"
10+
version = "0.1.0"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name = "genotype-test-cyclic-refs"
2+
out = "dist/py-legacy"
3+
4+
[py]
5+
enabled = true
6+
version = "legacy"
7+
8+
[py.manifest]
9+
name = "module"
10+
version = "0.1.0"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[project]
2+
name = "genotype-test-cyclic-refs"
3+
version = "0.1.0"
4+
requires-python = ">=3.8"
5+
dependencies = ["genotype-runtime"]
6+
7+
[tool.uv.sources]
8+
genotype-runtime = { path = "../../../pkgs/pip-genotype-runtime", editable = true }
9+
10+
[build-system]
11+
requires = ["setuptools>=68"]
12+
build-backend = "setuptools.build_meta"
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
JsonAny: JsonNull | JsonBoolean | JsonNumber | JsonString | JsonArray | JsonObject | JsonUnion | JsonLiteral | JsonTuple
2+
3+
JsonBase: {
4+
name?: string,
5+
doc?: string,
6+
}
7+
8+
JsonNull: {
9+
...JsonBase,
10+
kind: "null",
11+
}
12+
13+
JsonBoolean: {
14+
...JsonBase,
15+
kind: "boolean",
16+
}
17+
18+
JsonNumber: {
19+
...JsonBase,
20+
kind: "number",
21+
}
22+
23+
JsonString: {
24+
...JsonBase,
25+
kind: "string",
26+
}
27+
28+
JsonArray: {
29+
...JsonBase,
30+
kind: "array",
31+
descriptor: JsonAny,
32+
}
33+
34+
JsonObject: {
35+
...JsonBase,
36+
kind: "object",
37+
properties: [JsonProperty],
38+
}
39+
40+
JsonProperty: {
41+
kind: "property",
42+
name: string,
43+
doc?: string,
44+
descriptor: JsonAny,
45+
required?: boolean,
46+
}
47+
48+
JsonUnion: {
49+
...JsonBase,
50+
kind: "union",
51+
descriptors: [JsonAny],
52+
}
53+
54+
JsonTuple: {
55+
...JsonBase,
56+
kind: "tuple",
57+
descriptors: [JsonAny],
58+
}
59+
60+
JsonLiteral: {
61+
...JsonBase,
62+
kind: "literal",
63+
value: string | number | boolean | null,
64+
}
65+
66+
JsonLiteralKind: "string" | "number" | "boolean" | "null"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
import types
3+
4+
5+
def install_genotype_runtime_stub() -> None:
6+
genotype = types.ModuleType("genotype")
7+
8+
class Model:
9+
pass
10+
11+
genotype.Model = Model
12+
sys.modules["genotype"] = genotype
13+
14+
15+
def main() -> None:
16+
install_genotype_runtime_stub()
17+
import module.json # noqa: F401
18+
19+
print("🟢 OK: imported generated module")
20+
21+
22+
if __name__ == "__main__":
23+
main()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
LATEST_VERSIONS=(
6+
"3.14"
7+
"3.13"
8+
"3.12"
9+
)
10+
11+
LEGACY_VERSIONS=(
12+
"3.11"
13+
"3.10"
14+
"3.9"
15+
"3.8"
16+
)
17+
18+
build_for() {
19+
version_family="$1"
20+
echo -e "🌀 Building for $version_family Python"
21+
if output=$(cargo run -p genotype_cli --bin gt -- build . --config "genotype.py-${version_family}.toml" 2>&1); then
22+
echo "🟢 Build: OK"
23+
else
24+
echo "🔴 Build: FAILED"
25+
echo "--- Output ------------------------------------------"
26+
echo "$output"
27+
echo "-----------------------------------------------------"
28+
exit 1
29+
fi
30+
echo
31+
}
32+
33+
run_tests_for() {
34+
version_family="$1"
35+
python_version="$2"
36+
PYTHONPATH="dist/py-${version_family}/py${PYTHONPATH:+:$PYTHONPATH}"
37+
38+
if output=$(PYTHONPATH="$PYTHONPATH" uv run --python $python_version python test.py 2>&1); then
39+
echo "🟢 Python $python_version: OK"
40+
else
41+
echo "🔴 Python $python_version: FAILED"
42+
echo "--- Output ------------------------------------------"
43+
echo "$output"
44+
echo "-----------------------------------------------------"
45+
exit 1
46+
fi
47+
}
48+
49+
build_for "latest"
50+
for version in "${LATEST_VERSIONS[@]}"; do
51+
run_tests_for "latest" "$version"
52+
done
53+
54+
echo
55+
56+
build_for "legacy"
57+
for version in "${LEGACY_VERSIONS[@]}"; do
58+
run_tests_for "legacy" "$version"
59+
done
60+
61+
echo
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
JsonAny: JsonNull | JsonBoolean | JsonNumber | JsonString | JsonArray | JsonObject | JsonUnion | JsonLiteral | JsonTuple
2+
3+
JsonBase: {
4+
name?: string,
5+
doc?: string,
6+
}
7+
8+
JsonNull: {
9+
...JsonBase,
10+
kind: "null",
11+
}
12+
13+
JsonBoolean: {
14+
...JsonBase,
15+
kind: "boolean",
16+
}
17+
18+
JsonNumber: {
19+
...JsonBase,
20+
kind: "number",
21+
}
22+
23+
JsonString: {
24+
...JsonBase,
25+
kind: "string",
26+
}
27+
28+
JsonArray: {
29+
...JsonBase,
30+
kind: "array",
31+
descriptor: JsonAny,
32+
}
33+
34+
JsonObject: {
35+
...JsonBase,
36+
kind: "object",
37+
properties: [JsonProperty],
38+
}
39+
40+
JsonProperty: {
41+
kind: "property",
42+
name: string,
43+
doc?: string,
44+
descriptor: JsonAny,
45+
required?: boolean,
46+
}
47+
48+
JsonUnion: {
49+
...JsonBase,
50+
kind: "union",
51+
descriptors: [JsonAny],
52+
}
53+
54+
JsonTuple: {
55+
...JsonBase,
56+
kind: "tuple",
57+
descriptors: [JsonAny],
58+
}
59+
60+
JsonLiteral: {
61+
...JsonBase,
62+
kind: "literal",
63+
value: string | number | boolean | null,
64+
}
65+
66+
JsonLiteralKind: "string" | "number" | "boolean" | "null"

pkgs/crate-genotype-lang-py-project/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ pub use error::*;
44
mod module;
55
pub use module::*;
66

7-
mod index;
8-
pub use index::*;
7+
mod project;
8+
pub use project::*;
99

1010
mod manifest;
1111
pub use manifest::*;

0 commit comments

Comments
 (0)