Skip to content

Commit 51f2bb7

Browse files
authored
Centralize cargo workspace dependencies (#33)
* docs: add cargo workspace dependency design Signed-off-by: lucarlig <luca.carlig@ibm.com> * build: centralize cargo workspace dependencies Signed-off-by: lucarlig <luca.carlig@ibm.com> * build: centralize remaining cargo dependencies Signed-off-by: lucarlig <luca.carlig@ibm.com> * docs: remove superpowers planning notes Signed-off-by: lucarlig <luca.carlig@ibm.com> --------- Signed-off-by: lucarlig <luca.carlig@ibm.com>
1 parent 54279f2 commit 51f2bb7

8 files changed

Lines changed: 270 additions & 18 deletions

File tree

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,15 @@ license = "Apache-2.0"
1616
repository = "https://github.com/IBM/cpex-plugins"
1717

1818
[workspace.dependencies]
19+
cpex_framework_bridge = { path = "crates/framework_bridge" }
20+
criterion = { version = "0.8", features = ["html_reports"] }
1921
log = "0.4"
2022
pyo3-async-runtimes = { version = "0.28", features = ["tokio-runtime"] }
2123
pyo3 = { version = "0.28.2", features = ["abi3-py311"] }
2224
pyo3-log = "0.13"
2325
pyo3-stub-gen = "0.20.0"
26+
regex = "1.12"
27+
serde_json = "1.0"
2428
thiserror = "2.0"
2529
tokio = { version = "1", features = ["full"] }
2630
rand = "0.8"

plugins/rust/python-package/encoded_exfil_detection/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ path = "src/bin/stub_gen.rs"
1717

1818
[dependencies]
1919
base64 = "0.22"
20-
cpex_framework_bridge = { path = "../../../../crates/framework_bridge" }
20+
cpex_framework_bridge = { workspace = true }
2121
log = { workspace = true }
2222
pyo3 = { workspace = true }
2323
pyo3-log = { workspace = true }
2424
pyo3-stub-gen = { workspace = true }
25-
regex = "1.12"
26-
serde_json = "1"
25+
regex = { workspace = true }
26+
serde_json = { workspace = true }
2727

2828
[dev-dependencies]
29-
criterion = { version = "0.8", features = ["html_reports"] }
29+
criterion = { workspace = true }
3030

3131
[[bench]]
3232
name = "encoded_exfil_detection"

plugins/rust/python-package/pii_filter/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ name = "stub_gen"
1616
path = "src/bin/stub_gen.rs"
1717

1818
[dependencies]
19-
cpex_framework_bridge = { path = "../../../../crates/framework_bridge" }
19+
cpex_framework_bridge = { workspace = true }
2020
log = { workspace = true }
2121
pyo3 = { workspace = true }
2222
pyo3-log = { workspace = true }
2323
pyo3-stub-gen = { workspace = true }
24-
regex = "1.12"
24+
regex = { workspace = true }
2525
once_cell = "1.21"
2626
serde = { version = "1.0", features = ["derive"] }
27-
serde_json = "1.0"
27+
serde_json = { workspace = true }
2828
thiserror = { workspace = true }
2929
sha2 = "0.10"
3030
uuid = { version = "1.18", features = ["v4"] }
3131

3232
[dev-dependencies]
33-
criterion = { version = "0.8", features = ["html_reports"] }
33+
criterion = { workspace = true }
3434

3535
[[bench]]
3636
name = "pii_filter"

plugins/rust/python-package/rate_limiter/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ name = "stub_gen"
1616
path = "src/bin/stub_gen.rs"
1717

1818
[dependencies]
19-
cpex_framework_bridge = { path = "../../../../crates/framework_bridge" }
19+
cpex_framework_bridge = { workspace = true }
2020
log = { workspace = true }
2121
pyo3 = { workspace = true }
2222
pyo3-async-runtimes = { workspace = true }
@@ -28,7 +28,7 @@ redis = { version = "0.27", features = ["aio", "tokio-comp"] }
2828
tokio = { workspace = true }
2929

3030
[dev-dependencies]
31-
criterion = { version = "0.8", features = ["html_reports"] }
31+
criterion = { workspace = true }
3232

3333
[[bench]]
3434
name = "rate_limiter"

plugins/rust/python-package/secrets_detection/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,16 @@ name = "stub_gen"
1616
path = "src/bin/stub_gen.rs"
1717

1818
[dependencies]
19-
cpex_framework_bridge = { path = "../../../../crates/framework_bridge" }
19+
cpex_framework_bridge = { workspace = true }
2020
log = { workspace = true }
2121
pyo3 = { workspace = true }
2222
pyo3-log = { workspace = true }
2323
pyo3-stub-gen = { workspace = true }
24-
regex = "1.12"
25-
serde_json = "1.0"
24+
regex = { workspace = true }
25+
serde_json = { workspace = true }
2626

2727
[dev-dependencies]
28-
criterion = { version = "0.8", features = ["html_reports"] }
28+
criterion = { workspace = true }
2929

3030
[[bench]]
3131
name = "secrets_detection"

plugins/rust/python-package/url_reputation/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ path = "src/bin/stub_gen.rs"
1717

1818
[dependencies]
1919
idna = "1.1.0"
20-
log = "0.4"
20+
log = { workspace = true }
2121
phf = { version = "0.13.1", features = ["macros"] }
22-
pyo3 = { workspace = true, features = ["abi3-py311"] }
22+
pyo3 = { workspace = true }
2323
pyo3-log = { workspace = true }
24-
regex = "1.12.3"
24+
regex = { workspace = true }
2525
unicode-script = "0.5.8"
2626
unicode-security = "0.1.2"
2727
url = "2.5.8"
2828

2929
[dev-dependencies]
30-
criterion = "0.8.2"
30+
criterion = { workspace = true }
3131

3232
[[bench]]
3333
name = "url_validation"

tests/test_plugin_catalog.py

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import subprocess
55
import tempfile
66
import textwrap
7+
import tomllib
78
import unittest
89
from pathlib import Path
910
import re
@@ -172,6 +173,141 @@ def test_repo_validates_managed_plugins_layout(self) -> None:
172173
result = run_catalog("validate", str(REPO_ROOT))
173174
self.assertEqual(result.returncode, 0, result.stderr)
174175

176+
def test_repo_centralizes_shared_cargo_dependencies(self) -> None:
177+
cargo = tomllib.loads((REPO_ROOT / "Cargo.toml").read_text())
178+
workspace_deps = cargo["workspace"]["dependencies"]
179+
180+
self.assertEqual(
181+
workspace_deps["cpex_framework_bridge"],
182+
{"path": "crates/framework_bridge"},
183+
)
184+
self.assertEqual(
185+
workspace_deps["criterion"],
186+
{"version": "0.8", "features": ["html_reports"]},
187+
)
188+
self.assertEqual(workspace_deps["log"], "0.4")
189+
self.assertEqual(
190+
workspace_deps["pyo3-async-runtimes"],
191+
{"version": "0.28", "features": ["tokio-runtime"]},
192+
)
193+
self.assertEqual(
194+
workspace_deps["pyo3"],
195+
{"version": "0.28.2", "features": ["abi3-py311"]},
196+
)
197+
self.assertEqual(workspace_deps["pyo3-log"], "0.13")
198+
self.assertEqual(workspace_deps["pyo3-stub-gen"], "0.20.0")
199+
self.assertEqual(workspace_deps["rand"], "0.8")
200+
self.assertEqual(workspace_deps["regex"], "1.12")
201+
self.assertEqual(workspace_deps["serde_json"], "1.0")
202+
self.assertEqual(workspace_deps["thiserror"], "2.0")
203+
self.assertEqual(
204+
workspace_deps["tokio"],
205+
{"version": "1", "features": ["full"]},
206+
)
207+
208+
expected_plugin_deps = {
209+
"encoded_exfil_detection": {
210+
"dependencies": {
211+
"cpex_framework_bridge": {"workspace": True},
212+
"log": {"workspace": True},
213+
"pyo3": {"workspace": True},
214+
"pyo3-log": {"workspace": True},
215+
"pyo3-stub-gen": {"workspace": True},
216+
"regex": {"workspace": True},
217+
"serde_json": {"workspace": True},
218+
},
219+
"dev-dependencies": {
220+
"criterion": {"workspace": True},
221+
},
222+
},
223+
"pii_filter": {
224+
"dependencies": {
225+
"cpex_framework_bridge": {"workspace": True},
226+
"log": {"workspace": True},
227+
"pyo3": {"workspace": True},
228+
"pyo3-log": {"workspace": True},
229+
"pyo3-stub-gen": {"workspace": True},
230+
"regex": {"workspace": True},
231+
"serde_json": {"workspace": True},
232+
"thiserror": {"workspace": True},
233+
},
234+
"dev-dependencies": {
235+
"criterion": {"workspace": True},
236+
},
237+
},
238+
"rate_limiter": {
239+
"dependencies": {
240+
"cpex_framework_bridge": {"workspace": True},
241+
"log": {"workspace": True},
242+
"pyo3": {"workspace": True},
243+
"pyo3-async-runtimes": {"workspace": True},
244+
"pyo3-log": {"workspace": True},
245+
"pyo3-stub-gen": {"workspace": True},
246+
"thiserror": {"workspace": True},
247+
"tokio": {"workspace": True},
248+
},
249+
"dev-dependencies": {
250+
"criterion": {"workspace": True},
251+
},
252+
},
253+
"retry_with_backoff": {
254+
"dependencies": {
255+
"log": {"workspace": True},
256+
"pyo3": {"workspace": True},
257+
"pyo3-log": {"workspace": True},
258+
"pyo3-stub-gen": {"workspace": True},
259+
"rand": {"workspace": True},
260+
},
261+
"dev-dependencies": {},
262+
},
263+
"secrets_detection": {
264+
"dependencies": {
265+
"cpex_framework_bridge": {"workspace": True},
266+
"log": {"workspace": True},
267+
"pyo3": {"workspace": True},
268+
"pyo3-log": {"workspace": True},
269+
"pyo3-stub-gen": {"workspace": True},
270+
"regex": {"workspace": True},
271+
"serde_json": {"workspace": True},
272+
},
273+
"dev-dependencies": {
274+
"criterion": {"workspace": True},
275+
},
276+
},
277+
"url_reputation": {
278+
"dependencies": {
279+
"log": {"workspace": True},
280+
"pyo3": {"workspace": True},
281+
"pyo3-log": {"workspace": True},
282+
"regex": {"workspace": True},
283+
},
284+
"dev-dependencies": {
285+
"criterion": {"workspace": True},
286+
},
287+
},
288+
}
289+
290+
for slug, expected_sections in expected_plugin_deps.items():
291+
plugin_cargo = tomllib.loads(
292+
(
293+
REPO_ROOT
294+
/ "plugins"
295+
/ "rust"
296+
/ "python-package"
297+
/ slug
298+
/ "Cargo.toml"
299+
).read_text()
300+
)
301+
for section_name, expected_deps in expected_sections.items():
302+
actual_section = plugin_cargo.get(section_name, {})
303+
self.assertIsInstance(actual_section, dict)
304+
for dependency_name, expected_value in expected_deps.items():
305+
self.assertEqual(
306+
actual_section.get(dependency_name),
307+
expected_value,
308+
f"{slug} should source {dependency_name} from workspace {section_name}",
309+
)
310+
175311
def test_repo_lists_all_managed_plugins(self) -> None:
176312
result = run_catalog("list", str(REPO_ROOT))
177313
self.assertEqual(result.returncode, 0, result.stderr)

0 commit comments

Comments
 (0)