Skip to content

Commit

Permalink
Merge pull request #602 from gauge-sh/remove-global-exclusion-state
Browse files Browse the repository at this point in the history
Remove global path exclusion state
  • Loading branch information
emdoyle authored Feb 7, 2025
2 parents 8df4e07 + 30e32aa commit 2138c29
Show file tree
Hide file tree
Showing 29 changed files with 435 additions and 510 deletions.
13 changes: 2 additions & 11 deletions python/tach/check_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from tach.extension import (
Diagnostic,
check_external_dependencies,
set_excluded_paths,
)
from tach.utils.external import (
get_module_mappings,
Expand All @@ -31,23 +30,15 @@ def extract_module_mappings(rename: list[str]) -> dict[str, list[str]]:


def check_external(
project_root: Path,
project_config: ProjectConfig,
exclude_paths: list[str],
project_root: Path, project_config: ProjectConfig
) -> list[Diagnostic]:
set_excluded_paths(
project_root=str(project_root),
exclude_paths=exclude_paths,
use_regex_matching=project_config.use_regex_matching,
)

metadata_module_mappings = get_module_mappings()
if project_config.external.rename:
metadata_module_mappings.update(
extract_module_mappings(project_config.external.rename)
)
return check_external_dependencies(
project_root=str(project_root),
project_root=project_root,
project_config=project_config,
module_mappings=metadata_module_mappings,
stdlib_modules=get_stdlib_modules(),
Expand Down
28 changes: 6 additions & 22 deletions python/tach/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
format_diagnostics,
run_server,
serialize_diagnostics_json,
sync_project,
update_computation_cache,
)
from tach.filesystem import install_pre_commit
Expand All @@ -42,7 +43,6 @@
generate_module_graph_mermaid,
generate_show_url,
)
from tach.sync import sync_project
from tach.test import run_affected_tests

if TYPE_CHECKING:
Expand Down Expand Up @@ -452,10 +452,9 @@ def check_cache_for_action(
project_root: Path, project_config: ProjectConfig, action: str
) -> CachedOutput:
cache_key = create_computation_cache_key(
project_root=str(project_root),
project_root=project_root,
source_roots=[
str(project_root / source_root)
for source_root in project_config.source_roots
project_root / source_root for source_root in project_config.source_roots
],
action=action,
py_interpreter_version=f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}",
Expand All @@ -464,7 +463,7 @@ def check_cache_for_action(
backend=project_config.cache.backend,
)
cache_result = check_computation_cache(
project_root=str(project_root), cache_key=cache_key
project_root=project_root, cache_key=cache_key
)
if cache_result:
return CachedOutput(
Expand All @@ -478,7 +477,6 @@ def check_cache_for_action(
def tach_check(
project_config: ProjectConfig,
project_root: Path,
exclude_paths: list[str],
exact: bool = False,
dependencies: bool = True,
interfaces: bool = True,
Expand All @@ -501,7 +499,6 @@ def tach_check(
project_config=project_config,
dependencies=dependencies,
interfaces=interfaces,
exclude_paths=exclude_paths,
)
has_errors = any(diagnostic.is_error() for diagnostic in diagnostics)

Expand All @@ -524,7 +521,6 @@ def tach_check(
unused_dependencies = detect_unused_dependencies(
project_root=project_root,
project_config=project_config,
exclude_paths=exclude_paths,
)
if unused_dependencies:
print_unused_dependencies(unused_dependencies)
Expand All @@ -551,7 +547,6 @@ def tach_check(
def tach_check_external(
project_config: ProjectConfig,
project_root: Path,
exclude_paths: list[str],
):
logger.info(
"tach check-external called",
Expand All @@ -565,7 +560,6 @@ def tach_check_external(
diagnostics = check_external(
project_root=project_root,
project_config=project_config,
exclude_paths=exclude_paths,
)

if diagnostics:
Expand Down Expand Up @@ -633,7 +627,6 @@ def tach_mod(
def tach_sync(
project_config: ProjectConfig,
project_root: Path,
exclude_paths: list[str],
add: bool = False,
):
logger.info(
Expand All @@ -649,7 +642,6 @@ def tach_sync(
sync_project(
project_root=project_root,
project_config=project_config,
exclude_paths=exclude_paths,
add=add,
)
except Exception as e:
Expand Down Expand Up @@ -708,7 +700,6 @@ def tach_report(
usages: bool = False,
external: bool = False,
raw: bool = False,
exclude_paths: list[str] | None = None,
):
logger.info(
"tach report called",
Expand Down Expand Up @@ -742,7 +733,6 @@ def tach_report(
skip_dependencies=not generate_dependencies,
skip_usages=not generate_usages,
raw=raw,
exclude_paths=exclude_paths,
)
)

Expand All @@ -753,7 +743,6 @@ def tach_report(
Path(path),
raw=raw,
project_config=project_config,
exclude_paths=exclude_paths,
)
)

Expand Down Expand Up @@ -901,7 +890,7 @@ def tach_test(

if results.tests_ran_to_completion:
update_computation_cache(
str(project_root),
project_root,
cache_key=cached_output.key,
value=(
[
Expand Down Expand Up @@ -1071,7 +1060,7 @@ def main() -> None:

# Exclude paths on the CLI extend those from the project config
try:
exclude_paths = extend_and_validate(
project_config.exclude = extend_and_validate(
exclude_paths, project_config.exclude, project_config.use_regex_matching
)
except TachConfigError as e:
Expand All @@ -1083,7 +1072,6 @@ def main() -> None:
project_config=project_config,
project_root=project_root,
add=args.add,
exclude_paths=exclude_paths,
)
elif args.command == "check":
if args.dependencies or args.interfaces:
Expand All @@ -1093,22 +1081,19 @@ def main() -> None:
dependencies=args.dependencies,
interfaces=args.interfaces,
exact=args.exact,
exclude_paths=exclude_paths,
output_format=args.output,
)
else:
tach_check(
project_config=project_config,
project_root=project_root,
exact=args.exact,
exclude_paths=exclude_paths,
output_format=args.output,
)
elif args.command == "check-external":
tach_check_external(
project_config=project_config,
project_root=project_root,
exclude_paths=exclude_paths,
)
elif args.command == "report":
include_dependency_modules = (
Expand All @@ -1127,7 +1112,6 @@ def main() -> None:
usages=args.usages,
external=args.external,
raw=args.raw,
exclude_paths=exclude_paths,
)
elif args.command == "show":
tach_show(
Expand Down
35 changes: 15 additions & 20 deletions python/tach/extension.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,41 @@ class PythonImport:
line_number: int

def get_project_imports(
source_roots: list[str],
file_path: str,
ignore_type_checking_imports: bool,
include_string_imports: bool,
project_root: Path,
source_roots: list[Path],
file_path: Path,
project_config: ProjectConfig,
) -> list[PythonImport]: ...
def get_external_imports(
source_roots: list[str],
file_path: str,
ignore_type_checking_imports: bool,
project_root: Path,
source_roots: list[Path],
file_path: Path,
project_config: ProjectConfig,
) -> list[PythonImport]: ...
def set_excluded_paths(
project_root: str, exclude_paths: list[str], use_regex_matching: bool
) -> None: ...
def create_dependency_report(
project_root: str,
project_root: Path,
project_config: ProjectConfig,
path: str,
path: Path,
include_dependency_modules: list[str] | None,
include_usage_modules: list[str] | None,
skip_dependencies: bool,
skip_usages: bool,
raw: bool,
) -> str: ...
def create_computation_cache_key(
project_root: str,
source_roots: list[str],
project_root: Path,
source_roots: list[Path],
action: str,
py_interpreter_version: str,
file_dependencies: list[str],
env_dependencies: list[str],
backend: str,
) -> str: ...
def check_computation_cache(
project_root: str, cache_key: str
project_root: Path, cache_key: str
) -> tuple[list[tuple[int, str]], int] | None: ...
def update_computation_cache(
project_root: str, cache_key: str, value: tuple[list[tuple[int, str]], int]
project_root: Path, cache_key: str, value: tuple[list[tuple[int, str]], int]
) -> None: ...
def parse_project_config(filepath: Path) -> tuple[ProjectConfig, bool]: ...
def dump_project_config_to_toml(project_config: ProjectConfig) -> str: ...
Expand All @@ -51,10 +49,9 @@ def check(
project_config: ProjectConfig,
dependencies: bool,
interfaces: bool,
exclude_paths: list[str],
) -> list[Diagnostic]: ...
def check_external_dependencies(
project_root: str,
project_root: Path,
project_config: ProjectConfig,
module_mappings: dict[str, list[str]],
stdlib_modules: list[str],
Expand All @@ -66,12 +63,10 @@ def format_diagnostics(
def detect_unused_dependencies(
project_root: Path,
project_config: ProjectConfig,
exclude_paths: list[str],
) -> list[UnusedDependencies]: ...
def sync_project(
project_root: Path,
project_config: ProjectConfig,
exclude_paths: list[str],
add: bool = False,
) -> None: ...
def run_server(project_root: Path, project_config: ProjectConfig) -> None: ...
Expand Down
11 changes: 5 additions & 6 deletions python/tach/modularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,10 @@ def get_containing_module(mod_path: str) -> str | None:
)
pyfile_containing_module = get_containing_module(pyfile_mod_path)
imports = get_project_imports(
source_roots=list(map(str, source_roots)),
file_path=str(project_root / pyfile),
ignore_type_checking_imports=project_config.ignore_type_checking_imports,
include_string_imports=project_config.include_string_imports,
project_root=project_root,
source_roots=source_roots,
file_path=pyfile,
project_config=project_config,
)
for project_import in imports:
import_containing_module = get_containing_module(project_import.module_path)
Expand Down Expand Up @@ -296,13 +296,12 @@ def generate_modularity_report(

report.modules = build_modules(project_config)
report.usages = build_usages(project_root, source_roots, project_config)
exclude_paths = extend_and_validate(
project_config.exclude = extend_and_validate(
None, project_config.exclude, project_config.use_regex_matching
)
check_diagnostics = check(
project_root=project_root,
project_config=project_config,
exclude_paths=exclude_paths,
dependencies=True,
interfaces=True,
)
Expand Down
Loading

0 comments on commit 2138c29

Please sign in to comment.