jinja2-git-dir 0.1.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,8 @@
1
+ .cache/
2
+ .direnv/
3
+ .idea/
4
+ .venv/
5
+
6
+ __pycache__
7
+
8
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Gordon Code LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,73 @@
1
+ Metadata-Version: 2.4
2
+ Name: jinja2-git-dir
3
+ Version: 0.1.0
4
+ Summary: Jinja2 filter extension for detecting if a directory is a git repository
5
+ Project-URL: repository, https://github.com/gordoncode/jinja2-git-dir/
6
+ Author-email: Will Gordon <will@gordoncode.dev>
7
+ License: MIT License
8
+
9
+ Copyright (c) 2025 Gordon Code LLC
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ License-File: LICENSE
29
+ Keywords: copier,extension,filters,jinja,jinja2
30
+ Classifier: Development Status :: 5 - Production/Stable
31
+ Classifier: Intended Audience :: Developers
32
+ Classifier: License :: OSI Approved :: MIT License
33
+ Classifier: Operating System :: OS Independent
34
+ Classifier: Programming Language :: Python :: 3
35
+ Classifier: Typing :: Typed
36
+ Requires-Python: >=3.9
37
+ Requires-Dist: jinja2>=3.0
38
+ Description-Content-Type: text/markdown
39
+
40
+ # Git Directory Extension
41
+
42
+ Jinja2 filter extension for detecting if a directory is a git repository.
43
+
44
+ ## Usage
45
+
46
+ Examples:
47
+
48
+ - Detect if `git_path` is a git directory
49
+ `{{ git_path | gitdir }}`
50
+ - Assert that `git_path` is a git directory
51
+ `{{ git_path | gitdir is true }}`
52
+ - Assert that `git_path` is **NOT** a git directory
53
+ `{{ git_path | gitdir is false }}`
54
+ - Using `gitdir` in a conditional
55
+ `{% if (git_path | gitdir) %}{{ git_path }} is a git directory{% else %}no git directory at {{ git_path }}{% endif %}`
56
+
57
+ ### Copier
58
+
59
+ This can be utilized within a Copier `copier.yaml` file for determining if the destination
60
+ path is already initialized as a git directory.
61
+
62
+ Example:
63
+
64
+ This will configure a Copier `_task` to run `git init` but _only_ if the destination
65
+ path isn't already a git directory.
66
+
67
+ ```yaml
68
+ _jinja_extensions:
69
+ - jinja2_git_dir.GitDirectoryExtension
70
+ _tasks:
71
+ - command: "git init"
72
+ when: "{{ _copier_conf.dst_path | realpath | gitdir }}"
73
+ ```
@@ -0,0 +1,34 @@
1
+ # Git Directory Extension
2
+
3
+ Jinja2 filter extension for detecting if a directory is a git repository.
4
+
5
+ ## Usage
6
+
7
+ Examples:
8
+
9
+ - Detect if `git_path` is a git directory
10
+ `{{ git_path | gitdir }}`
11
+ - Assert that `git_path` is a git directory
12
+ `{{ git_path | gitdir is true }}`
13
+ - Assert that `git_path` is **NOT** a git directory
14
+ `{{ git_path | gitdir is false }}`
15
+ - Using `gitdir` in a conditional
16
+ `{% if (git_path | gitdir) %}{{ git_path }} is a git directory{% else %}no git directory at {{ git_path }}{% endif %}`
17
+
18
+ ### Copier
19
+
20
+ This can be utilized within a Copier `copier.yaml` file for determining if the destination
21
+ path is already initialized as a git directory.
22
+
23
+ Example:
24
+
25
+ This will configure a Copier `_task` to run `git init` but _only_ if the destination
26
+ path isn't already a git directory.
27
+
28
+ ```yaml
29
+ _jinja_extensions:
30
+ - jinja2_git_dir.GitDirectoryExtension
31
+ _tasks:
32
+ - command: "git init"
33
+ when: "{{ _copier_conf.dst_path | realpath | gitdir }}"
34
+ ```
@@ -0,0 +1,25 @@
1
+ from pathlib import Path
2
+ from subprocess import CalledProcessError, CompletedProcess, run
3
+
4
+ from jinja2.environment import Environment
5
+ from jinja2.ext import Extension
6
+
7
+
8
+ def _git_dir(git_path: str) -> bool:
9
+ # Utilize Path() to sanitize the input and resolve to an absolute path
10
+ try:
11
+ git_path = str(Path(git_path).resolve())
12
+ except TypeError:
13
+ return False
14
+ command: list[str] = ["git", "-C", git_path, "rev-parse", "--show-toplevel"]
15
+ try:
16
+ result: CompletedProcess[str] = run(command, check=True, capture_output=True, text=True) # noqa: S603
17
+ return result.stdout.lower() == git_path
18
+ except CalledProcessError:
19
+ return False
20
+
21
+
22
+ class GitDirectoryExtension(Extension):
23
+ def __init__(self, environment: Environment) -> None:
24
+ super().__init__(environment)
25
+ environment.filters["gitdir"] = _git_dir
File without changes
@@ -0,0 +1,74 @@
1
+ [project]
2
+ name = "jinja2-git-dir"
3
+ version = "v0.1.0"
4
+ description = "Jinja2 filter extension for detecting if a directory is a git repository"
5
+ authors = [
6
+ {name = "Will Gordon", email = "will@gordoncode.dev"},
7
+ ]
8
+ readme = "README.md"
9
+ license = {file = "LICENSE"}
10
+ requires-python = ">=3.9"
11
+ classifiers = [
12
+ "Development Status :: 5 - Production/Stable",
13
+ "Intended Audience :: Developers",
14
+ "License :: OSI Approved :: MIT License",
15
+ "Operating System :: OS Independent",
16
+ "Programming Language :: Python :: 3",
17
+ "Typing :: Typed"
18
+ ]
19
+ keywords = ["jinja", "jinja2", "extension", "filters", "copier"]
20
+ dependencies = ["jinja2>=3.0"]
21
+
22
+ [project.urls]
23
+ repository = "https://github.com/gordoncode/jinja2-git-dir/"
24
+
25
+ [dependency-groups]
26
+ dev = ["mypy", "ruff", "pylint", "pytest", "pytest-subprocess"]
27
+
28
+ [tool.hatch.build.targets.sdist]
29
+ packages = ["src/jinja2_git_dir"]
30
+
31
+ [build-system]
32
+ requires = ["hatchling"]
33
+ build-backend = "hatchling.build"
34
+
35
+ [tool.ruff]
36
+ line-length = 120
37
+ src = ["src"]
38
+ target-version = "py39"
39
+ cache-dir = ".cache/.ruff_cache"
40
+ force-exclude = true
41
+
42
+ [tool.ruff.lint]
43
+ select = ["ALL"]
44
+ ignore = ["D100", "D101", "D102", "D104", "D205", "D401", "COM812"]
45
+ unfixable = ["T201", "F401", "F841"]
46
+
47
+ [tool.ruff.lint.per-file-ignores]
48
+ "test_*.py" = ["S101", "PLR2004", "SLF001", "INP001", "ANN001", "ANN201", "D103"]
49
+
50
+ [tool.ruff.lint.isort]
51
+ known-first-party = ["src"]
52
+ section-order = ["future", "standard-library", "third-party", "first-party", "local-folder"]
53
+
54
+ [tool.ruff.lint.pydocstyle]
55
+ convention = "numpy"
56
+
57
+ [tool.pytest.ini_options]
58
+ cache_dir = ".cache/.pytest_cache"
59
+ python_files = "test_*.py"
60
+
61
+ [tool.pylint.master]
62
+ ignore-patterns = "test_.*.py"
63
+
64
+ [tool.pylint.format]
65
+ max-line-length = 120
66
+
67
+ [tool.pylint.messages_control]
68
+ disable = ["missing-module-docstring", "missing-class-docstring"]
69
+
70
+ [tool.pylint.string]
71
+ check-quote-consistency = "yes"
72
+
73
+ [tool.mypy]
74
+ cache_dir = ".cache/.mypy_cache"