Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove ignore paths in workflows triggers #16

Merged
merged 2 commits into from
Jan 5, 2024
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
6 changes: 0 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,9 @@ on:
branches:
- "main"
- "master"
paths-ignore:
- "**.md"
- LICENSE
pull_request:
branches:
- "*"
paths-ignore:
- "**.md"
- LICENSE
workflow_dispatch:
release:
types: [published, edited]
Expand Down
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
[![codecov](https://codecov.io/gh/andhus/scantree/branch/master/graph/badge.svg)](https://codecov.io/gh/andhus/scantree)

# scantree

Recursive directory iterator supporting:

- flexible filtering including wildcard path matching
- in memory representation of file-tree (for repeated access)
- efficient access to directory entry properties (`posix.DirEntry` interface) extended with real path and path relative to the recursion root directory
- detection and handling of cyclic symlinks

## Installation

```commandline
pip install scantree
```

## Usage

See source code for full documentation, some generic examples below.

Get matching file paths:

```python
from scantree import scantree, RecursionFilter

tree = scantree('/path/to/dir', RecursionFilter(match=['*.txt']))
print([path.relative for path in tree.filepaths()])
print([path.real for path in tree.filepaths()])
```

```
['d1/d2/file3.txt', 'd1/file2.txt', 'file1.txt']
['/path/to/other_dir/file3.txt', '/path/to/dir/d1/file2.txt', '/path/to/dir/file1.txt']
```

Access metadata of directory entries in file tree:

```python
d2 = tree.directories[0].directories[0]
print(type(d2))
Expand All @@ -36,6 +44,7 @@ print(d2.path.real)
print(d2.path.is_symlink())
print(d2.files[0].relative)
```

```
scantree._node.DirNode
/path/to/dir/d1/d2
Expand All @@ -45,6 +54,7 @@ d1/d2/file3.txt
```

Aggregate information by operating on tree:

```python
hello_count = tree.apply(
file_apply=lambda path: sum([
Expand All @@ -55,6 +65,7 @@ hello_count = tree.apply(
)
print(hello_count)
```

```
3
```
Expand All @@ -77,6 +88,7 @@ hello_count_tree = tree.apply(
from pprint import pprint
pprint(hello_count_tree)
```

```
{'count': 3,
'name': 'dir',
Expand All @@ -91,6 +103,7 @@ pprint(hello_count_tree)
```

Flexible filtering:

```python
without_hidden_files = scantree('.', RecursionFilter(match=['*', '!.*']))

Expand All @@ -107,6 +120,7 @@ without_palindrome_linked_dirs = scantree(
```

Comparison:

```python
tree = scandir('path/to/dir')
# make some operations on filesystem, make sure file tree is the same:
Expand All @@ -124,6 +138,7 @@ assert (
```

Inspect symlinks:

```python
from scantree import CyclicLinkedDir

Expand All @@ -142,4 +157,4 @@ def dir_apply(dir_node):
cyclic_links.append((dir_node.path, dir_node.target_path))

scantree('.', file_apply=file_apply, dir_apply=dir_apply)
```
```
Loading