libsightseeing 0.2.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,68 @@
1
+ # python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ build/
8
+ develop-eggs/
9
+ dist/
10
+ downloads/
11
+ eggs/
12
+ .eggs/
13
+ lib/
14
+ lib64/
15
+ parts/
16
+ sdist/
17
+ var/
18
+ wheels/
19
+ share/python-wheels/
20
+ *.egg-info/
21
+ .installed.cfg
22
+ *.egg
23
+ MANIFEST
24
+
25
+ # virtual environments
26
+ .env
27
+ .venv
28
+ env/
29
+ venv/
30
+ ENV/
31
+ env.bak/
32
+ venv.bak/
33
+
34
+ # ides
35
+ .vscode/
36
+ .idea/
37
+ *.swp
38
+ *.swo
39
+ *~
40
+
41
+ # testing
42
+ .pytest_cache/
43
+ .coverage
44
+ htmlcov/
45
+ .tox/
46
+ .nox/
47
+
48
+ # raiseattention cache
49
+ .raiseattention/
50
+
51
+ # misc
52
+ .DS_Store
53
+ *.log
54
+
55
+ # nix
56
+ result
57
+ result-*
58
+ .direnv/
59
+
60
+ # playground and debug files
61
+ playground/
62
+ test_debug*.py
63
+ test_env_config.py
64
+
65
+ # caches
66
+ .ruff_cache/
67
+ .pytest_cache/
68
+ .mypy_cache/
@@ -0,0 +1,25 @@
1
+ This software is unencumbered and free-as-in-freedom.
2
+
3
+ This project is dual-licenced under The Unlicense or the BSD Zero Clause
4
+ License. (SPDX: `Unlicense OR 0BSD`)
5
+
6
+ The spirit and intent of the project is to treat the work as public domain via
7
+ The Unlicense, but providing the BSD Zero Clause License where public domain
8
+ dedication is not possible due to policies bound to a contributor or their
9
+ employer. However, this is not a legal condition.
10
+
11
+ Either way, you are free to use the software as you wish, without any
12
+ restrictions or obligations, subject only to the warranty disclaimers in the
13
+ licence texts.
14
+
15
+ > Does dual licencing not invalidate the ethos behind The Unlicense?
16
+
17
+ Well yeah, but like, even if ten percent of code is 0BSD-licenced, the rest
18
+ is still unlicenced. And that's... good enough, and better than the
19
+ alternative of a fully 0BSD-licenced project. _Everyone should be able to
20
+ contribute._
21
+
22
+ ---
23
+
24
+ See the [CONTRIBUTING](./CONTRIBUTING), [UNLICENSE](./UNLICENSE), and
25
+ [LICENSE-0BSD](./LICENSE-0BSD) files for more information.
@@ -0,0 +1,12 @@
1
+ Copyright (C) 2024 by Mark Joshwel <mark@joshwel.co>
2
+
3
+ Permission to use, copy, modify, and/or distribute this software for
4
+ any purpose with or without fee is hereby granted.
5
+
6
+ THE SOFTWARE IS PROVIDED “AS IS” AND THE AUTHOR DISCLAIMS ALL
7
+ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
8
+ OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE
9
+ FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
10
+ DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
11
+ AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
12
+ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
@@ -0,0 +1,149 @@
1
+ Metadata-Version: 2.4
2
+ Name: libsightseeing
3
+ Version: 0.2.0
4
+ Summary: a shared library for file finding and source resolution with gitignore support
5
+ Project-URL: Documentation, https://github.com/markjoshwel/RaiseAttention/tree/main/src/libsightseeing#readme
6
+ Project-URL: Repository, https://github.com/markjoshwel/RaiseAttention/tree/main/src/libsightseeing
7
+ Project-URL: Issues, https://github.com/markjoshwel/RaiseAttention/issues
8
+ Author-email: Mark Joshwel <mark@joshwel.co>
9
+ Maintainer-email: Mark Joshwel <mark@joshwel.co>
10
+ License-Expression: Unlicense OR 0BSD
11
+ License-File: LICENCING
12
+ License-File: LICENSE-0BSD
13
+ Keywords: file-finding,gitignore,source-resolution
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Intended Audience :: Developers
16
+ Classifier: License :: OSI Approved :: The Unlicense (Unlicense)
17
+ Classifier: License :: OSI Approved :: Zero-Clause BSD (0BSD)
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: >=3.11
24
+ Requires-Dist: pathspec>=1.0.0
25
+ Provides-Extra: dev
26
+ Requires-Dist: pytest>=8.0.0; extra == 'dev'
27
+ Description-Content-Type: text/markdown
28
+
29
+ # libsightseeing
30
+
31
+ a shared library for file finding and source resolution with gitignore support,
32
+ after i needed a simple way to find files while respecting .gitignore
33
+
34
+ ## installation
35
+
36
+ ```text
37
+ pip install libsightseeing
38
+ ```
39
+
40
+ ## usage
41
+
42
+ ### finding project root
43
+
44
+ ```python
45
+ from libsightseeing import find_project_root
46
+
47
+ # find project root from current directory
48
+ root = find_project_root()
49
+ if root:
50
+ print(f"found project at: {root}")
51
+
52
+ # find from a subdirectory
53
+ root = find_project_root("~/Works/example/sub/dir")
54
+ if root:
55
+ print(f"found project at: {root}") # ~/Works/example
56
+
57
+ # use with custom markers
58
+ root = find_project_root(
59
+ ".",
60
+ markers=[".git", "pyproject.toml", "package.json"]
61
+ )
62
+ ```
63
+
64
+ ### finding files (simple)
65
+
66
+ ```python
67
+ from libsightseeing import find_files
68
+
69
+ # find all python files
70
+ files = find_files(".", include=["*.py"])
71
+
72
+ # find files excluding tests
73
+ files = find_files("src", exclude=["tests"])
74
+
75
+ # include gitignored files
76
+ files = find_files(".", include=["*.py"], respect_gitignore=False)
77
+ ```
78
+
79
+ ### finding files (advanced)
80
+
81
+ use `SourceResolver` when you need more control or want to reuse the resolver:
82
+
83
+ ```python
84
+ from libsightseeing import SourceResolver
85
+
86
+ # create a reusable resolver
87
+ resolver = SourceResolver(
88
+ root=".",
89
+ include=["src/**/*.py"],
90
+ exclude=["tests", "*.pyc"],
91
+ respect_gitignore=True,
92
+ )
93
+
94
+ # resolve files multiple times (e.g., in a watch loop)
95
+ files = resolver.resolve()
96
+ ```
97
+
98
+ ### combining both
99
+
100
+ ```python
101
+ from libsightseeing import find_project_root, find_files
102
+
103
+ # find project root first, then find files there
104
+ root = find_project_root(".")
105
+ if root:
106
+ files = find_files(root, include=["*.py"])
107
+ ```
108
+
109
+ ## api differences
110
+
111
+ **`find_files()` vs `SourceResolver`**
112
+
113
+ - **`find_files()`** — simple one-liner function. creates a resolver internally
114
+ and returns files immediately. use this for one-off file finding.
115
+
116
+ - **`SourceResolver`** — class-based api. gives you a reusable resolver object
117
+ that you can call `.resolve()` on multiple times. use this when you need to
118
+ search the same directory repeatedly or want more control.
119
+
120
+ both respect .gitignore and support the same include/exclude patterns.
121
+
122
+ ## features
123
+
124
+ - **find project root**
125
+ walk up the tree looking for .git, pyproject.toml, package.json, cargo.toml, etc.
126
+
127
+ - **respects .gitignore**
128
+ automatically excludes gitignored files
129
+
130
+ - **glob patterns**
131
+ supports include/exclude patterns
132
+
133
+ - **simple one-liner**
134
+ `find_files()` and `find_project_root()` for quick usage
135
+
136
+ - **configurable resolver**
137
+ `SourceResolver` for advanced cases
138
+
139
+ - **lightweight**
140
+ only depends on pathspec
141
+
142
+ ## licence
143
+
144
+ libsightseeing is unencumbered, free-as-in-freedom, and is dual-licenced under
145
+ The Unlicense or the BSD Zero Clause License. (SPDX: `Unlicense OR 0BSD`)
146
+
147
+ you are free to use the software as you wish, without any restrictions or
148
+ obligations, subject only to the warranty disclaimers in the licence text
149
+ of your choosing.
@@ -0,0 +1,121 @@
1
+ # libsightseeing
2
+
3
+ a shared library for file finding and source resolution with gitignore support,
4
+ after i needed a simple way to find files while respecting .gitignore
5
+
6
+ ## installation
7
+
8
+ ```text
9
+ pip install libsightseeing
10
+ ```
11
+
12
+ ## usage
13
+
14
+ ### finding project root
15
+
16
+ ```python
17
+ from libsightseeing import find_project_root
18
+
19
+ # find project root from current directory
20
+ root = find_project_root()
21
+ if root:
22
+ print(f"found project at: {root}")
23
+
24
+ # find from a subdirectory
25
+ root = find_project_root("~/Works/example/sub/dir")
26
+ if root:
27
+ print(f"found project at: {root}") # ~/Works/example
28
+
29
+ # use with custom markers
30
+ root = find_project_root(
31
+ ".",
32
+ markers=[".git", "pyproject.toml", "package.json"]
33
+ )
34
+ ```
35
+
36
+ ### finding files (simple)
37
+
38
+ ```python
39
+ from libsightseeing import find_files
40
+
41
+ # find all python files
42
+ files = find_files(".", include=["*.py"])
43
+
44
+ # find files excluding tests
45
+ files = find_files("src", exclude=["tests"])
46
+
47
+ # include gitignored files
48
+ files = find_files(".", include=["*.py"], respect_gitignore=False)
49
+ ```
50
+
51
+ ### finding files (advanced)
52
+
53
+ use `SourceResolver` when you need more control or want to reuse the resolver:
54
+
55
+ ```python
56
+ from libsightseeing import SourceResolver
57
+
58
+ # create a reusable resolver
59
+ resolver = SourceResolver(
60
+ root=".",
61
+ include=["src/**/*.py"],
62
+ exclude=["tests", "*.pyc"],
63
+ respect_gitignore=True,
64
+ )
65
+
66
+ # resolve files multiple times (e.g., in a watch loop)
67
+ files = resolver.resolve()
68
+ ```
69
+
70
+ ### combining both
71
+
72
+ ```python
73
+ from libsightseeing import find_project_root, find_files
74
+
75
+ # find project root first, then find files there
76
+ root = find_project_root(".")
77
+ if root:
78
+ files = find_files(root, include=["*.py"])
79
+ ```
80
+
81
+ ## api differences
82
+
83
+ **`find_files()` vs `SourceResolver`**
84
+
85
+ - **`find_files()`** — simple one-liner function. creates a resolver internally
86
+ and returns files immediately. use this for one-off file finding.
87
+
88
+ - **`SourceResolver`** — class-based api. gives you a reusable resolver object
89
+ that you can call `.resolve()` on multiple times. use this when you need to
90
+ search the same directory repeatedly or want more control.
91
+
92
+ both respect .gitignore and support the same include/exclude patterns.
93
+
94
+ ## features
95
+
96
+ - **find project root**
97
+ walk up the tree looking for .git, pyproject.toml, package.json, cargo.toml, etc.
98
+
99
+ - **respects .gitignore**
100
+ automatically excludes gitignored files
101
+
102
+ - **glob patterns**
103
+ supports include/exclude patterns
104
+
105
+ - **simple one-liner**
106
+ `find_files()` and `find_project_root()` for quick usage
107
+
108
+ - **configurable resolver**
109
+ `SourceResolver` for advanced cases
110
+
111
+ - **lightweight**
112
+ only depends on pathspec
113
+
114
+ ## licence
115
+
116
+ libsightseeing is unencumbered, free-as-in-freedom, and is dual-licenced under
117
+ The Unlicense or the BSD Zero Clause License. (SPDX: `Unlicense OR 0BSD`)
118
+
119
+ you are free to use the software as you wish, without any restrictions or
120
+ obligations, subject only to the warranty disclaimers in the licence text
121
+ of your choosing.
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <https://unlicense.org/>
@@ -0,0 +1,100 @@
1
+ """
2
+ libsightseeing - a shared library for file finding and source resolution.
3
+
4
+ a library for finding files in repositories while respecting .gitignore files
5
+ and supporting include/exclude patterns.
6
+
7
+ functions:
8
+ `find_files` - one-liner api for finding files
9
+ `find_project_root` - find project root by walking up directory tree
10
+
11
+ classes:
12
+ `SourceResolver` - configurable file resolver with gitignore support
13
+
14
+ usage:
15
+ ```python
16
+ from libsightseeing import find_files, find_project_root, SourceResolver
17
+
18
+ # find project root
19
+ root = find_project_root("~/Works/example/sub/dir")
20
+ if root:
21
+ print(f"found project at: {root}") # ~/Works/example
22
+
23
+ # simple file finding
24
+ files = find_files(".", include=["*.py"])
25
+
26
+ # advanced usage
27
+ resolver = SourceResolver(
28
+ root=".",
29
+ include=["src/**/*.py"],
30
+ exclude=["tests"],
31
+ respect_gitignore=True,
32
+ )
33
+ files = resolver.resolve()
34
+ ```
35
+ """
36
+
37
+ from __future__ import annotations
38
+
39
+ from pathlib import Path
40
+
41
+ from .core import SourceResolver, find_project_root
42
+
43
+ __version__ = "0.2.0"
44
+ __all__ = ["find_files", "find_project_root", "SourceResolver"]
45
+
46
+
47
+ def find_files(
48
+ root: str | Path = ".",
49
+ *,
50
+ include: list[str] | None = None,
51
+ exclude: list[str] | None = None,
52
+ respect_gitignore: bool = True,
53
+ ) -> tuple[Path, ...]:
54
+ """
55
+ find files in a directory with gitignore support.
56
+
57
+ a convenience function that creates a SourceResolver with the given
58
+ parameters and returns the resolved files.
59
+
60
+ arguments:
61
+ `root: str | Path`
62
+ the root directory to search in (default: current directory)
63
+ `include: list[str] | None`
64
+ glob patterns for files to include
65
+ `exclude: list[str] | None`
66
+ glob patterns for files to exclude
67
+ `respect_gitignore: bool`
68
+ whether to respect .gitignore files (default: True)
69
+
70
+ returns: `tuple[Path, ...]`
71
+ tuple of resolved file paths
72
+
73
+ usage:
74
+ ```python
75
+ # find all python files
76
+ files = find_files(".", include=["*.py"])
77
+
78
+ # find files excluding tests
79
+ files = find_files("src", exclude=["tests"])
80
+
81
+ # include gitignored files
82
+ files = find_files(".", include=["*.py"], respect_gitignore=False)
83
+ ```
84
+ """
85
+ # call constructor directly, conditionally passing exclude
86
+ # this preserves the default exclude patterns from SourceResolver when not specified
87
+ if exclude is not None:
88
+ resolver = SourceResolver(
89
+ root=Path(root),
90
+ include=include or [],
91
+ exclude=exclude,
92
+ respect_gitignore=respect_gitignore,
93
+ )
94
+ else:
95
+ resolver = SourceResolver(
96
+ root=Path(root),
97
+ include=include or [],
98
+ respect_gitignore=respect_gitignore,
99
+ )
100
+ return resolver.resolve()