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
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/question.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name: Question or consultation
about: Ask anything about this project
title: ''
labels: guestion
labels: question
assignees: pomponchik

---
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:

- name: Run mypy
shell: bash
run: mypy dirstree
run: mypy --strict dirstree

- name: Run mypy for tests
shell: bash
Expand Down
4 changes: 0 additions & 4 deletions .ruff.toml

This file was deleted.

8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
![logo](https://raw.githubusercontent.com/pomponchik/dirstree/develop/docs/assets/logo_1.svg)
<details>
<summary>ⓘ</summary>

[![Downloads](https://static.pepy.tech/badge/dirstree/month)](https://pepy.tech/project/dirstree)
[![Downloads](https://static.pepy.tech/badge/dirstree)](https://pepy.tech/project/dirstree)
Expand All @@ -12,6 +13,11 @@
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/pomponchik/dirstree)

</details>

![logo](https://raw.githubusercontent.com/pomponchik/dirstree/develop/docs/assets/logo_1.svg)


There are many libraries for traversing directories. You can also do this using the standard library. This particular library is a bit different in that:

- ⚗️ Filtering by file extensions, text patterns in [`.gitignore` format](https://git-scm.com/book/en/v2/Git-Basics-Recording-Changes-to-the-Repository#_ignoring), and using custom callables.
Expand Down
6 changes: 4 additions & 2 deletions dirstree/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
from dirstree.crawlers.crawler import Crawler as Crawler # noqa: F401
from dirstree.crawlers.python_crawler import PythonCrawler as PythonCrawler # noqa: F401
from dirstree.crawlers.crawler import Crawler as Crawler
from dirstree.crawlers.python_crawler import (
PythonCrawler as PythonCrawler,
)
6 changes: 3 additions & 3 deletions dirstree/crawlers/abstract.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABC, abstractmethod
from typing import Generator
from pathlib import Path
from typing import Generator

from cantok import AbstractToken, DefaultToken

Expand All @@ -13,10 +13,10 @@ def __add__(self, other: 'AbstractCrawler') -> 'AbstractCrawler':
if not isinstance(other, AbstractCrawler):
raise TypeError(f"Cannot add {type(self).__name__} and {type(other).__name__}.")

from dirstree.crawlers.group import CrawlersGroup
from dirstree.crawlers.group import CrawlersGroup # noqa: PLC0415

return CrawlersGroup([self, other])

@abstractmethod
def go(self, token: AbstractToken = DefaultToken()) -> Generator[Path, None, None]:
def go(self, token: AbstractToken = DefaultToken()) -> Generator[Path, None, None]: # noqa: B008
... # pragma: no cover
15 changes: 9 additions & 6 deletions dirstree/crawlers/crawler.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from typing import List, Dict, Optional, Union, Collection, Generator, Callable, Any
from pathlib import Path
from typing import Any, Callable, Collection, Dict, Generator, List, Optional, Union

import pathspec
from printo import descript_data_object, not_none
from cantok import AbstractToken, DefaultToken
from printo import descript_data_object, not_none
from sigmatch import PossibleCallMatcher

from dirstree.crawlers.abstract import AbstractCrawler

Expand All @@ -30,15 +31,17 @@ def __init__(
*paths: Union[str, Path],
extensions: Optional[Collection[str]] = None,
exclude: Optional[List[str]] = None,
filter: Optional[Callable[[Path], bool]] = None,
token: AbstractToken = DefaultToken(),
filter: Optional[Callable[[Path], bool]] = None, # noqa: A002
token: AbstractToken = DefaultToken(), # noqa: B008
) -> None:
if extensions is not None:
for extension in extensions:
if not extension.startswith('.'):
raise ValueError(
f'The line with the file extension must start with a dot. You have passed: "{extension}".'
f'The line with the file extension must start with a dot. You have passed: "{extension}".',
)
if filter is not None:
PossibleCallMatcher('.').match(filter, raise_exception=True)

self.paths = paths
self.extensions = extensions
Expand Down Expand Up @@ -69,7 +72,7 @@ def __repr__(self) -> str:
filters=filters, # type: ignore[arg-type]
)

def go(self, token: AbstractToken = DefaultToken()) -> Generator[Path, None, None]:
def go(self, token: AbstractToken = DefaultToken()) -> Generator[Path, None, None]: # noqa: B008
token = token + self.token

excludes_spec = pathspec.PathSpec.from_lines('gitwildmatch', self.exclude)
Expand Down
6 changes: 3 additions & 3 deletions dirstree/crawlers/group.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List, Generator
from pathlib import Path
from typing import Generator, List

from cantok import AbstractToken, DefaultToken
from printo import descript_data_object
Expand All @@ -11,14 +11,14 @@ class CrawlersGroup(AbstractCrawler):
def __init__(self, crawlers: List[AbstractCrawler]) -> None:
self.crawlers = crawlers

def __repr__(self):
def __repr__(self) -> str:
return descript_data_object(
type(self).__name__,
(self.crawlers,),
{},
)

def go(self, token: AbstractToken = DefaultToken()) -> Generator[Path, None, None]:
def go(self, token: AbstractToken = DefaultToken()) -> Generator[Path, None, None]: # noqa: B008
memory = set()

for crawler in self.crawlers:
Expand Down
10 changes: 5 additions & 5 deletions dirstree/crawlers/python_crawler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import List, Optional, Union, Callable
from pathlib import Path
from typing import Callable, List, Optional, Union

from cantok import AbstractToken, DefaultToken

Expand All @@ -11,12 +11,12 @@ def __init__(
self,
*paths: Union[str, Path],
exclude: Optional[List[str]] = None,
filter: Optional[Callable[[Path], bool]] = None,
token: AbstractToken = DefaultToken(),
filter: Optional[Callable[[Path], bool]] = None, # noqa: A002
token: AbstractToken = DefaultToken(), # noqa: B008
) -> None:
super().__init__(
*paths, extensions=('.py',), exclude=exclude, filter=filter, token=token
*paths, extensions=('.py',), exclude=exclude, filter=filter, token=token,
)
self.addictional_repr_filters = {
'extensions': lambda x: False,
'extensions': lambda x: False, # noqa: ARG005
}
11 changes: 9 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ build-backend = "setuptools.build_meta"

[project]
name = "dirstree"
version = "0.0.3"
version = "0.0.4"
authors = [{ name = "Evgeniy Blinov", email = "zheni-b@yandex.ru" }]
description = 'Another library for iterating through the contents of a directory'
readme = "README.md"
requires-python = ">=3.8"
dependencies = ['pathspec==0.12.1', 'printo==0.0.8', 'cantok==0.0.32']
dependencies = ['pathspec==0.12.1', 'printo>=0.0.10', 'cantok==0.0.32', 'sigmatch>=0.0.6']

classifiers = [
"Operating System :: OS Independent",
Expand All @@ -25,6 +25,8 @@ classifiers = [
'Programming Language :: Python :: 3.12',
'Programming Language :: Python :: 3.13',
'Programming Language :: Python :: 3.14',
'Programming Language :: Python :: Free Threading',
'Programming Language :: Python :: Free Threading :: 3 - Stable',
'License :: OSI Approved :: MIT License',
'Intended Audience :: Developers',
'Topic :: Software Development :: Libraries',
Expand All @@ -41,6 +43,11 @@ runner = "pytest"
[tool.pytest.ini_options]
markers = ["mypy_testing"]

[tool.ruff]
lint.ignore = ['E501', 'E712', 'PTH123', 'PTH118', 'PLR2004', 'PTH107', 'SIM105', 'SIM102', 'RET503', 'PLR0912', 'C901']
lint.select = ["ERA001", "YTT", "ASYNC", "BLE", "B", "A", "COM", "INP", "PIE", "T20", "PT", "RSE", "RET", "SIM", "SLOT", "TID252", "ARG", "PTH", "I", "C90", "N", "E", "W", "D201", "D202", "D419", "F", "PL", "PLE", "PLR", "PLW", "RUF", "TRY201", "TRY400", "TRY401"]
format.quote-style = "single"

[project.urls]
'Source' = 'https://github.com/pomponchik/dirstree'
'Tracker' = 'https://github.com/pomponchik/dirstree/issues'
4 changes: 2 additions & 2 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ build==1.2.2.post1
twine==6.1.0
mypy==1.14.1
pytest-mypy-testing==0.1.3
ruff==0.9.9
ruff==0.14.6
mutmut==3.2.3
full_match==0.0.2
full_match==0.0.3
Loading
Loading