py-arguments 1.0.2__tar.gz → 1.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.
Files changed (31) hide show
  1. {py_arguments-1.0.2 → py_arguments-1.2.0}/.github/workflows/release.yml +1 -1
  2. py_arguments-1.2.0/.github/workflows/unittest.yml +22 -0
  3. py_arguments-1.2.0/.gitignore +36 -0
  4. py_arguments-1.2.0/CHANGELOG.md +45 -0
  5. {py_arguments-1.0.2 → py_arguments-1.2.0}/DEVELOPERS.md +4 -1
  6. py_arguments-1.2.0/LICENSE +7 -0
  7. {py_arguments-1.0.2 → py_arguments-1.2.0}/PKG-INFO +30 -14
  8. {py_arguments-1.0.2 → py_arguments-1.2.0}/README.md +2 -10
  9. {py_arguments-1.0.2 → py_arguments-1.2.0}/hooks/format_commit_message.py +1 -1
  10. {py_arguments-1.0.2 → py_arguments-1.2.0}/pyarg/parser.py +4 -2
  11. py_arguments-1.2.0/pyarg/py.typed +0 -0
  12. py_arguments-1.2.0/pyproject.toml +84 -0
  13. py_arguments-1.2.0/tests/test_parser.py +163 -0
  14. py_arguments-1.0.2/.gitignore +0 -61
  15. py_arguments-1.0.2/CHANGELOG.md +0 -21
  16. py_arguments-1.0.2/py_arguments.egg-info/PKG-INFO +0 -154
  17. py_arguments-1.0.2/py_arguments.egg-info/SOURCES.txt +0 -22
  18. py_arguments-1.0.2/py_arguments.egg-info/dependency_links.txt +0 -1
  19. py_arguments-1.0.2/py_arguments.egg-info/requires.txt +0 -3
  20. py_arguments-1.0.2/py_arguments.egg-info/scm_file_list.json +0 -19
  21. py_arguments-1.0.2/py_arguments.egg-info/scm_version.json +0 -8
  22. py_arguments-1.0.2/py_arguments.egg-info/top_level.txt +0 -1
  23. py_arguments-1.0.2/pyproject.toml +0 -56
  24. py_arguments-1.0.2/setup.cfg +0 -4
  25. {py_arguments-1.0.2 → py_arguments-1.2.0}/.github/workflows/claude-review.yml +0 -0
  26. {py_arguments-1.0.2 → py_arguments-1.2.0}/.github/workflows/pre-commit.yml +0 -0
  27. {py_arguments-1.0.2 → py_arguments-1.2.0}/.github/workflows/publish.yml +0 -0
  28. {py_arguments-1.0.2 → py_arguments-1.2.0}/.pre-commit-config.yaml +0 -0
  29. {py_arguments-1.0.2 → py_arguments-1.2.0}/.releaserc.json +0 -0
  30. {py_arguments-1.0.2 → py_arguments-1.2.0}/Makefile +0 -0
  31. {py_arguments-1.0.2 → py_arguments-1.2.0}/pyarg/__init__.py +0 -0
@@ -24,7 +24,7 @@ jobs:
24
24
  token: ${{ steps.app-token.outputs.token }}
25
25
  - uses: actions/setup-node@v4
26
26
  with:
27
- node-version: 20
27
+ node-version: 22
28
28
  - name: Install semantic-release
29
29
  run: npm install -g semantic-release @semantic-release/git @semantic-release/changelog
30
30
  - name: Release
@@ -0,0 +1,22 @@
1
+ name: Unittest
2
+ on:
3
+ pull_request:
4
+ push:
5
+ branches: [main, develop]
6
+ jobs:
7
+ test:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ python: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
13
+ steps:
14
+ - uses: actions/checkout@v4
15
+ with:
16
+ fetch-depth: 0
17
+ - uses: astral-sh/setup-uv@v6
18
+ with:
19
+ python-version: ${{ matrix.python }}
20
+ activate-environment: true
21
+ - run: uv pip install . pytest
22
+ - run: uv run --no-project pytest
@@ -0,0 +1,36 @@
1
+ # Python.
2
+ *.pyc
3
+ __pycache__/
4
+
5
+ # Distribution / packaging.
6
+ dist/
7
+ build/
8
+ *.egg-info/
9
+
10
+ # Environment.
11
+ *.env*
12
+ *.venv*
13
+ env/
14
+ venv/
15
+
16
+ # Tests.
17
+ .pytest_cache/
18
+ .coverage
19
+ htmlcov/
20
+
21
+ # Ruff.
22
+ .ruff_cache/
23
+
24
+ # MyPy.
25
+ .mypy_cache/
26
+
27
+ # IDEs and code editors.
28
+ .idea/
29
+ .vscode/
30
+
31
+ # OS.
32
+ .DS_Store
33
+
34
+ # Secrets.
35
+ *.pem
36
+ *.key
@@ -0,0 +1,45 @@
1
+ # [1.2.0](https://github.com/SmilingTech/pyarg/compare/v1.1.0...v1.2.0) (2026-11-08)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * Fix name of one of the types of commits. ([2940587](https://github.com/SmilingTech/pyarg/commit/2940587e6719d10c936f5eca7fc00c969324ab9b))
7
+
8
+
9
+ ### Features
10
+
11
+ * Add py.pyted file to specify that the lib is typed. ([80d234b](https://github.com/SmilingTech/pyarg/commit/80d234bb8ad245b54689038389065a350ec76799))
12
+
13
+ # [1.1.0](https://github.com/SmilingTech/pyarg/compare/v1.0.2...v1.1.0) (2026-11-08)
14
+
15
+
16
+ ### Bug Fixes
17
+
18
+ * Run unittest inside of a virtual environment. ([413e129](https://github.com/SmilingTech/pyarg/commit/413e1290a40f459fd5feb66f0f29556036b62dee))
19
+
20
+
21
+ ### Features
22
+
23
+ * Include __future__ annotations to allow old python versions. ([02002e0](https://github.com/SmilingTech/pyarg/commit/02002e04ffe9684056fba9c61836588df6812127))
24
+
25
+ ## [1.0.2](https://github.com/SmilingTech/pyarg/compare/v1.0.1...v1.0.2) (2026-11-08)
26
+
27
+
28
+ ### Bug Fixes
29
+
30
+ * Add missing description to library. ([01bc7b6](https://github.com/SmilingTech/pyarg/commit/01bc7b6c081f6cb88cc913f0382bf93f59668cf1))
31
+
32
+ ## [1.0.1](https://github.com/SmilingTech/pyarg/compare/v1.0.0...v1.0.1) (2026-11-08)
33
+
34
+
35
+ ### Bug Fixes
36
+
37
+ * Accept manual publish via UI. ([1396176](https://github.com/SmilingTech/pyarg/commit/139617633f7d533aaad4923a5016af80c2a9a651))
38
+
39
+ # 1.0.0 (2026-11-08)
40
+
41
+
42
+ ### Features
43
+
44
+ * Add main lib folder and it utilities. ([31bb920](https://github.com/SmilingTech/pyarg/commit/31bb920c5d484b7eb4ad74ef81f94915078be334))
45
+ * Drop all unnecessary files and directories for the project. ([36733f9](https://github.com/SmilingTech/pyarg/commit/36733f9d8085b0fb7e59acd5691c90d4a2bc3ba6))
@@ -15,12 +15,15 @@ $ make setup-local-development # Install all development requirements.
15
15
  ᒪ workflows/
16
16
  ᒪ ... # YAML files to be executed in GitHub workflows.
17
17
  pyarg/ # Main library directory.
18
+ tests/ # Unit tests (pytest).
18
19
  hooks/
19
20
  ᒪ ... # Python scripts to be used as hooks in pre-commit.
20
21
  .gitignore # File with all files and folders to be ignored by Git.
21
22
  .pre-commit-config.yaml # Configuration file to set up local hooks for pre-commit.
22
23
  .releaserc.json # Plugins needed for generate the Release Notes.
24
+ CHANGELOG.md # Generated automatically by semantic-release.
23
25
  DEVELOPERS.md # Documentation for developers.
26
+ LICENSE # MIT license.
24
27
  Makefile # Used to define keywords to execute long commands.
25
28
  pyproject.toml # Main Python configuration file.
26
29
  README.md # Main project documentation.
@@ -29,7 +32,7 @@ README.md # Main project documentation.
29
32
  ### Conventional Commit Message.
30
33
  All projects in this organizations must to use the conventional commit message format based on the following pattern:
31
34
  ```
32
- ^(feat|fix|docs|styles|refactor|test|chore|revert|ci|build|perf): .+$
35
+ ^(feat|fix|docs|style|refactor|test|chore|revert|ci|build|perf): .+$
33
36
  ```
34
37
  |Type|Description|
35
38
  |-|-|
@@ -0,0 +1,7 @@
1
+ Copyright © 2026 SmilingTech
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,10 +1,34 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: py-arguments
3
- Version: 1.0.2
3
+ Version: 1.2.0
4
4
  Summary: Build CLIs with reusable argparse parser classes.
5
- Description-Content-Type: text/markdown
5
+ Project-URL: Homepage, https://github.com/SmilingTech/pyarg
6
+ Project-URL: Repository, https://github.com/SmilingTech/pyarg
7
+ Project-URL: Issues, https://github.com/SmilingTech/pyarg/issues
8
+ Project-URL: Changelog, https://github.com/SmilingTech/pyarg/blob/main/CHANGELOG.md
9
+ Author: Matheus Oliveira de Souza
10
+ License-Expression: MIT
11
+ License-File: LICENSE
12
+ Keywords: argparse,cli,command-line,subcommands
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3 :: Only
18
+ Classifier: Programming Language :: Python :: 3.8
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Programming Language :: Python :: 3.13
24
+ Classifier: Programming Language :: Python :: 3.14
25
+ Classifier: Topic :: Software Development :: Libraries
26
+ Classifier: Typing :: Typed
27
+ Requires-Python: >=3.8
6
28
  Provides-Extra: development
7
- Requires-Dist: pre-commit; extra == "development"
29
+ Requires-Dist: pre-commit; extra == 'development'
30
+ Requires-Dist: pytest; extra == 'development'
31
+ Description-Content-Type: text/markdown
8
32
 
9
33
  # PyArg
10
34
 
@@ -16,17 +40,9 @@ command, without rewriting the arguments.
16
40
  ## Installation
17
41
 
18
42
  ```bash
19
- pip install .
43
+ pip install py-arguments
20
44
  ```
21
45
 
22
- For development (changes apply without reinstalling):
23
-
24
- ```bash
25
- pip install -e .
26
- ```
27
-
28
- Requires Python 3.10+ and has no dependencies.
29
-
30
46
  ## Quick start
31
47
 
32
48
  Create a class that inherits from `PyArg` and define the arguments in `setup_arguments`:
@@ -120,7 +136,7 @@ Use `add_help=False` on the parent parser so the `-h` option is not registered t
120
136
 
121
137
  ## API
122
138
 
123
- ### `PyArg(name, description=None, parents=[], **kwargs)`
139
+ ### `PyArg(name, description=None, parents=None, **kwargs)`
124
140
 
125
141
  Abstract class. It cannot be instantiated directly, you must inherit from it and implement `setup_arguments`.
126
142
 
@@ -8,17 +8,9 @@ command, without rewriting the arguments.
8
8
  ## Installation
9
9
 
10
10
  ```bash
11
- pip install .
11
+ pip install py-arguments
12
12
  ```
13
13
 
14
- For development (changes apply without reinstalling):
15
-
16
- ```bash
17
- pip install -e .
18
- ```
19
-
20
- Requires Python 3.10+ and has no dependencies.
21
-
22
14
  ## Quick start
23
15
 
24
16
  Create a class that inherits from `PyArg` and define the arguments in `setup_arguments`:
@@ -112,7 +104,7 @@ Use `add_help=False` on the parent parser so the `-h` option is not registered t
112
104
 
113
105
  ## API
114
106
 
115
- ### `PyArg(name, description=None, parents=[], **kwargs)`
107
+ ### `PyArg(name, description=None, parents=None, **kwargs)`
116
108
 
117
109
  Abstract class. It cannot be instantiated directly, you must inherit from it and implement `setup_arguments`.
118
110
 
@@ -20,7 +20,7 @@ class CommitTypeEmoji(Enum):
20
20
  FEAT = "🔥"
21
21
  FIX = "🐛"
22
22
  DOCS = "📝"
23
- STYLE = "💄"
23
+ STYLES = "💄"
24
24
  REFACTOR = "✨"
25
25
  TEST = "🔍"
26
26
  CHORE = "⚙️"
@@ -1,3 +1,5 @@
1
+ from __future__ import annotations
2
+
1
3
  import argparse
2
4
  import re
3
5
  from abc import ABC, abstractmethod
@@ -61,7 +63,7 @@ class PyArg(ABC, argparse.ArgumentParser):
61
63
 
62
64
  # Special methods.
63
65
  def __init__(
64
- self, name: str, description: str | None = None, parents: Iterable["PyArg"] | None = None, **kwargs: Any
66
+ self, name: str, description: str | None = None, parents: Iterable[PyArg] | None = None, **kwargs: Any
65
67
  ) -> None:
66
68
  # Remove parameters.
67
69
  for to_remove in ("prog", "description", "parents", "conflict_handler"):
@@ -97,7 +99,7 @@ class PyArg(ABC, argparse.ArgumentParser):
97
99
 
98
100
  # Methods.
99
101
  def add_command_parser(
100
- self, parser: "PyArg", description: str | None = None, script_entrypoint: Callable[..., Any] | None = None
102
+ self, parser: PyArg, description: str | None = None, script_entrypoint: Callable[..., Any] | None = None
101
103
  ) -> None:
102
104
  """Add an extra parser to a parent **PyArg** class to be called by `name`."""
103
105
  if self.__subparser is None:
File without changes
@@ -0,0 +1,84 @@
1
+ # Build system.
2
+ [build-system]
3
+ requires = ["hatchling>=1.27", "hatch-vcs"]
4
+ build-backend = "hatchling.build"
5
+
6
+ # Project metadata.
7
+ [project]
8
+ name = "py-arguments"
9
+ description = "Build CLIs with reusable argparse parser classes."
10
+ requires-python = ">=3.8"
11
+ readme = "README.md"
12
+ license = "MIT"
13
+ license-files = ["LICENSE"]
14
+ authors = [{ name = "Matheus Oliveira de Souza" }]
15
+ dynamic = ["version"]
16
+ keywords = ["argparse", "cli", "command-line", "subcommands"]
17
+ classifiers = [
18
+ "Development Status :: 4 - Beta",
19
+ "Intended Audience :: Developers",
20
+ "Operating System :: OS Independent",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3 :: Only",
23
+ "Programming Language :: Python :: 3.8",
24
+ "Programming Language :: Python :: 3.9",
25
+ "Programming Language :: Python :: 3.10",
26
+ "Programming Language :: Python :: 3.11",
27
+ "Programming Language :: Python :: 3.12",
28
+ "Programming Language :: Python :: 3.13",
29
+ "Programming Language :: Python :: 3.14",
30
+ "Topic :: Software Development :: Libraries",
31
+ "Typing :: Typed",
32
+ ]
33
+ dependencies = []
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/SmilingTech/pyarg"
37
+ Repository = "https://github.com/SmilingTech/pyarg"
38
+ Issues = "https://github.com/SmilingTech/pyarg/issues"
39
+ Changelog = "https://github.com/SmilingTech/pyarg/blob/main/CHANGELOG.md"
40
+
41
+ # Dependencies.
42
+ [project.optional-dependencies]
43
+ development = [
44
+ "pre-commit",
45
+ "pytest"
46
+ ]
47
+
48
+ [tool.hatch.build.targets.wheel]
49
+ packages = ["pyarg"]
50
+
51
+ # Version comes from the git tag created by semantic-release.
52
+ [tool.hatch.version]
53
+ source = "vcs"
54
+
55
+ # Ruff.
56
+ [tool.ruff]
57
+ target-version = "py38"
58
+ line-length = 120
59
+
60
+ [tool.ruff.lint]
61
+ select = [
62
+ "E", # All pycodestyle errors
63
+ "F", # Pyflakes
64
+ "I", # All isort errors
65
+ "B", # All flake8-bugbear errors
66
+ "C4", # flake8-comprehensions
67
+ "UP", # All pyupgrade errors
68
+ "SIM", # flake8-simplify
69
+ ]
70
+
71
+ [tool.ruff.format]
72
+ quote-style = "double"
73
+ indent-style = "space"
74
+ line-ending = "auto"
75
+
76
+ # Mypy.
77
+ [tool.mypy]
78
+ python_version = "3.8"
79
+ mypy_path = "."
80
+ strict = true
81
+ ignore_missing_imports = true
82
+ explicit_package_bases = true
83
+ disallow_untyped_decorators = false
84
+ disallow_subclassing_any = false
@@ -0,0 +1,163 @@
1
+ """Tests for the PyArg class."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import sys
6
+ from typing import Any
7
+
8
+ import pytest
9
+
10
+ from pyarg import PyArg
11
+
12
+
13
+ # Helpers.
14
+ class Login(PyArg):
15
+ def setup_arguments(self) -> None:
16
+ self.add_argument("--username", "-u")
17
+ self.add_argument("--password", "-p")
18
+
19
+
20
+ class Logout(PyArg):
21
+ def setup_arguments(self) -> None:
22
+ self.add_argument("--all", action="store_true")
23
+
24
+
25
+ class Common(PyArg):
26
+ def setup_arguments(self) -> None:
27
+ self.add_argument("--verbose", "-v", action="store_true")
28
+
29
+
30
+ class App(PyArg):
31
+ def setup_arguments(self) -> None:
32
+ pass
33
+
34
+
35
+ @pytest.fixture
36
+ def argv(monkeypatch: pytest.MonkeyPatch) -> Any:
37
+ """Set `sys.argv` as if the CLI had been called with the given arguments."""
38
+
39
+ def _set(*args: str) -> None:
40
+ monkeypatch.setattr(sys, "argv", ["prog", *args])
41
+
42
+ return _set
43
+
44
+
45
+ @pytest.fixture
46
+ def app() -> App:
47
+ app = App(name="My App", description="Test application.")
48
+ app.add_command_parser(Login(name="Login", description="Sign in."))
49
+ app.add_command_parser(Logout(name="Logout"), description="Sign out.")
50
+ return app
51
+
52
+
53
+ # Instantiation.
54
+ def test_cannot_instantiate_abstract_class() -> None:
55
+ with pytest.raises(TypeError):
56
+ PyArg(name="Abstract") # type: ignore[abstract]
57
+
58
+
59
+ def test_setup_arguments_is_called_on_init() -> None:
60
+ parser = Login(name="Login")
61
+ destinations = {action.dest for action in parser._actions}
62
+ assert {"username", "password"} <= destinations
63
+
64
+
65
+ @pytest.mark.parametrize(
66
+ ("name", "expected"),
67
+ [
68
+ ("Login", "login"),
69
+ ("Make Directory", "make-directory"),
70
+ (" Spaced Out ", "spaced-out"),
71
+ ],
72
+ )
73
+ def test_command_name(name: str, expected: str) -> None:
74
+ assert Login(name=name).command_name == expected
75
+
76
+
77
+ def test_reserved_kwargs_are_ignored() -> None:
78
+ parser = Login(name="Login", prog="other", conflict_handler="error")
79
+ assert parser.prog == "Login"
80
+ assert parser.conflict_handler == "resolve"
81
+
82
+
83
+ # Parsing.
84
+ def test_get_arguments_without_args(argv: Any) -> None:
85
+ argv()
86
+ assert App(name="App").get_arguments() == {}
87
+
88
+
89
+ def test_get_arguments_simple_parser(argv: Any) -> None:
90
+ argv("-u", "ana", "--password", "123")
91
+ assert Login(name="Login").get_arguments() == {"username": "ana", "password": "123"}
92
+
93
+
94
+ def test_unknown_argument_exits(argv: Any) -> None:
95
+ argv("--nope")
96
+ with pytest.raises(SystemExit) as error:
97
+ Login(name="Login").get_arguments()
98
+ assert error.value.code == 2
99
+
100
+
101
+ # Sub-commands.
102
+ def test_command_login(app: App, argv: Any) -> None:
103
+ argv("login", "-u", "ana", "-p", "123")
104
+ assert app.get_arguments() == {"command": "login", "username": "ana", "password": "123"}
105
+
106
+
107
+ def test_command_logout(app: App, argv: Any) -> None:
108
+ argv("logout", "--all")
109
+ assert app.get_arguments() == {"command": "logout", "all": True}
110
+
111
+
112
+ def test_no_command_selected(app: App, argv: Any) -> None:
113
+ argv()
114
+ assert app.get_arguments() == {"command": None}
115
+
116
+
117
+ def test_unknown_command_exits(app: App, argv: Any) -> None:
118
+ argv("signup")
119
+ with pytest.raises(SystemExit):
120
+ app.get_arguments()
121
+
122
+
123
+ def test_command_help_has_no_conflict(app: App, argv: Any, capsys: pytest.CaptureFixture[str]) -> None:
124
+ argv("login", "-h")
125
+ with pytest.raises(SystemExit) as error:
126
+ app.get_arguments()
127
+ assert error.value.code == 0
128
+ assert "--username" in capsys.readouterr().out
129
+
130
+
131
+ def test_main_help_lists_commands(app: App, argv: Any, capsys: pytest.CaptureFixture[str]) -> None:
132
+ argv("-h")
133
+ with pytest.raises(SystemExit):
134
+ app.get_arguments()
135
+ output = capsys.readouterr().out
136
+ assert "login" in output
137
+ assert "logout" in output
138
+
139
+
140
+ def test_command_description(app: App, argv: Any, capsys: pytest.CaptureFixture[str]) -> None:
141
+ for command, description in (("login", "Sign in."), ("logout", "Sign out.")):
142
+ argv(command, "-h")
143
+ with pytest.raises(SystemExit):
144
+ app.get_arguments()
145
+ assert description in capsys.readouterr().out
146
+
147
+
148
+ def test_entrypoint_is_not_returned(argv: Any) -> None:
149
+ app = App(name="App")
150
+ app.add_command_parser(Logout(name="Logout"), script_entrypoint=lambda **_: None)
151
+ argv("logout")
152
+ assert app.get_arguments() == {"command": "logout", "all": False}
153
+
154
+
155
+ # Parents.
156
+ def test_parents_reuse_arguments(argv: Any) -> None:
157
+ parser = Login(name="Login", parents=[Common(name="Common", add_help=False)])
158
+ argv("-v", "-u", "ana")
159
+ assert parser.get_arguments() == {"verbose": True, "username": "ana", "password": None}
160
+
161
+
162
+ def test_parents_with_help_do_not_conflict() -> None:
163
+ Login(name="Login", parents=[Common(name="Common")])
@@ -1,61 +0,0 @@
1
- # Python.
2
- *.pyc
3
- __pycache__/
4
-
5
- # Distribution / packaging.
6
- dist/
7
- build/
8
- *.egg-info/
9
-
10
- # Node.
11
- node_modules/
12
- npm-debug.*
13
- yarn-debug.*
14
- yarn-error.*
15
- pnpm-debug.log*
16
- lerna-debug.log*
17
- *.log
18
- logs
19
-
20
- # Vite.
21
- dist-ssr
22
- *.local
23
-
24
- # Expo / React Native.
25
- .expo/
26
- web-build/
27
- expo-env.d.ts
28
- .metro-health-check*
29
-
30
- # Native (iOS/Android).
31
- .kotlin/
32
- /ios
33
- /android
34
- *.jks
35
- *.p8
36
- *.p12
37
- *.key
38
- *.mobileprovision
39
-
40
- # TypeScript.
41
- *.tsbuildinfo
42
-
43
- # Environment.
44
- *.env*
45
- *.venv*
46
- env/
47
- venv/
48
-
49
- # Ruff.
50
- .ruff_cache/
51
-
52
- # MyPy.
53
- .mypy_cache/
54
-
55
- # IDEs and code editors.
56
- .idea/
57
- .vscode/
58
-
59
- # macOS.
60
- .DS_Store
61
- *.pem
@@ -1,21 +0,0 @@
1
- ## [1.0.2](https://github.com/SmilingTech/pyarg/compare/v1.0.1...v1.0.2) (2026-11-08)
2
-
3
-
4
- ### Bug Fixes
5
-
6
- * Add missing description to library. ([01bc7b6](https://github.com/SmilingTech/pyarg/commit/01bc7b6c081f6cb88cc913f0382bf93f59668cf1))
7
-
8
- ## [1.0.1](https://github.com/SmilingTech/pyarg/compare/v1.0.0...v1.0.1) (2026-11-08)
9
-
10
-
11
- ### Bug Fixes
12
-
13
- * Accept manual publish via UI. ([1396176](https://github.com/SmilingTech/pyarg/commit/139617633f7d533aaad4923a5016af80c2a9a651))
14
-
15
- # 1.0.0 (2026-11-08)
16
-
17
-
18
- ### Features
19
-
20
- * Add main lib folder and it utilities. ([31bb920](https://github.com/SmilingTech/pyarg/commit/31bb920c5d484b7eb4ad74ef81f94915078be334))
21
- * Drop all unnecessary files and directories for the project. ([36733f9](https://github.com/SmilingTech/pyarg/commit/36733f9d8085b0fb7e59acd5691c90d4a2bc3ba6))
@@ -1,154 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: py-arguments
3
- Version: 1.0.2
4
- Summary: Build CLIs with reusable argparse parser classes.
5
- Description-Content-Type: text/markdown
6
- Provides-Extra: development
7
- Requires-Dist: pre-commit; extra == "development"
8
-
9
- # PyArg
10
-
11
- A small layer on top of `argparse` to build CLIs with sub-commands by **reusing parser classes**.
12
-
13
- Each parser is a class. You define its arguments in one method, and then plug that class into another parser as a
14
- command, without rewriting the arguments.
15
-
16
- ## Installation
17
-
18
- ```bash
19
- pip install .
20
- ```
21
-
22
- For development (changes apply without reinstalling):
23
-
24
- ```bash
25
- pip install -e .
26
- ```
27
-
28
- Requires Python 3.10+ and has no dependencies.
29
-
30
- ## Quick start
31
-
32
- Create a class that inherits from `PyArg` and define the arguments in `setup_arguments`:
33
-
34
- ```python
35
- from pyarg import PyArg
36
-
37
-
38
- class Login(PyArg):
39
- def setup_arguments(self) -> None:
40
- self.add_argument("--username", "-u")
41
- self.add_argument("--password", "-p")
42
-
43
-
44
- parser = Login(name="Login")
45
- print(parser.get_arguments())
46
- ```
47
-
48
- ```console
49
- $ python main.py -u ana -p 123
50
- {'username': 'ana', 'password': '123'}
51
- ```
52
-
53
- Since `PyArg` inherits from `argparse.ArgumentParser`, everything from `argparse` still works
54
- (`add_argument`, `add_mutually_exclusive_group`, `type`, `nargs`, `choices`, etc.).
55
-
56
- ## Sub-commands
57
-
58
- Use `add_command_parser` to attach parsers to a main one. Each command is named after the parser `name`, converted to
59
- lowercase with spaces replaced by `-` (`"Make Directory"` becomes `make-directory`).
60
-
61
- ```python
62
- from pyarg import PyArg
63
-
64
-
65
- class Login(PyArg):
66
- def setup_arguments(self) -> None:
67
- self.add_argument("--username", "-u")
68
- self.add_argument("--password", "-p")
69
-
70
-
71
- class Logout(PyArg):
72
- def setup_arguments(self) -> None:
73
- self.add_argument("--all", action="store_true")
74
-
75
-
76
- class App(PyArg):
77
- def setup_arguments(self) -> None:
78
- pass # The main parser can have its own arguments too.
79
-
80
-
81
- app = App(name="My App", description="Demo app.")
82
- app.add_command_parser(Login(name="Login", description="Sign in."))
83
- app.add_command_parser(Logout(name="Logout"), description="Sign out.")
84
-
85
- print(app.get_arguments())
86
- ```
87
-
88
- ```console
89
- $ python main.py login -u ana -p 123
90
- {'command': 'login', 'username': 'ana', 'password': '123'}
91
-
92
- $ python main.py logout --all
93
- {'command': 'logout', 'all': True}
94
-
95
- $ python main.py -h
96
- usage: My App [-h] {login,logout} ...
97
- ```
98
-
99
- The chosen command is available under the `command` key.
100
-
101
- ## Reusing arguments
102
-
103
- Arguments from other parsers can be inherited with `parents`:
104
-
105
- ```python
106
- class Common(PyArg):
107
- def setup_arguments(self) -> None:
108
- self.add_argument("--verbose", "-v", action="store_true")
109
-
110
-
111
- class Build(PyArg):
112
- def setup_arguments(self) -> None:
113
- self.add_argument("--target")
114
-
115
-
116
- build = Build(name="Build", parents=[Common(name="Common", add_help=False)])
117
- ```
118
-
119
- Use `add_help=False` on the parent parser so the `-h` option is not registered twice.
120
-
121
- ## API
122
-
123
- ### `PyArg(name, description=None, parents=[], **kwargs)`
124
-
125
- Abstract class. It cannot be instantiated directly, you must inherit from it and implement `setup_arguments`.
126
-
127
- - `name`: parser name. Used as `prog` in the help text and to build the command name.
128
- - `description`: text shown in `-h`.
129
- - `parents`: other parsers whose arguments are copied into this one.
130
- - `**kwargs`: forwarded to `argparse.ArgumentParser`. The `prog`, `description`, `parents` and `conflict_handler`
131
- keys are ignored, as `conflict_handler` is always `"resolve"`.
132
-
133
- ### `setup_arguments(self) -> None`
134
-
135
- Abstract method. Define all the arguments of the parser here. It runs at the end of `__init__`.
136
-
137
- ### `command_name`
138
-
139
- Read-only property with the command name derived from `name`.
140
-
141
- ### `add_command_parser(parser, description=None, script_entrypoint=None)`
142
-
143
- Adds `parser` as a sub-command. If `description` is not set, the parser's own description is used.
144
-
145
- `script_entrypoint` stores a callable on the command, but `get_arguments` does not call it and removes it from the
146
- result.
147
-
148
- ### `get_arguments() -> dict[str, Any]`
149
-
150
- Parses `sys.argv` and returns the arguments passed by the user as a dictionary.
151
-
152
- ## Development
153
-
154
- See [DEVELOPERS.md](DEVELOPERS.md).
@@ -1,22 +0,0 @@
1
- .gitignore
2
- .pre-commit-config.yaml
3
- .releaserc.json
4
- CHANGELOG.md
5
- DEVELOPERS.md
6
- Makefile
7
- README.md
8
- pyproject.toml
9
- .github/workflows/claude-review.yml
10
- .github/workflows/pre-commit.yml
11
- .github/workflows/publish.yml
12
- .github/workflows/release.yml
13
- hooks/format_commit_message.py
14
- py_arguments.egg-info/PKG-INFO
15
- py_arguments.egg-info/SOURCES.txt
16
- py_arguments.egg-info/dependency_links.txt
17
- py_arguments.egg-info/requires.txt
18
- py_arguments.egg-info/scm_file_list.json
19
- py_arguments.egg-info/scm_version.json
20
- py_arguments.egg-info/top_level.txt
21
- pyarg/__init__.py
22
- pyarg/parser.py
@@ -1,3 +0,0 @@
1
-
2
- [development]
3
- pre-commit
@@ -1,19 +0,0 @@
1
- {
2
- "files": [
3
- ".github/workflows/claude-review.yml",
4
- ".github/workflows/pre-commit.yml",
5
- ".github/workflows/publish.yml",
6
- ".github/workflows/release.yml",
7
- ".gitignore",
8
- ".pre-commit-config.yaml",
9
- ".releaserc.json",
10
- "CHANGELOG.md",
11
- "DEVELOPERS.md",
12
- "Makefile",
13
- "README.md",
14
- "hooks/format_commit_message.py",
15
- "pyarg/__init__.py",
16
- "pyarg/parser.py",
17
- "pyproject.toml"
18
- ]
19
- }
@@ -1,8 +0,0 @@
1
- {
2
- "tag": "1.0.2",
3
- "distance": 0,
4
- "node": "g188e175e1929f43573713af4d0d686047dd1bea7",
5
- "dirty": false,
6
- "branch": "HEAD",
7
- "node_date": "2026-11-08"
8
- }
@@ -1 +0,0 @@
1
- pyarg
@@ -1,56 +0,0 @@
1
- # Build system.
2
- [build-system]
3
- requires = ["setuptools>=64", "setuptools-scm>=8"]
4
- build-backend = "setuptools.build_meta"
5
-
6
- # Project metadata.
7
- [project]
8
- name = "py-arguments"
9
- description = "Build CLIs with reusable argparse parser classes."
10
- readme = "README.md"
11
- authors = []
12
- dynamic = ["version"]
13
- dependencies = []
14
-
15
- # Dependencies.
16
- [project.optional-dependencies]
17
- development = [
18
- "pre-commit"
19
- ]
20
-
21
- [tool.setuptools]
22
- packages = ["pyarg"]
23
-
24
- # Version comes from the git tag created by semantic-release.
25
- [tool.setuptools_scm]
26
-
27
- # Ruff.
28
- [tool.ruff]
29
- line-length = 120
30
-
31
- [tool.ruff.lint]
32
- select = [
33
- "E", # All pycodestyle errors
34
- "F", # Pyflakes
35
- "I", # All isort errors
36
- "B", # All flake8-bugbear errors
37
- "C4", # flake8-comprehensions
38
- "UP", # All pyupgrade errors
39
- "SIM", # flake8-simplify
40
- ]
41
- ignore = ["B008"] # Valid for FastAPI `Depends` call.
42
-
43
- [tool.ruff.format]
44
- quote-style = "double"
45
- indent-style = "space"
46
- line-ending = "auto"
47
-
48
- # Mypy.
49
- [tool.mypy]
50
- mypy_path = "."
51
- strict = true
52
- ignore_missing_imports = true
53
- explicit_package_bases = true
54
- disallow_untyped_decorators = false
55
- disallow_subclassing_any = false
56
- plugins = ["pydantic.mypy"]
@@ -1,4 +0,0 @@
1
- [egg_info]
2
- tag_build =
3
- tag_date = 0
4
-
File without changes