Skip to content

Commit 5586d74

Browse files
authored
Merge pull request #322 from PyO3/examples-no-workspace
Break examples out of main workspace
2 parents 4454e04 + 3ef3f33 commit 5586d74

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-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: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import os
5+
import shutil
56
import subprocess
67
import sys
78
from pathlib import Path
@@ -24,13 +25,21 @@ def nightly():
2425
return b"-nightly " in proc.stdout
2526

2627

28+
def gen_examples(manifest):
29+
for dir_ in Path("examples").iterdir():
30+
yield dir_ / manifest
31+
32+
2733
def default(args):
28-
run("cargo", "fmt")
34+
format_(args)
2935

3036
if nightly():
31-
run("cargo", "clippy", "--workspace", "--all-features", "--tests", "--benches")
37+
run("cargo", "clippy", "--all-features", "--tests", "--benches")
3238
else:
33-
run("cargo", "clippy", "--workspace", "--all-features", "--tests")
39+
run("cargo", "clippy", "--all-features", "--tests")
40+
41+
for manifest in gen_examples("Cargo.toml"):
42+
run("cargo", "clippy", "--manifest-path", manifest)
3443

3544
run("cargo", "test", "--all-features", "--lib", "--tests")
3645

@@ -41,14 +50,18 @@ def check(args):
4150
run(
4251
"cargo",
4352
"clippy",
44-
"--workspace",
4553
"--all-features",
4654
"--tests",
4755
"--",
4856
"--deny",
4957
"warnings",
5058
)
5159

60+
for manifest in gen_examples("Cargo.toml"):
61+
run("cargo", "fmt", "--manifest-path", manifest, "--", "--check")
62+
63+
run("cargo", "clippy", "--manifest-path", manifest, "--", "--deny", "warnings")
64+
5265

5366
def doc(args):
5467
if args.name is None:
@@ -63,6 +76,8 @@ def doc(args):
6376

6477

6578
def test(args):
79+
run("cargo", "test", "--all-features", "--lib")
80+
6681
if args.name is None:
6782
run("cargo", "test", "--all-features", "--tests")
6883
else:
@@ -84,16 +99,10 @@ def examples(args):
8499
sys.exit("Examples require the Nox tool (https://nox.thea.codes)")
85100

86101
if args.name is None:
87-
dirs = [
88-
dir_.name
89-
for dir_ in Path("examples").iterdir()
90-
if (dir_ / "noxfile.py").exists()
91-
]
102+
for manifest in gen_examples("noxfile.py"):
103+
run("nox", "--noxfile", manifest)
92104
else:
93-
dirs = [args.name]
94-
95-
for dir in dirs:
96-
run("nox", "--noxfile", f"examples/{dir}/noxfile.py")
105+
run("nox", "--noxfile", f"examples/{args.name}/noxfile.py")
97106

98107

99108
def format_(args):
@@ -104,9 +113,22 @@ def format_(args):
104113

105114
run("cargo", "fmt")
106115

116+
for manifest in gen_examples("Cargo.toml"):
117+
run("cargo", "fmt", "--manifest-path", manifest)
118+
107119
run("black", ".")
108120

109121

122+
def prune(args):
123+
shutil.rmtree("target", ignore_errors=True)
124+
125+
for target_dir in gen_examples("target"):
126+
shutil.rmtree(target_dir, ignore_errors=True)
127+
128+
for nox_dir in gen_examples(".nox"):
129+
shutil.rmtree(nox_dir, ignore_errors=True)
130+
131+
110132
if __name__ == "__main__":
111133
parser = argparse.ArgumentParser()
112134
subparsers = parser.add_subparsers(
@@ -149,6 +171,11 @@ def format_(args):
149171
)
150172
format_parser.set_defaults(func=format_)
151173

174+
prune_parser = subparsers.add_parser(
175+
"prune", aliases=["p"], help="Remove target and venv directories"
176+
)
177+
prune_parser.set_defaults(func=prune)
178+
152179
args = parser.parse_args()
153180
os.chdir(Path(__file__).parent)
154181
args.func(args)

0 commit comments

Comments
 (0)