Skip to content

Commit

Permalink
Merge pull request #126 from gauge-sh/fixes-0.6.1
Browse files Browse the repository at this point in the history
[Bugfixes] 0.6.1
  • Loading branch information
emdoyle authored Jun 21, 2024
2 parents 9ddfbe9 + e31ba51 commit c478c27
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tach"
version = "0.6.0"
version = "0.6.1"
edition = "2021"

[lib]
Expand Down
2 changes: 1 addition & 1 deletion docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ If you use the [pre-commit framework](https://github.com/pre-commit/pre-commit),
```yaml
repos:
- repo: https://github.com/gauge-sh/tach-pre-commit
rev: v0.6.0 # change this to the latest tag!
rev: v0.6.1 # change this to the latest tag!
hooks:
- id: tach
```
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "tach"
version = "0.6.0"
version = "0.6.1"
authors = [
{ name="Caelean Barnes", email="[email protected]" },
{ name="Evan Doyle", email="[email protected]" },
Expand Down
2 changes: 1 addition & 1 deletion python/tach/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from __future__ import annotations

__version__ = "0.6.0"
__version__ = "0.6.1"

__all__ = ["__version__"]
22 changes: 16 additions & 6 deletions python/tach/check.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import annotations

import re
from dataclasses import dataclass, field
from pathlib import Path
from typing import TYPE_CHECKING

from tach import errors
from tach import filesystem as fs
from tach.constants import ROOT_MODULE_SENTINEL_TAG
from tach.core import ModuleConfig
from tach.extension import get_project_imports, set_excluded_paths
from tach.parsing import build_module_tree
Expand Down Expand Up @@ -136,7 +138,7 @@ def validate_project_modules(
) -> ProjectModuleValidationResult:
result = ProjectModuleValidationResult()
for module in modules:
if fs.module_to_pyfile_or_dir_path(
if module.path == ROOT_MODULE_SENTINEL_TAG or fs.module_to_pyfile_or_dir_path(
source_root=source_root, module_path=module.path
):
result.valid_modules.append(module)
Expand All @@ -145,6 +147,13 @@ def validate_project_modules(
return result


def is_path_excluded(path: Path, exclude_paths: list[str]) -> bool:
dirpath_for_matching = f"{path}/"
return any(
re.match(exclude_path, dirpath_for_matching) for exclude_path in exclude_paths
)


def check(
project_root: Path,
project_config: ProjectConfig,
Expand Down Expand Up @@ -181,11 +190,12 @@ def check(
# This informs the Rust extension ahead-of-time which paths are excluded.
# The extension builds regexes and uses them during `get_project_imports`
set_excluded_paths(exclude_paths=exclude_paths or [])
for file_path in fs.walk_pyfiles(
project_root,
exclude_paths=exclude_paths,
):
abs_file_path = project_root / file_path
for file_path in fs.walk_pyfiles(source_root):
abs_file_path = source_root / file_path
rel_file_path = abs_file_path.relative_to(project_root)
if is_path_excluded(rel_file_path, exclude_paths=exclude_paths or []):
continue

mod_path = fs.file_to_module_path(
source_root=source_root, file_path=abs_file_path
)
Expand Down
5 changes: 0 additions & 5 deletions python/tach/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,11 +243,6 @@ def tach_check(

exact |= project_config.exact

if exclude_paths is not None and project_config.exclude is not None:
exclude_paths.extend(project_config.exclude)
else:
exclude_paths = project_config.exclude

check_result = check(
project_root=project_root,
project_config=project_config,
Expand Down
34 changes: 4 additions & 30 deletions python/tach/filesystem/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import ast
import os
import re
import stat
import threading
from collections import defaultdict
Expand Down Expand Up @@ -157,58 +156,33 @@ def parse_ast(path: str) -> ast.AST:


def walk(
root: Path,
depth: int | None = None,
exclude_paths: list[str] | None = None,
root: Path, depth: int | None = None
) -> Generator[tuple[Path, list[Path]], None, None]:
if depth is not None and depth <= 0:
return
root = root.resolve()
for dirpath, dirnames, filenames in os.walk(root):
rel_dirpath = Path(dirpath).relative_to(root)
dirpath_for_matching = f"{rel_dirpath}/"

if rel_dirpath.name.startswith("."):
# This prevents recursing into child directories of hidden paths
del dirnames[:]
continue

if exclude_paths is not None and any(
re.match(exclude_path, dirpath_for_matching)
for exclude_path in exclude_paths
):
# Treat excluded paths as invisible
continue

if depth:
# Ignore anything past requested depth
current_depth = len(rel_dirpath.parts) - 1
if current_depth > depth:
continue

def filter_filename(filename: str) -> bool:
if filename.startswith("."):
return False
file_path = rel_dirpath / filename
if exclude_paths is not None and any(
re.match(exclude_path, str(file_path)) for exclude_path in exclude_paths
):
return False
return True
return not filename.startswith(".")

yield rel_dirpath, list(map(Path, filter(filter_filename, filenames)))


def walk_pyfiles(
root: Path,
depth: int | None = None,
exclude_paths: list[str] | None = None,
) -> Generator[Path, None, None]:
for dirpath, filepaths in walk(
root,
depth=depth,
exclude_paths=exclude_paths,
):
def walk_pyfiles(root: Path, depth: int | None = None) -> Generator[Path, None, None]:
for dirpath, filepaths in walk(root, depth=depth):
for filepath in filepaths:
if filepath.name.endswith(".py"):
yield dirpath / filepath
Expand Down
1 change: 1 addition & 0 deletions tach.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ modules:
strict: true
- path: tach.check
depends_on:
- tach.constants
- tach.core
- tach.errors
- tach.filesystem
Expand Down

0 comments on commit c478c27

Please sign in to comment.