Skip to content

Commit

Permalink
refractor
Browse files Browse the repository at this point in the history
  • Loading branch information
bitranox committed Sep 20, 2020
1 parent 2d61165 commit 34ede3e
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
23 changes: 23 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,35 @@ Usage
get all the rule files (default = '.gitignore') from the base_dir
all subdirectories will be searched for <filename> and the rules will be appended
Parameter
---------
path_base_dir
the base directory - all subdirectories will be searched for <filename>
filename
the rule filename, default = '.gitignore'
Examples
--------
>>> # test empty rule file
>>> path_test_dir = pathlib.Path(__file__).parent.parent.resolve() / 'tests'
>>> path_source_dir = path_test_dir / 'example'
>>> # parse existing file with rules
>>> ignore_parser=IgnoreParser()
>>> ignore_parser.parse_rule_files(path_test_dir, '.test_gitignore')
>>> # parse existing file without rules
>>> ignore_parser=IgnoreParser()
>>> ignore_parser.parse_rule_files(path_test_dir, '.test_gitignore_empty')
>>> # parse none existing file
>>> ignore_parser=IgnoreParser()
>>> ignore_parser.parse_rule_files(path_test_dir, '.test_not_existing')
"""
.. code-block:: python
Expand Down
29 changes: 24 additions & 5 deletions igittigitt/igittigitt.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,35 @@ def parse_rule_files(
get all the rule files (default = '.gitignore') from the base_dir
all subdirectories will be searched for <filename> and the rules will be appended
Parameter
---------
path_base_dir
the base directory - all subdirectories will be searched for <filename>
filename
the rule filename, default = '.gitignore'
Examples
--------
>>> # test empty rule file
>>> path_test_dir = pathlib.Path(__file__).parent.parent.resolve() / 'tests'
>>> path_source_dir = path_test_dir / 'example'
>>> # parse existing file with rules
>>> ignore_parser=IgnoreParser()
>>> ignore_parser.parse_rule_files(path_test_dir, '.test_gitignore')
>>> # parse existing file without rules
>>> ignore_parser=IgnoreParser()
>>> ignore_parser.parse_rule_files(path_test_dir, '.test_gitignore_empty')
>>> # parse none existing file
>>> ignore_parser=IgnoreParser()
>>> ignore_parser.parse_rule_files(path_test_dir, '.test_not_existing')
"""
# parse_rule_files}}}

Expand Down Expand Up @@ -161,11 +184,7 @@ def _parse_rule_file(
"""
path_rule_file = pathlib.Path(rule_file).resolve()

if base_dir is None:
path_base_dir = path_rule_file.parent
else:
path_base_dir = pathlib.Path(base_dir).resolve()
path_base_dir = path_rule_file.parent

with open(path_rule_file) as ignore_file:
counter = 0
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def test_parse_rule_files():
assert sorted(paths_filtered) == [
".test_gitignore",
".test_gitignore",
".test_gitignore_empty",
"excluded_not",
"excluded_not.txt",
"not_excluded",
Expand Down Expand Up @@ -180,7 +181,7 @@ def test_shutil_ignore_function():
path_source_dir, path_target_dir, ignore=ignore_parser.shutil_ignore,
)

assert len(list(path_target_dir.glob("**/*"))) == 8
assert len(list(path_target_dir.glob("**/*"))) == 9

# Teardown
shutil.rmtree(path_target_dir, ignore_errors=True)
Expand Down

0 comments on commit 34ede3e

Please sign in to comment.