Skip to content

Commit 5513daa

Browse files
committed
WIP - get plumbing for nominate_cycle_breakers in rust
1 parent ea5da5f commit 5513daa

3 files changed

Lines changed: 44 additions & 0 deletions

File tree

rust/src/graph/cycle_breakers.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
use crate::errors::GrimpResult;
2+
use crate::graph::{Graph, ModuleToken};
3+
use rustc_hash::FxHashSet;
4+
5+
impl Graph {
6+
pub fn nominate_cycle_breakers(
7+
&self,
8+
_package: ModuleToken,
9+
) -> GrimpResult<FxHashSet<(ModuleToken, ModuleToken)>> {
10+
Ok(FxHashSet::default())
11+
}
12+
}

rust/src/graph/mod.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod hierarchy_queries;
2525
pub mod higher_order_queries;
2626
pub mod import_chain_queries;
2727

28+
pub mod cycle_breakers;
2829
pub(crate) mod pathfinding;
2930

3031
static MODULE_NAMES: LazyLock<RwLock<StringInterner<StringBackend>>> =
@@ -619,6 +620,33 @@ impl GraphWrapper {
619620
self.convert_package_dependencies_to_python(py, illegal_dependencies)
620621
}
621622

623+
pub fn nominate_cycle_breakers<'py>(
624+
&self,
625+
py: Python<'py>,
626+
package: &str,
627+
) -> PyResult<Bound<'py, PySet>> {
628+
let package = self.get_visible_module_by_name(package)?.token();
629+
let cycle_breakers = self._graph.nominate_cycle_breakers(package)?;
630+
PySet::new(
631+
py,
632+
cycle_breakers
633+
.into_iter()
634+
.map(|(importer, imported)| {
635+
let importer = self._graph.get_module(importer).unwrap();
636+
let imported = self._graph.get_module(imported).unwrap();
637+
Import::new(importer.name(), imported.name())
638+
})
639+
.map(|import| {
640+
[
641+
("importer", import.importer.into_py_any(py).unwrap()),
642+
("imported", import.imported.into_py_any(py).unwrap()),
643+
]
644+
.into_py_dict(py)
645+
.unwrap()
646+
}),
647+
)
648+
}
649+
622650
#[pyo3(name = "clone")]
623651
pub fn clone_py(&self) -> GraphWrapper {
624652
self.clone()

src/grimp/application/graph.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,10 @@ def nominate_cycle_breakers(self, package: str) -> set[ImportTuple]:
450450
"""
451451
Identify a set of imports that, if removed, would make the package locally acyclic.
452452
"""
453+
# Check plumbing - not implemented yet.
454+
rust_result = self._rustgraph.nominate_cycle_breakers(package)
455+
assert rust_result == set()
456+
453457
children = self.find_children(package)
454458
if len(children) < 2:
455459
return set()

0 commit comments

Comments
 (0)