ignorante 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,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Jasper van Merle
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,18 @@
1
+ Metadata-Version: 2.4
2
+ Name: ignorante
3
+ Version: 0.1.0
4
+ Summary: CLI to generate .gitignore files by combining templates from github/gitignore, interactively or by name
5
+ Keywords: gitignore,cli
6
+ Author: Jasper van Merle
7
+ Author-email: Jasper van Merle <jaspervmerle@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: Environment :: Console
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Topic :: Software Development :: Version Control :: Git
14
+ Classifier: Programming Language :: Python :: 3
15
+ Requires-Dist: platformdirs>=4.10.1
16
+ Requires-Dist: questionary>=2.1.1
17
+ Requires-Dist: typer>=0.27.0
18
+ Requires-Python: >=3.12
@@ -0,0 +1,40 @@
1
+ [project]
2
+ name = "ignorante"
3
+ version = "0.1.0"
4
+ description = "CLI to generate .gitignore files by combining templates from github/gitignore, interactively or by name"
5
+ license = "MIT"
6
+ license-files = ["LICENSE"]
7
+ authors = [{ name = "Jasper van Merle", email = "jaspervmerle@gmail.com" }]
8
+ keywords = ["gitignore", "cli"]
9
+ classifiers = [
10
+ "Development Status :: 4 - Beta",
11
+ "Environment :: Console",
12
+ "Intended Audience :: Developers",
13
+ "Topic :: Software Development :: Version Control :: Git",
14
+ "Programming Language :: Python :: 3"
15
+ ]
16
+ requires-python = ">=3.12"
17
+ dependencies = [
18
+ "platformdirs>=4.10.1",
19
+ "questionary>=2.1.1",
20
+ "typer>=0.27.0",
21
+ ]
22
+
23
+ [project.scripts]
24
+ ignorante = "ignorante.__main__:main"
25
+
26
+ [build-system]
27
+ requires = ["uv_build>=0.11.30,<0.12.0"]
28
+ build-backend = "uv_build"
29
+
30
+ [dependency-groups]
31
+ dev = [
32
+ "ruff>=0.15.22",
33
+ "ty>=0.0.61",
34
+ ]
35
+
36
+ [tool.ruff]
37
+ line-length = 120
38
+
39
+ [tool.ruff.lint]
40
+ extend-select = ["I"]
@@ -0,0 +1,5 @@
1
+ import importlib.metadata
2
+
3
+ IGNORANTE = "ignorante"
4
+
5
+ __version__ = importlib.metadata.version(IGNORANTE)
@@ -0,0 +1,53 @@
1
+ import sys
2
+ from pathlib import Path
3
+ from typing import Annotated
4
+
5
+ from typer import Argument, Exit, Option, Typer
6
+
7
+ from ignorante import __version__
8
+ from ignorante.generate import generate_gitignore
9
+ from ignorante.interactive import select_templates
10
+
11
+ app = Typer(context_settings={"help_option_names": ["--help", "-h"]}, add_completion=False)
12
+
13
+
14
+ def version_callback(value: bool) -> None:
15
+ if value:
16
+ print(__version__)
17
+ raise Exit()
18
+
19
+
20
+ @app.command()
21
+ def cli(
22
+ templates: Annotated[
23
+ list[str] | None,
24
+ Argument(help="Names of gitignore templates to combine. Omit to select templates interactively."),
25
+ ] = None,
26
+ output: Annotated[
27
+ Path | None,
28
+ Option("-o", "--output", help="Write the generated .gitignore to this file instead of stdout."),
29
+ ] = None,
30
+ version: Annotated[
31
+ bool | None,
32
+ Option("-v", "--version", help="Print the version and exit.", callback=version_callback, is_eager=True),
33
+ ] = None,
34
+ ) -> None:
35
+ try:
36
+ names = templates if templates else select_templates()
37
+ content = generate_gitignore(names)
38
+ except (RuntimeError, ValueError) as error:
39
+ print(error, file=sys.stderr)
40
+ raise Exit(1) from error
41
+
42
+ if output is not None:
43
+ output.write_text(content)
44
+ else:
45
+ print(content, end="")
46
+
47
+
48
+ def main() -> None:
49
+ app()
50
+
51
+
52
+ if __name__ == "__main__":
53
+ main()
@@ -0,0 +1,27 @@
1
+ from ignorante.templates import find_templates, sort_key
2
+
3
+
4
+ def generate_gitignore(names: list[str]) -> str:
5
+ """Fetch and combine the given gitignore templates into a single file."""
6
+ if not names:
7
+ return ""
8
+
9
+ sorted_names = sorted((name.strip().lower() for name in names), key=sort_key)
10
+
11
+ templates = find_templates()
12
+ name_by_lower_name = {name.lower(): name for name in templates}
13
+
14
+ sections = []
15
+ for lower_name in sorted_names:
16
+ name = name_by_lower_name.get(lower_name)
17
+
18
+ if name is None:
19
+ raise ValueError(f"Unknown gitignore template: {lower_name!r}")
20
+
21
+ sections.append(f"### {name} ###\n{templates[name].read_text().strip()}")
22
+
23
+ command = f"uvx ignorante {' '.join(sorted_names)}"
24
+ header = f"# Created with https://github.com/jmerle/ignorante\n# Update by running `{command}`"
25
+ footer = f"# End of `{command}`"
26
+
27
+ return "\n\n".join([header, *sections, footer]) + "\n"
@@ -0,0 +1,22 @@
1
+ import questionary
2
+
3
+ from ignorante.templates import find_templates, sort_key
4
+
5
+
6
+ def select_templates() -> list[str]:
7
+ """Prompt the user to interactively select gitignore templates.
8
+
9
+ Returns the names of the selected templates, in their original casing.
10
+ """
11
+ names = sorted(find_templates(), key=sort_key)
12
+ selected = questionary.checkbox(
13
+ "Select gitignore templates to include",
14
+ choices=names,
15
+ use_jk_keys=False,
16
+ use_search_filter=True,
17
+ ).ask()
18
+
19
+ if selected is None:
20
+ raise RuntimeError("Aborted.")
21
+
22
+ return selected
@@ -0,0 +1,48 @@
1
+ import subprocess
2
+ import time
3
+ from pathlib import Path
4
+ from shutil import which
5
+
6
+ from platformdirs import user_cache_path
7
+
8
+ from ignorante import IGNORANTE
9
+
10
+ REPOSITORY_URL = "https://github.com/github/gitignore.git"
11
+ UPDATE_INTERVAL = 60 * 60 * 24 # 1 day, in seconds
12
+
13
+
14
+ def get_repository() -> Path:
15
+ """Return the root of a local, always up-to-date clone of github/gitignore.
16
+
17
+ The clone lives in the user's cache directory. It is created on first use
18
+ and pulled at most once a day on subsequent calls.
19
+ """
20
+ if which("git") is None:
21
+ raise RuntimeError("git is required by ignorante but was not found on PATH.")
22
+
23
+ repo_path = user_cache_path(IGNORANTE, ensure_exists=True) / "gitignore"
24
+
25
+ if not (repo_path / ".git").exists():
26
+ _run_git("clone", "--depth", "1", REPOSITORY_URL, str(repo_path))
27
+ elif _seconds_since_last_pull(repo_path) >= UPDATE_INTERVAL:
28
+ _run_git("pull", "--depth", "1", cwd=repo_path)
29
+
30
+ return repo_path
31
+
32
+
33
+ def _seconds_since_last_pull(repo_path: Path) -> float:
34
+ # git touches .git/FETCH_HEAD on every fetch/pull, so its mtime doubles as a
35
+ # "last updated" timestamp without needing to persist one ourselves.
36
+ fetch_head = repo_path / ".git" / "FETCH_HEAD"
37
+
38
+ if not fetch_head.exists():
39
+ return float("inf")
40
+
41
+ return time.time() - fetch_head.stat().st_mtime
42
+
43
+
44
+ def _run_git(*args: str, cwd: Path | None = None) -> None:
45
+ result = subprocess.run(["git", *args], cwd=cwd, capture_output=True, text=True)
46
+
47
+ if result.returncode != 0:
48
+ raise RuntimeError(f"git {args[0]} failed: {result.stderr.strip()}")
@@ -0,0 +1,22 @@
1
+ from pathlib import Path
2
+
3
+ from ignorante.repository import get_repository
4
+
5
+
6
+ def find_templates() -> dict[str, Path]:
7
+ """Map every template name, in original casing, to its file.
8
+
9
+ e.g. "Python" -> repo/Python.gitignore, "Global/Linux" -> repo/Global/Linux.gitignore,
10
+ "community/Golang/Hugo" -> repo/community/Golang/Hugo.gitignore.
11
+ """
12
+ repo = get_repository()
13
+ return {path.relative_to(repo).with_suffix("").as_posix(): path for path in repo.rglob("*.gitignore")}
14
+
15
+
16
+ def sort_key(name: str) -> tuple[int, str]:
17
+ """Sort key that groups root-level templates first, then Global/, then community/.
18
+
19
+ Each group is sorted lexicographically, case-insensitively, within itself.
20
+ """
21
+ group = {"global": 1, "community": 2}.get(name.split("/", 1)[0].lower(), 0)
22
+ return group, name.lower()