Skip to content

Commit 381a173

Browse files
authored
Improve path finding. (#67)
* Fix: Gitignore, include, and exclude path matching rules don't apply for file sources.
1 parent a7bba6f commit 381a173

File tree

15 files changed

+34
-10
lines changed

15 files changed

+34
-10
lines changed

docs/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
1616
- [Support `__all__` with add binary operator (concatenation) by @hadialqattan](https://github.com/hadialqattan/pycln/pull/64)
1717
- [Support `__all__` list operations (append & extend) by @hadialqattan](https://github.com/hadialqattan/pycln/pull/63)
1818

19+
### Fixed
20+
21+
- [Gitignore, include, and exclude path matching rules don't apply for file sources by @hadialqattan](https://github.com/hadialqattan/pycln/pull/67)
22+
1923
## [0.0.4] - 2021-07-07
2024

2125
### Fixed

pycln/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ def main( # pylint: disable=R0913,R0914
144144
)
145145
reporter = report.Report(configs)
146146
session_maker = refactor.Refactor(configs, reporter)
147-
gitignore = regexu.get_gitignore(Path("."), configs.no_gitignore)
148147
for path in configs.paths:
148+
gitignore = regexu.get_gitignore(
149+
path if path.is_dir() else path.parent, configs.no_gitignore
150+
)
149151
sources: Generator = pathu.yield_sources(
150152
path, configs.include, configs.exclude, gitignore, reporter
151153
)

pycln/utils/pathu.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@ def yield_sources(
5858
:param reporter: a `report.Report` object.
5959
:returns: generator of `.py` files paths.
6060
"""
61-
if path.is_file():
62-
if str(path).endswith(PY_EXTENSION):
63-
yield path
64-
return
65-
return
6661

6762
dirs: List[str] = []
6863
files: List[str] = []
6964

7065
is_included, is_excluded = regexu.is_included, regexu.is_excluded
7166

72-
scandir = os.scandir(path)
73-
for entry in scandir:
67+
if path.is_dir():
68+
root_dir = os.scandir(path) # type: ignore
69+
else:
70+
root_dir = {path} # type: ignore
71+
path = path.parent
72+
73+
for entry in root_dir:
7474

7575
# Skip symlinks.
7676
if entry.is_symlink():

tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from pathlib import Path
33

44
# Constatns.
5-
CONFIG_DIR = Path(__file__).parent.joinpath(Path("config"))
5+
CONFIG_DIR = Path(__file__).parent.joinpath("data/config")
File renamed without changes.

tests/data/config/cli.cfg

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This file has created for `tests/test_cli.py::test_integrations`.
2+
3+
[pycln]
4+
include = .*.py$
5+
exclude = .*_test.py$
6+
expand_stars = True
7+
verbose = True
8+
diff = True
9+
all = True
10+
no_gitignore = False
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)