Skip to content

Commit

Permalink
Remove dead code related to interface members in ModuleTree
Browse files Browse the repository at this point in the history
  • Loading branch information
emdoyle committed Dec 5, 2024
1 parent d81c433 commit 4d1d2ed
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 163 deletions.
1 change: 0 additions & 1 deletion python/tach/extension.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def update_computation_cache(
project_root: str, cache_key: str, value: tuple[list[tuple[int, str]], int]
) -> None: ...
def parse_project_config(filepath: Path) -> tuple[ProjectConfig, bool]: ...
def parse_interface_members(source_roots: list[Path], path: str) -> list[str]: ...
def dump_project_config_to_toml(project_config: ProjectConfig) -> str: ...
def check(
project_root: Path,
Expand Down
22 changes: 0 additions & 22 deletions src/commands/check_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,28 +123,6 @@ impl ImportCheckError {
}
}

fn is_top_level_module_import(mod_path: &str, module: &ModuleNode) -> bool {
mod_path == module.full_path
}

fn import_matches_interface_members(mod_path: &str, module: &ModuleNode) -> bool {
let mod_path_segments: Vec<&str> = mod_path.rsplitn(2, '.').collect();

if mod_path_segments.len() == 1 {
// If there's no '.' in the path, compare the whole path with the module's full path.
mod_path_segments[0] == module.full_path
} else {
// If there's a '.', split into package path and member name.
let mod_pkg_path = mod_path_segments[1];
let mod_member_name = mod_path_segments[0];

mod_pkg_path == module.full_path
&& module
.interface_members
.contains(&mod_member_name.to_string())
}
}

fn check_import(
import_mod_path: &str,
module_tree: &ModuleTree,
Expand Down
10 changes: 0 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,6 @@ fn update_computation_cache(
cache::update_computation_cache(project_root, cache_key, value)
}

#[pyfunction]
#[pyo3(signature = (source_roots, path))]
fn parse_interface_members(
source_roots: Vec<PathBuf>,
path: String,
) -> python::parsing::Result<Vec<String>> {
python::parsing::parse_interface_members(&source_roots, &path)
}

#[pyfunction]
#[pyo3(signature = (project_root, project_config, dependencies, interfaces, exclude_paths))]
fn check(
Expand Down Expand Up @@ -385,7 +376,6 @@ fn extension(py: Python, m: &Bound<'_, PyModule>) -> PyResult<()> {
m.add_function(wrap_pyfunction_bound!(create_computation_cache_key, m)?)?;
m.add_function(wrap_pyfunction_bound!(check_computation_cache, m)?)?;
m.add_function(wrap_pyfunction_bound!(update_computation_cache, m)?)?;
m.add_function(wrap_pyfunction_bound!(parse_interface_members, m)?)?;
m.add_function(wrap_pyfunction_bound!(dump_project_config_to_toml, m)?)?;
m.add_function(wrap_pyfunction_bound!(check, m)?)?;
m.add_function(wrap_pyfunction_bound!(sync_dependency_constraints, m)?)?;
Expand Down
4 changes: 1 addition & 3 deletions src/modules/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use std::path::PathBuf;
use crate::core::config::{
global_visibility, ModuleConfig, RootModuleTreatment, ROOT_MODULE_SENTINEL_TAG,
};
use crate::python::parsing::parse_interface_members;
use petgraph::algo::kosaraju_scc;
use petgraph::graphmap::DiGraphMap;

Expand Down Expand Up @@ -203,9 +202,8 @@ pub fn build_module_tree(
// Construct the ModuleTree
let mut tree = ModuleTree::new();
for module in modules {
let interface_members = parse_interface_members(source_roots, &module.path)?;
let mod_path = module.mod_path();
tree.insert(module, mod_path, interface_members)?;
tree.insert(module, mod_path)?;
}

Ok(tree)
Expand Down
26 changes: 6 additions & 20 deletions src/modules/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ pub struct ModuleNode {
pub is_end_of_path: bool,
pub full_path: String,
pub config: Option<ModuleConfig>,
pub interface_members: Vec<String>,
pub children: HashMap<String, Arc<ModuleNode>>,
}

Expand All @@ -29,7 +28,6 @@ impl ModuleNode {
is_end_of_path: false,
full_path: String::new(),
config: None,
interface_members: vec![],
children: HashMap::new(),
}
}
Expand All @@ -40,7 +38,6 @@ impl ModuleNode {
is_end_of_path: true,
full_path: ".".to_string(),
config: Some(config),
interface_members: vec![],
children: HashMap::new(),
}
}
Expand All @@ -53,16 +50,10 @@ impl ModuleNode {
self.config.as_ref().map_or(false, |c| c.unchecked)
}

pub fn fill(
&mut self,
config: ModuleConfig,
full_path: String,
interface_members: Vec<String>,
) {
pub fn fill(&mut self, config: ModuleConfig, full_path: String) {
self.is_end_of_path = true;
self.config = Some(config);
self.full_path = full_path;
self.interface_members = interface_members;
}
}

Expand Down Expand Up @@ -115,12 +106,7 @@ impl ModuleTree {
}
}

pub fn insert(
&mut self,
config: ModuleConfig,
path: String,
interface_members: Vec<String>,
) -> Result<(), ModuleTreeError> {
pub fn insert(&mut self, config: ModuleConfig, path: String) -> Result<(), ModuleTreeError> {
if path.is_empty() {
return Err(ModuleTreeError::InsertNodeError);
}
Expand All @@ -135,7 +121,7 @@ impl ModuleTree {
.unwrap();
}

node.fill(config, path, interface_members);
node.fill(config, path);
Ok(())
}

Expand Down Expand Up @@ -253,7 +239,7 @@ mod tests {
#[rstest]
fn test_insert_empty_path(test_config: ModuleConfig) {
let mut tree = ModuleTree::new();
let result = tree.insert(test_config, "".to_string(), vec![]);
let result = tree.insert(test_config, "".to_string());
assert!(matches!(
result.unwrap_err(),
ModuleTreeError::InsertNodeError
Expand All @@ -263,7 +249,7 @@ mod tests {
#[rstest]
fn test_insert_single_level_path(test_config: ModuleConfig) {
let mut tree = ModuleTree::new();
let result = tree.insert(test_config, "domain".to_string(), vec![]);
let result = tree.insert(test_config, "domain".to_string());
assert!(result.is_ok());
let paths: Vec<String> = tree.iter().map(|node| node.full_path.clone()).collect();
assert_eq!(paths, [".", "domain"]);
Expand All @@ -272,7 +258,7 @@ mod tests {
#[rstest]
fn test_insert_multi_level_path(test_config: ModuleConfig) {
let mut tree = ModuleTree::new();
let result = tree.insert(test_config, "domain.subdomain".to_string(), vec![]);
let result = tree.insert(test_config, "domain.subdomain".to_string());
assert!(result.is_ok());
let paths: Vec<String> = tree.iter().map(|node| node.full_path.clone()).collect();
assert_eq!(paths, [".", "domain.subdomain"]);
Expand Down
6 changes: 0 additions & 6 deletions src/tests/check_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ pub mod fixtures {
is_end_of_path: false,
full_path: String::new(),
config: None,
interface_members: vec![],
children: HashMap::from([
(
"domain_one".to_string(),
Expand All @@ -37,14 +36,12 @@ pub mod fixtures {
strict: false,
..Default::default()
}),
interface_members: vec![],
children: HashMap::from([(
"subdomain".to_string(),
Arc::new(ModuleNode {
is_end_of_path: true,
full_path: "domain_one.subdomain".to_string(),
config: Some(ModuleConfig::new("domain_one.subdomain", false)),
interface_members: vec![],
children: HashMap::new(),
}),
)]),
Expand All @@ -61,7 +58,6 @@ pub mod fixtures {
strict: false,
..Default::default()
}),
interface_members: vec![],
children: HashMap::from([(
"subdomain".to_string(),
Arc::new(ModuleNode {
Expand All @@ -73,7 +69,6 @@ pub mod fixtures {
strict: false,
..Default::default()
}),
interface_members: vec![],
children: HashMap::new(),
}),
)]),
Expand All @@ -85,7 +80,6 @@ pub mod fixtures {
is_end_of_path: true,
full_path: "domain_three".to_string(),
config: Some(ModuleConfig::new("domain_three", false)),
interface_members: vec![],
children: HashMap::new(),
}),
),
Expand Down
6 changes: 0 additions & 6 deletions src/tests/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,19 @@ pub mod fixtures {
is_end_of_path: true,
full_path: ".".to_string(),
config: Some(ModuleConfig::new_root_config()),
interface_members: vec![],
children: HashMap::from([
(
"domain_one".to_string(),
Arc::new(ModuleNode {
is_end_of_path: true,
full_path: "domain_one".to_string(),
config: Some(ModuleConfig::new("test", false)),
interface_members: vec!["public_fn".to_string()],
children: HashMap::from([(
"subdomain".to_string(),
Arc::new(ModuleNode {
is_end_of_path: true,
full_path: "domain_one.subdomain".to_string(),
config: Some(ModuleConfig::new("test", false)),
interface_members: vec![],
children: HashMap::new(),
}),
)]),
Expand All @@ -39,14 +36,12 @@ pub mod fixtures {
is_end_of_path: true,
full_path: "domain_two".to_string(),
config: Some(ModuleConfig::new("test", false)),
interface_members: vec![],
children: HashMap::from([(
"subdomain".to_string(),
Arc::new(ModuleNode {
is_end_of_path: true,
full_path: "domain_two.subdomain".to_string(),
config: Some(ModuleConfig::new("test", false)),
interface_members: vec![],
children: HashMap::new(),
}),
)]),
Expand All @@ -58,7 +53,6 @@ pub mod fixtures {
is_end_of_path: true,
full_path: "domain_three".to_string(),
config: Some(ModuleConfig::new("test", false)),
interface_members: vec![],
children: HashMap::new(),
}),
),
Expand Down
Loading

0 comments on commit 4d1d2ed

Please sign in to comment.