Skip to content

Commit

Permalink
Rename get_path to find_path
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter554 committed Jan 3, 2025
1 parent 5e3935c commit 988d413
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ fn main() -> Result<()> {
);

assert_eq!(
imports_info.internal_imports().get_path(
imports_info.internal_imports().find_path(
&InternalImportsPathQuery::new()
.from(root_pkg)
.to(d)
Expand Down
21 changes: 11 additions & 10 deletions src/imports_info/queries/internal_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl InternalImportsPathQuery {
///
/// // Sanity check: The shortest path goes via `b`.
/// assert_eq!(
/// imports_info.internal_imports().get_path(
/// imports_info.internal_imports().find_path(
/// &InternalImportsPathQuery::new()
/// .from(a)
/// .to(c)
Expand All @@ -96,7 +96,7 @@ impl InternalImportsPathQuery {
///
/// // If we exclude `b`, we get the longer path via `e`.
/// assert_eq!(
/// imports_info.internal_imports().get_path(
/// imports_info.internal_imports().find_path(
/// &InternalImportsPathQuery::new()
/// .from(a)
/// .to(c)
Expand Down Expand Up @@ -476,7 +476,8 @@ impl<'a> InternalImportsQueries<'a> {
}
}

/// Returns the shortest import path between the passed package items.
/// Returns the shortest import path between the passed package items,
/// or `None` if no path can be found.
///
/// ```
/// # use std::collections::HashSet;
Expand Down Expand Up @@ -508,7 +509,7 @@ impl<'a> InternalImportsQueries<'a> {
/// .token();
///
/// assert_eq!(
/// imports_info.internal_imports().get_path(
/// imports_info.internal_imports().find_path(
/// &InternalImportsPathQuery::new()
/// .from(root_init)
/// .to(c)
Expand All @@ -518,7 +519,7 @@ impl<'a> InternalImportsQueries<'a> {
/// # Ok(())
/// # }
/// ```
pub fn get_path(
pub fn find_path(
&'a self,
query: &InternalImportsPathQuery,
) -> Result<Option<Vec<PackageItemToken>>> {
Expand Down Expand Up @@ -611,7 +612,7 @@ impl<'a> InternalImportsQueries<'a> {
/// # }
/// ```
pub fn path_exists(&'a self, query: &InternalImportsPathQuery) -> Result<bool> {
Ok(self.get_path(query)?.is_some())
Ok(self.find_path(query)?.is_some())
}
}

Expand Down Expand Up @@ -835,7 +836,7 @@ from testpackage import books",
}

#[test]
fn test_get_path() -> Result<()> {
fn test_find_path() -> Result<()> {
let testpackage = testpackage! {
"__init__.py" => "",
"a.py" => "from testpackage import b; from testpackage import c",
Expand All @@ -855,7 +856,7 @@ from testpackage import books",
assert_eq!(
imports_info
.internal_imports()
.get_path(&InternalImportsPathQuery::new().from(a).to(e))?,
.find_path(&InternalImportsPathQuery::new().from(a).to(e))?,
Some(vec![a, c, e])
);

Expand Down Expand Up @@ -885,12 +886,12 @@ from testpackage import books",
assert_eq!(
imports_info
.internal_imports()
.get_path(&InternalImportsPathQuery::new().from(a).to(c))?,
.find_path(&InternalImportsPathQuery::new().from(a).to(c))?,
Some(vec![a, b, c])
);

assert_eq!(
imports_info.internal_imports().get_path(
imports_info.internal_imports().find_path(
&InternalImportsPathQuery::new()
.from(a)
.to(c)
Expand Down

0 comments on commit 988d413

Please sign in to comment.