Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions codelimit/commands/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
from pygments.util import ClassNotFound

from codelimit.common.CheckResult import CheckResult
from codelimit.common.Configuration import Configuration
from codelimit.common.Scanner import is_excluded, scan_file
from codelimit.common.Scanner import is_excluded, scan_file, generate_exclude_spec
from codelimit.common.lexer_utils import lex
from codelimit.languages import Languages


def check_command(paths: list[Path], quiet: bool):
check_result = CheckResult()
excludes_spec = PathSpec.from_lines("gitignore", Configuration.exclude)
excludes_spec = generate_exclude_spec(Path.cwd())
for path in paths:
if path.is_file():
_handle_file_path(path, check_result, excludes_spec)
Expand All @@ -25,7 +24,7 @@ def check_command(paths: list[Path], quiet: bool):
dirs[:] = [d for d in dirs if not d[0] == "."]
for file in files:
abs_path = Path(os.path.join(root, file))
rel_path = abs_path.relative_to(path.absolute())
rel_path = abs_path.relative_to(Path.cwd())
if is_excluded(rel_path, excludes_spec):
continue
check_file(abs_path, check_result)
Expand Down
4 changes: 2 additions & 2 deletions codelimit/common/Scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def scan_path(path: Path, cached_report: Union[Report, None] = None,
add_file_entry_callback: Union[Callable[[SourceFileEntry], None], None] = None,
) -> Codebase:
result = Codebase(str(path.resolve().absolute()))
excludes_spec = _generate_exclude_spec(path)
excludes_spec = generate_exclude_spec(path)
for root, dirs, files in os.walk(path.absolute()):
files = [f for f in files if not f[0] == "."]
dirs[:] = [d for d in dirs if not d[0] == "."]
Expand Down Expand Up @@ -180,7 +180,7 @@ def scan_file(tokens: list[Token], language: Language) -> list[Measurement]:
return measurements


def _generate_exclude_spec(root: Path) -> PathSpec:
def generate_exclude_spec(root: Path) -> PathSpec:
excludes = DEFAULT_EXCLUDES.copy()
excludes.extend(Configuration.exclude)
gitignore_excludes = _read_gitignore(root)
Expand Down
1 change: 1 addition & 0 deletions tests/common/test_Scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ def test_is_excluded():
excludes_spec = PathSpec.from_lines("gitignore", DEFAULT_EXCLUDES)

assert is_excluded(Path("venv/foo/bar.py"), excludes_spec)
assert is_excluded(Path("tests/test_utils.py"), excludes_spec)
assert not is_excluded(Path("foo/bar.py"), excludes_spec)

excludes_spec = PathSpec.from_lines("gitignore", ["output"])
Expand Down
Loading