Skip to content

Commit

Permalink
InternalImportsPathQueryBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter554 committed Jan 6, 2025
1 parent c006c6c commit 305a82b
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 69 deletions.
85 changes: 85 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ tap = "1.0.1"
derive_more = { version = "1.0.0", features = ["full"] }
derive-getters = "0.5.0"
derive-new = "0.7.0"
derive_builder = "0.20.2"

[dev-dependencies]
parameterized = "2.0.0"
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use anyhow::Result;
use maplit::{hashmap,hashset};

use pyimports::prelude::*;
use pyimports::{PackageInfo,ImportsInfo,PackageItemToken,InternalImportsPathQuery};
use pyimports::{PackageInfo,ImportsInfo,PackageItemToken,InternalImportsPathQueryBuilder};

// You shouldn't use `testpackage!`, it just creates a fake python package
// in a temporary directory. It's (unfortunately) included in the public API
Expand Down Expand Up @@ -63,9 +63,10 @@ fn main() -> Result<()> {

assert_eq!(
imports_info.internal_imports().find_path(
&InternalImportsPathQuery::new()
&InternalImportsPathQueryBuilder::default()
.from(root_pkg)
.to(d)
.build()?
)?,
Some(vec![root_pkg, root_init, b, d])
);
Expand Down
9 changes: 6 additions & 3 deletions src/contracts/layers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,9 @@
//! ```
use crate::contracts::{ContractViolation, ForbiddenImport, ImportsContract};
use crate::{ExtendWithDescendants, ImportsInfo, InternalImportsPathQuery, PackageItemToken};
use crate::{
ExtendWithDescendants, ImportsInfo, InternalImportsPathQueryBuilder, PackageItemToken,
};
use anyhow::Result;
use itertools::Itertools;
use maplit::hashset;
Expand Down Expand Up @@ -191,10 +193,11 @@ impl ImportsContract for LayeredArchitectureContract {
.with_descendants(imports_info.package_info());

let path = imports_info.internal_imports().find_path(
&InternalImportsPathQuery::new()
&InternalImportsPathQueryBuilder::default()
.from(from)
.to(to)
.excluding_paths_via(except_via),
.excluding_paths_via(except_via)
.build()?,
)?;
if let Some(path) = path {
violations.push(ContractViolation::ForbiddenImport {
Expand Down
2 changes: 1 addition & 1 deletion src/imports_info/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod queries;

pub use crate::imports_info::queries::external_imports::ExternalImportsQueries;
pub use crate::imports_info::queries::internal_imports::{
InternalImportsPathQuery, InternalImportsQueries,
InternalImportsPathQuery, InternalImportsPathQueryBuilder, InternalImportsQueries,
};
use crate::{
package_info::{PackageInfo, PackageItemToken},
Expand Down
Loading

0 comments on commit 305a82b

Please sign in to comment.