Skip to content

Commit c913cac

Browse files
committed
Break examples out of main workspace
As features are unified over the whole of a workspace, having the examples inside the main workspace prevents independent tests of different combinations of PyO3 features. Therefore, this PR breaks them out into separate workspaces and adjust the xtask script to still include them where appropriate.
1 parent 4454e04 commit c913cac

File tree

6 files changed

+31
-19
lines changed

6 files changed

+31
-19
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ jobs:
6666
run: |
6767
import toml
6868
cargo_toml = toml.load("Cargo.toml")
69-
cargo_toml["workspace"]["resolver"] = "2"
69+
cargo_toml["package"]["resolver"] = "2"
7070
with open("Cargo.toml", "w") as f:
7171
toml.dump(cargo_toml, f)
7272
shell: python
@@ -116,14 +116,13 @@ jobs:
116116
continue-on-error: true
117117
- name: Install toml
118118
run: pip install toml
119-
- name: Edit Cargo.toml and detach from workspace
119+
- name: Edit Cargo.toml
120120
run: |
121121
import toml
122122
cargo_toml = toml.load("Cargo.toml")
123123
cargo_toml["dependencies"]["ndarray"] = "0.13.1"
124124
cargo_toml["dependencies"]["parking_lot"] = "0.11.2"
125125
cargo_toml["dependencies"]["num-complex"] = "0.2.4"
126-
cargo_toml["workspace"] = {}
127126
with open("Cargo.toml", "w") as f:
128127
toml.dump(cargo_toml, f)
129128
working-directory: examples/simple

Cargo.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,5 @@ pyo3 = { version = "0.16", default-features = false, features = ["macros"] }
2727
[dev-dependencies]
2828
pyo3 = { version = "0.16", default-features = false, features = ["auto-initialize"] }
2929

30-
[workspace]
31-
members = ["examples/*"]
32-
3330
[package.metadata.docs.rs]
3431
all-features = true

examples/linalg/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ crate-type = ["cdylib"]
1212
pyo3 = { version = "0.16", features = ["extension-module"] }
1313
numpy = { path = "../.." }
1414
ndarray-linalg = { version = "0.14.1", features = ["openblas-system"] }
15+
16+
[workspace]

examples/parallel/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@ numpy = { path = "../.." }
1414
ndarray = { version = "0.15", features = ["rayon", "blas"] }
1515
blas-src = { version = "0.8", features = ["openblas"] }
1616
openblas-src = { version = "0.10", features = ["cblas", "system"] }
17+
18+
[workspace]

examples/simple/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ crate-type = ["cdylib"]
1111
[dependencies]
1212
pyo3 = { version = "0.16", features = ["extension-module", "abi3-py37"] }
1313
numpy = { path = "../.." }
14+
15+
[workspace]

x.py

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,20 @@ def nightly():
2424
return b"-nightly " in proc.stdout
2525

2626

27+
def example_manifests(manifest):
28+
return [dir_ / manifest for dir_ in Path("examples").iterdir()]
29+
30+
2731
def default(args):
28-
run("cargo", "fmt")
32+
format_(args)
2933

3034
if nightly():
31-
run("cargo", "clippy", "--workspace", "--all-features", "--tests", "--benches")
35+
run("cargo", "clippy", "--all-features", "--tests", "--benches")
3236
else:
33-
run("cargo", "clippy", "--workspace", "--all-features", "--tests")
37+
run("cargo", "clippy", "--all-features", "--tests")
38+
39+
for manifest in example_manifests("Cargo.toml"):
40+
run("cargo", "clippy", "--manifest-path", manifest)
3441

3542
run("cargo", "test", "--all-features", "--lib", "--tests")
3643

@@ -41,14 +48,18 @@ def check(args):
4148
run(
4249
"cargo",
4350
"clippy",
44-
"--workspace",
4551
"--all-features",
4652
"--tests",
4753
"--",
4854
"--deny",
4955
"warnings",
5056
)
5157

58+
for manifest in example_manifests("Cargo.toml"):
59+
run("cargo", "fmt", "--manifest-path", manifest, "--", "--check")
60+
61+
run("cargo", "clippy", "--manifest-path", manifest, "--", "--deny", "warnings")
62+
5263

5364
def doc(args):
5465
if args.name is None:
@@ -63,6 +74,8 @@ def doc(args):
6374

6475

6576
def test(args):
77+
run("cargo", "test", "--all-features", "--lib")
78+
6679
if args.name is None:
6780
run("cargo", "test", "--all-features", "--tests")
6881
else:
@@ -84,16 +97,10 @@ def examples(args):
8497
sys.exit("Examples require the Nox tool (https://nox.thea.codes)")
8598

8699
if args.name is None:
87-
dirs = [
88-
dir_.name
89-
for dir_ in Path("examples").iterdir()
90-
if (dir_ / "noxfile.py").exists()
91-
]
100+
for manifest in example_manifests("noxfile.py"):
101+
run("nox", "--noxfile", manifest)
92102
else:
93-
dirs = [args.name]
94-
95-
for dir in dirs:
96-
run("nox", "--noxfile", f"examples/{dir}/noxfile.py")
103+
run("nox", "--noxfile", f"examples/{args.name}/noxfile.py")
97104

98105

99106
def format_(args):
@@ -104,6 +111,9 @@ def format_(args):
104111

105112
run("cargo", "fmt")
106113

114+
for manifest in example_manifests("Cargo.toml"):
115+
run("cargo", "fmt", "--manifest-path", manifest)
116+
107117
run("black", ".")
108118

109119

0 commit comments

Comments
 (0)