hinagata 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,119 @@
1
+ Metadata-Version: 2.3
2
+ Name: hinagata
3
+ Version: 0.2.0
4
+ Summary: A lightweight license generator CLI.
5
+ Author: Keksi
6
+ Author-email: Keksi <hello@keksi.dev>
7
+ Requires-Dist: questionary>=2.1.1
8
+ Requires-Dist: typer>=0.27.3
9
+ Requires-Python: >=3.12
10
+ Description-Content-Type: text/markdown
11
+
12
+ # hinagata
13
+
14
+ A lightweight license generator CLI. Pick a license from a filterable list,
15
+ confirm the author and year, and get a `LICENSE` file.
16
+
17
+ Also available as the shorter `hina`.
18
+
19
+ ## Quick start
20
+
21
+ ```sh
22
+ uvx hinagata
23
+ ```
24
+
25
+ That runs `hinagata` once without installing anything. To keep it around:
26
+
27
+ ```sh
28
+ uv tool install hinagata
29
+ hinagata
30
+ ```
31
+
32
+ ## Installation
33
+
34
+ | Method | Run once | Install | Upgrade |
35
+ | ---------- | --------------------- | --------------------------- | --------------------------- |
36
+ | `uv` | `uvx hinagata` | `uv tool install hinagata` | `uv tool upgrade hinagata` |
37
+ | `pipx` | `pipx run hinagata` | `pipx install hinagata` | `pipx upgrade hinagata` |
38
+ | `pip` | | `pip install hinagata` | `pip install -U hinagata` |
39
+
40
+ `pip` installs into the current environment, so use a virtual environment or
41
+ `pip install --user hinagata`. With `uv`, `uv pip install hinagata` works the
42
+ same way.
43
+
44
+ To use the development version, install from Git or from a clone:
45
+
46
+ ```sh
47
+ uv tool install git+https://github.com/keksiqc/hinagata
48
+ uv sync && uv run hinagata
49
+ ```
50
+
51
+ `python -m hinagata` also works wherever the package is installed.
52
+
53
+ ## Usage
54
+
55
+ Run without arguments to choose a license interactively. Everything can also be
56
+ passed as flags, which skips the matching prompt and makes the command
57
+ scriptable:
58
+
59
+ ```sh
60
+ hinagata MIT --author "Ada Lovelace" --year 2026 # write ./LICENSE
61
+ hinagata Apache-2.0 --output LICENSE.txt --force # custom file, overwrite
62
+ hinagata ISC -o - > LICENSE # print to stdout
63
+ hinagata --list # show the catalogue
64
+ ```
65
+
66
+ | Option | Description |
67
+ | -------------- | --------------------------------------------------------- |
68
+ | `[LICENSE]` | SPDX identifier, case-insensitive. Asked when omitted. |
69
+ | `-a, --author` | Copyright holder. Defaults to `git config user.name`. |
70
+ | `-y, --year` | Year or range such as `2020-2026`. Defaults to this year. |
71
+ | `-o, --output` | File to write, or `-` for stdout. Defaults to `LICENSE`. |
72
+ | `-f, --force` | Overwrite an existing file without asking. |
73
+ | `-l, --list` | List the available licenses. |
74
+ | `--version` | Show the version. |
75
+
76
+ Author and year are only asked for licenses whose text contains them (MIT, ISC,
77
+ BSD, 0BSD). The others, such as the GPL family and Apache-2.0, are written
78
+ verbatim.
79
+
80
+ ### Short alias
81
+
82
+ `hina` is an alias for `hinagata` and takes the same arguments, which is handy
83
+ for everyday use once it is installed:
84
+
85
+ ```sh
86
+ hina MIT -a "Ada Lovelace"
87
+ ```
88
+
89
+ It ships inside the `hinagata` package rather than as a package of its own, so
90
+ `uvx hina` would fetch an unrelated project from PyPI. To run the alias without
91
+ installing, name the package explicitly:
92
+
93
+ ```sh
94
+ uvx --from hinagata hina MIT
95
+ pipx run --spec hinagata hina MIT
96
+ ```
97
+
98
+ ## Bundled licenses
99
+
100
+ MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD, BSL-1.0, MPL-2.0,
101
+ LGPL-3.0, GPL-2.0, GPL-3.0, AGPL-3.0, Unlicense and CC0-1.0. The texts come
102
+ from [choosealicense.com](https://github.com/github/choosealicense.com).
103
+
104
+ ## Development
105
+
106
+ Install the project and its development dependencies:
107
+
108
+ ```sh
109
+ uv sync
110
+ ```
111
+
112
+ Run the checks:
113
+
114
+ ```sh
115
+ uv run ruff format --check .
116
+ uv run ruff check .
117
+ uv run ty check .
118
+ uv run pytest
119
+ ```
@@ -0,0 +1,108 @@
1
+ # hinagata
2
+
3
+ A lightweight license generator CLI. Pick a license from a filterable list,
4
+ confirm the author and year, and get a `LICENSE` file.
5
+
6
+ Also available as the shorter `hina`.
7
+
8
+ ## Quick start
9
+
10
+ ```sh
11
+ uvx hinagata
12
+ ```
13
+
14
+ That runs `hinagata` once without installing anything. To keep it around:
15
+
16
+ ```sh
17
+ uv tool install hinagata
18
+ hinagata
19
+ ```
20
+
21
+ ## Installation
22
+
23
+ | Method | Run once | Install | Upgrade |
24
+ | ---------- | --------------------- | --------------------------- | --------------------------- |
25
+ | `uv` | `uvx hinagata` | `uv tool install hinagata` | `uv tool upgrade hinagata` |
26
+ | `pipx` | `pipx run hinagata` | `pipx install hinagata` | `pipx upgrade hinagata` |
27
+ | `pip` | | `pip install hinagata` | `pip install -U hinagata` |
28
+
29
+ `pip` installs into the current environment, so use a virtual environment or
30
+ `pip install --user hinagata`. With `uv`, `uv pip install hinagata` works the
31
+ same way.
32
+
33
+ To use the development version, install from Git or from a clone:
34
+
35
+ ```sh
36
+ uv tool install git+https://github.com/keksiqc/hinagata
37
+ uv sync && uv run hinagata
38
+ ```
39
+
40
+ `python -m hinagata` also works wherever the package is installed.
41
+
42
+ ## Usage
43
+
44
+ Run without arguments to choose a license interactively. Everything can also be
45
+ passed as flags, which skips the matching prompt and makes the command
46
+ scriptable:
47
+
48
+ ```sh
49
+ hinagata MIT --author "Ada Lovelace" --year 2026 # write ./LICENSE
50
+ hinagata Apache-2.0 --output LICENSE.txt --force # custom file, overwrite
51
+ hinagata ISC -o - > LICENSE # print to stdout
52
+ hinagata --list # show the catalogue
53
+ ```
54
+
55
+ | Option | Description |
56
+ | -------------- | --------------------------------------------------------- |
57
+ | `[LICENSE]` | SPDX identifier, case-insensitive. Asked when omitted. |
58
+ | `-a, --author` | Copyright holder. Defaults to `git config user.name`. |
59
+ | `-y, --year` | Year or range such as `2020-2026`. Defaults to this year. |
60
+ | `-o, --output` | File to write, or `-` for stdout. Defaults to `LICENSE`. |
61
+ | `-f, --force` | Overwrite an existing file without asking. |
62
+ | `-l, --list` | List the available licenses. |
63
+ | `--version` | Show the version. |
64
+
65
+ Author and year are only asked for licenses whose text contains them (MIT, ISC,
66
+ BSD, 0BSD). The others, such as the GPL family and Apache-2.0, are written
67
+ verbatim.
68
+
69
+ ### Short alias
70
+
71
+ `hina` is an alias for `hinagata` and takes the same arguments, which is handy
72
+ for everyday use once it is installed:
73
+
74
+ ```sh
75
+ hina MIT -a "Ada Lovelace"
76
+ ```
77
+
78
+ It ships inside the `hinagata` package rather than as a package of its own, so
79
+ `uvx hina` would fetch an unrelated project from PyPI. To run the alias without
80
+ installing, name the package explicitly:
81
+
82
+ ```sh
83
+ uvx --from hinagata hina MIT
84
+ pipx run --spec hinagata hina MIT
85
+ ```
86
+
87
+ ## Bundled licenses
88
+
89
+ MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD, BSL-1.0, MPL-2.0,
90
+ LGPL-3.0, GPL-2.0, GPL-3.0, AGPL-3.0, Unlicense and CC0-1.0. The texts come
91
+ from [choosealicense.com](https://github.com/github/choosealicense.com).
92
+
93
+ ## Development
94
+
95
+ Install the project and its development dependencies:
96
+
97
+ ```sh
98
+ uv sync
99
+ ```
100
+
101
+ Run the checks:
102
+
103
+ ```sh
104
+ uv run ruff format --check .
105
+ uv run ruff check .
106
+ uv run ty check .
107
+ uv run pytest
108
+ ```
@@ -0,0 +1,83 @@
1
+ [project]
2
+ name = "hinagata"
3
+ version = "0.2.0"
4
+ description = "A lightweight license generator CLI."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ dependencies = [
8
+ "questionary>=2.1.1",
9
+ "typer>=0.27.3",
10
+ ]
11
+
12
+ [[project.authors]]
13
+ name = "Keksi"
14
+ email = "hello@keksi.dev"
15
+
16
+ [project.scripts]
17
+ hina = "hinagata.cli:app"
18
+ hinagata = "hinagata.cli:app"
19
+
20
+ [dependency-groups]
21
+ dev = [
22
+ "commitizen>=4.19.2",
23
+ "coverage>=7.16.2",
24
+ "prek>=0.5.5",
25
+ "pytest>=9.1.1",
26
+ "ruff>=0.17.0",
27
+ "rumdl>=0.2.79",
28
+ "tombi>=1.8.4",
29
+ "ty>=0.0.86",
30
+ ]
31
+ docs = ["zensical>=0.0.69"]
32
+
33
+ [build-system]
34
+ requires = ["uv_build>=0.13.0,<0.14"]
35
+ build-backend = "uv_build"
36
+
37
+ [tool.commitizen]
38
+ name = "cz_conventional_commits"
39
+ tag_format = "v$version"
40
+ version_scheme = "pep440"
41
+ version_provider = "uv"
42
+ annotated_tag = true
43
+ update_changelog_on_bump = true
44
+ major_version_zero = true
45
+
46
+ [tool.coverage.run]
47
+ branch = true
48
+ omit = ["*/__main__.py"]
49
+ parallel = true
50
+ source = ["src"]
51
+
52
+ [tool.pytest.ini_options]
53
+ cache_dir = ".cache/pytest"
54
+ testpaths = "tests"
55
+
56
+ [tool.ruff]
57
+ cache-dir = "~/.cache/ruff"
58
+ line-length = 120
59
+ output-format = "grouped"
60
+
61
+ [tool.ruff.format]
62
+ docstring-code-format = true
63
+ indent-style = "space"
64
+ line-ending = "lf"
65
+ quote-style = "double"
66
+
67
+ [tool.ruff.lint]
68
+ preview = true
69
+ select = [
70
+ "correctness",
71
+ "suspicious",
72
+ "complexity",
73
+ "performance",
74
+ "style",
75
+ "security",
76
+ ]
77
+
78
+ [tool.ruff.lint.isort]
79
+ required-imports = ["from __future__ import annotations"]
80
+ lines-after-imports = 2
81
+
82
+ [tool.tombi.files]
83
+ exclude = ["uv.lock"]
@@ -0,0 +1,73 @@
1
+ [project]
2
+ name = "hinagata"
3
+ version = "0.2.0"
4
+ description = "A lightweight license generator CLI."
5
+ readme = "README.md"
6
+ requires-python = ">=3.12"
7
+ authors = [{ name = "Keksi", email = "hello@keksi.dev" }]
8
+ dependencies = [
9
+ "questionary>=2.1.1",
10
+ "typer>=0.27.3",
11
+ ]
12
+
13
+ [project.scripts]
14
+ hina = "hinagata.cli:app"
15
+ hinagata = "hinagata.cli:app"
16
+
17
+ [dependency-groups]
18
+ dev = [
19
+ "commitizen>=4.19.2",
20
+ "coverage>=7.16.2",
21
+ "prek>=0.5.5",
22
+ "pytest>=9.1.1",
23
+ "ruff>=0.17.0",
24
+ "rumdl>=0.2.79",
25
+ "tombi>=1.8.4",
26
+ "ty>=0.0.86",
27
+ ]
28
+ docs = ["zensical>=0.0.69"]
29
+
30
+ [build-system]
31
+ requires = ["uv_build>=0.13.0,<0.14"]
32
+ build-backend = "uv_build"
33
+
34
+ [tool.commitizen]
35
+ name = "cz_conventional_commits"
36
+ tag_format = "v$version"
37
+ version_scheme = "pep440"
38
+ version_provider = "uv"
39
+ annotated_tag = true
40
+ update_changelog_on_bump = true
41
+ major_version_zero = true
42
+
43
+ [tool.coverage.run]
44
+ branch = true
45
+ omit = ["*/__main__.py"]
46
+ parallel = true
47
+ source = ["src"]
48
+
49
+ [tool.pytest.ini_options]
50
+ cache_dir = ".cache/pytest"
51
+ testpaths = "tests"
52
+
53
+ [tool.ruff]
54
+ cache-dir = "~/.cache/ruff"
55
+ line-length = 120
56
+ output-format = "grouped"
57
+
58
+ [tool.ruff.format]
59
+ docstring-code-format = true
60
+ indent-style = "space"
61
+ line-ending = "lf"
62
+ quote-style = "double"
63
+
64
+ [tool.ruff.lint]
65
+ preview = true
66
+ select = ["correctness", "suspicious", "complexity", "performance", "style", "security"]
67
+
68
+ [tool.ruff.lint.isort]
69
+ required-imports = ["from __future__ import annotations"]
70
+ lines-after-imports = 2
71
+
72
+ [tool.tombi.files]
73
+ exclude = ["uv.lock"]
@@ -0,0 +1,8 @@
1
+ """Lightweight license generator."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from .cli import app
6
+
7
+
8
+ __all__ = ["app"]
@@ -0,0 +1,7 @@
1
+ from __future__ import annotations
2
+
3
+ from .cli import app
4
+
5
+
6
+ if __name__ == "__main__":
7
+ app()
@@ -0,0 +1,129 @@
1
+ """Command-line interface for hinagata."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import difflib
6
+ import getpass
7
+ import subprocess # noqa: S404
8
+ import sys
9
+ from datetime import UTC, datetime
10
+ from importlib.metadata import version
11
+ from pathlib import Path
12
+ from typing import Annotated
13
+
14
+ import typer
15
+ from rich.console import Console
16
+ from rich.table import Table
17
+
18
+ from . import prompts
19
+ from .licenses import LICENSES, License, find, is_valid_year
20
+
21
+
22
+ STDOUT = "-"
23
+
24
+ app = typer.Typer(add_completion=False, help="Generate a license file for your project.")
25
+ console = Console(stderr=True)
26
+
27
+
28
+ @app.command()
29
+ def generate(
30
+ license_id: Annotated[
31
+ str | None,
32
+ typer.Argument(metavar="[LICENSE]", help="SPDX identifier such as MIT. Asked interactively when omitted."),
33
+ ] = None,
34
+ author: Annotated[str | None, typer.Option("--author", "-a", help="Copyright holder.")] = None,
35
+ year: Annotated[str | None, typer.Option("--year", "-y", help="Copyright year or range.")] = None,
36
+ output: Annotated[Path, typer.Option("--output", "-o", help="File to write, or - for stdout.")] = Path("LICENSE"),
37
+ force: Annotated[bool, typer.Option("--force", "-f", help="Overwrite an existing file.")] = False,
38
+ list_licenses: Annotated[bool, typer.Option("--list", "-l", help="List the available licenses.")] = False,
39
+ show_version: Annotated[bool, typer.Option("--version", help="Show the version.", is_eager=True)] = False,
40
+ ) -> None:
41
+ """Generate a license file for your project."""
42
+ if show_version:
43
+ typer.echo(version("hinagata"))
44
+ raise typer.Exit
45
+ if list_licenses:
46
+ _print_catalogue()
47
+ raise typer.Exit
48
+ if year is not None and not is_valid_year(year):
49
+ msg = "use a year like 2026 or a range like 2020-2026"
50
+ raise typer.BadParameter(msg, param_hint="--year")
51
+
52
+ interactive = is_interactive()
53
+ lic = _resolve_license(license_id, interactive=interactive)
54
+ holder, years = _resolve_holder(lic, author, year, interactive=interactive)
55
+ text = lic.render(holder, years)
56
+
57
+ if str(output) == STDOUT:
58
+ typer.echo(text, nl=False)
59
+ return
60
+ _check_overwrite(output, force=force, interactive=interactive)
61
+ output.write_text(text, encoding="utf-8")
62
+ console.print(f"[green]✓[/] Wrote [bold]{lic.name}[/] to [cyan]{output}[/]")
63
+
64
+
65
+ def is_interactive() -> bool:
66
+ """Whether prompts can be shown."""
67
+ return sys.stdin.isatty() and sys.stdout.isatty()
68
+
69
+
70
+ def default_author() -> str:
71
+ """Best guess at the copyright holder: the git user, else the login name."""
72
+ try:
73
+ result = subprocess.run(
74
+ ["git", "config", "user.name"], # noqa: S607
75
+ capture_output=True,
76
+ check=False,
77
+ text=True,
78
+ timeout=5,
79
+ )
80
+ except (OSError, subprocess.SubprocessError):
81
+ return getpass.getuser()
82
+ return result.stdout.strip() or getpass.getuser()
83
+
84
+
85
+ def _resolve_license(license_id: str | None, *, interactive: bool) -> License:
86
+ if license_id is None:
87
+ if not interactive:
88
+ msg = "no license given; pass an SPDX identifier or run in a terminal (see --list)"
89
+ raise typer.BadParameter(msg, param_hint="LICENSE")
90
+ return prompts.select_license(LICENSES)
91
+ lic = find(license_id)
92
+ if lic is None:
93
+ known = {known.spdx_id.casefold(): known.spdx_id for known in LICENSES}
94
+ close = difflib.get_close_matches(license_id.casefold(), known, n=1, cutoff=0.5)
95
+ hint = f" Did you mean {known[close[0]]}?" if close else " See --list."
96
+ msg = f"unknown license {license_id!r}.{hint}"
97
+ raise typer.BadParameter(msg, param_hint="LICENSE")
98
+ return lic
99
+
100
+
101
+ def _resolve_holder(lic: License, author: str | None, year: str | None, *, interactive: bool) -> tuple[str, str]:
102
+ if not lic.has_holder:
103
+ return "", ""
104
+ default_year = str(datetime.now(UTC).year)
105
+ if interactive:
106
+ author = author or prompts.ask_author(default_author())
107
+ year = year or prompts.ask_year(default_year)
108
+ return author or default_author(), year or default_year
109
+
110
+
111
+ def _check_overwrite(output: Path, *, force: bool, interactive: bool) -> None:
112
+ if force or not output.exists():
113
+ return
114
+ if interactive and prompts.confirm_overwrite(output):
115
+ return
116
+ if interactive:
117
+ raise typer.Abort
118
+ console.print(f"[red]error:[/] {output} already exists, use --force to overwrite")
119
+ raise typer.Exit(1)
120
+
121
+
122
+ def _print_catalogue() -> None:
123
+ table = Table(box=None, pad_edge=False, header_style="bold")
124
+ table.add_column("ID", style="cyan", no_wrap=True)
125
+ table.add_column("Name")
126
+ table.add_column("Summary", style="dim")
127
+ for lic in LICENSES:
128
+ table.add_row(lic.spdx_id, lic.name, lic.summary)
129
+ Console().print(table)
@@ -0,0 +1,14 @@
1
+ BSD Zero Clause License
2
+
3
+ Copyright (c) [year] [fullname]
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any
6
+ purpose with or without fee is hereby granted.
7
+
8
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
9
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
10
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
11
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
12
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
13
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
14
+ PERFORMANCE OF THIS SOFTWARE.