Skip to content

Commit 2b012f5

Browse files
authored
refactor!: click -> argparse (#400)
click is an additional dependency, introduces complicated bugs, sphinx-click is difficult to place commands into document sections. On the other hand, argparse is stable, battle-tested, predictable.
2 parents 11a3a01 + 9f36207 commit 2b012f5

File tree

11 files changed

+303
-308
lines changed

11 files changed

+303
-308
lines changed

CHANGES

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,18 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force
1919

2020
- _Add your latest changes from PRs here_
2121

22+
**Maintenance release, no features or fixes**
23+
24+
### Internal
25+
26+
- Move from click to :mod:{argparse}
27+
28+
Click was more difficult to control and workwith, ironically.
29+
30+
### Packaging
31+
32+
- Drop click dependency (#400)
33+
2234
## vcspull v1.14.0 (2022-10-01)
2335

2436
**Maintenance release, no features or fixes**
@@ -230,7 +242,7 @@ Patch branch: [`v1.12.x`](https://github.com/vcs-python/vcspull/tree/v1.12.x)
230242

231243
### Fix
232244

233-
- Tab-completion for repository names and configurations
245+
- Tab-completion for repository names and configurations (retracted in v1.15)
234246

235247
## vcspull 1.11.1 (2022-03-12)
236248

@@ -272,7 +284,7 @@ Patch branch: [`v1.12.x`](https://github.com/vcs-python/vcspull/tree/v1.12.x)
272284

273285
### Improvements
274286

275-
- Experimental completion, see {ref}`completion`:
287+
- Experimental completion (retracted in v1.15):
276288

277289
- Completion for sync:
278290

@@ -281,7 +293,7 @@ Patch branch: [`v1.12.x`](https://github.com/vcs-python/vcspull/tree/v1.12.x)
281293

282294
### Documentation
283295

284-
- Added {ref}`completion`:
296+
- Added completion:
285297

286298
## vcspull 1.9.0 (2022-02-26)
287299

docs/cli/completion.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

docs/cli/index.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,3 @@ vcspull
1414
1515
sync
1616
```
17-
18-
```{toctree}
19-
:caption: More
20-
:maxdepth: 1
21-
22-
completion
23-
```

docs/cli/sync.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@
44

55
# vcspull sync
66

7+
## Command
8+
9+
```{eval-rst}
10+
.. argparse::
11+
:module: vcspull.cli
12+
:func: create_parser
13+
:prog: vcspull
14+
:path: sync
15+
```
16+
717
## Filtering repos
818

919
As of 1.13.x, `$ vcspull sync` with no args passed will show a help dialog:
@@ -80,10 +90,3 @@ Print traceback for errored repos:
8090
```console
8191
$ vcspull --log-level DEBUG sync --exit-on-error grako django
8292
```
83-
84-
```{eval-rst}
85-
.. click:: vcspull.cli.sync:sync
86-
:prog: vcspull sync
87-
:commands: sync
88-
:nested: full
89-
```

docs/cli/vcspull.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
# vcspull
66

77
```{eval-rst}
8-
.. click:: vcspull.cli:cli
9-
:prog: Usage
10-
:nested: none
8+
.. argparse::
9+
:module: vcspull.cli
10+
:func: create_parser
11+
:prog: vcspull
12+
:nosubcommands:
13+
14+
subparser_name : @replace
15+
See :ref:`cli-sync`
1116
```

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"sphinx.ext.todo",
2424
"sphinx.ext.napoleon",
2525
"sphinx.ext.linkcode",
26-
"sphinx_click.ext", # sphinx-click
26+
"sphinxarg.ext", # sphinx-argparse
2727
"sphinx_inline_tabs",
2828
"sphinx_copybutton",
2929
"sphinxext.opengraph",

poetry.lock

Lines changed: 20 additions & 19 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ vcspull = 'vcspull:cli.cli'
5959

6060
[tool.poetry.dependencies]
6161
python = "^3.9"
62-
click = "~8"
6362
libvcs = "~0.17.0"
6463
colorama = ">=0.3.9"
6564

@@ -70,7 +69,6 @@ furo = "*"
7069
gp-libs = "0.0.1a16"
7170
sphinx-autobuild = "*"
7271
sphinx-autodoc-typehints = "*"
73-
sphinx-click = "*"
7472
sphinx-inline-tabs = "*"
7573
sphinxext-opengraph = "*"
7674
sphinx-copybutton = "*"
@@ -105,7 +103,6 @@ types-colorama = "*"
105103
[tool.poetry.extras]
106104
docs = [
107105
"sphinx",
108-
"sphinx-click",
109106
"sphinx-autodoc-typehints",
110107
"sphinx-autobuild",
111108
"sphinxext-rediraffe",
@@ -129,6 +126,9 @@ lint = [
129126
"types-colorama",
130127
]
131128

129+
[tool.poetry.group.dev.dependencies]
130+
sphinx-argparse = "^0.3.1"
131+
132132
[tool.mypy]
133133
python_version = 3.9
134134
warn_unused_configs = true

src/vcspull/cli/__init__.py

Lines changed: 39 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,52 @@
44
~~~~~~~~~~~
55
66
"""
7+
import argparse
78
import logging
89

9-
import click
10-
1110
from libvcs.__about__ import __version__ as libvcs_version
1211

1312
from ..__about__ import __version__
1413
from ..log import setup_logger
15-
from .sync import sync
14+
from .sync import create_sync_subparser, sync
1615

1716
log = logging.getLogger(__name__)
1817

1918

20-
@click.group(
21-
context_settings={
22-
"obj": {},
23-
"help_option_names": ["-h", "--help"],
24-
}
25-
)
26-
@click.option(
27-
"--log-level",
28-
default="INFO",
29-
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
30-
)
31-
@click.version_option(
32-
__version__,
33-
"-V",
34-
"--version",
35-
message=f"%(prog)s %(version)s, libvcs {libvcs_version}",
36-
)
37-
def cli(log_level):
38-
setup_logger(log=log, level=log_level.upper())
39-
40-
41-
# Register sub-commands here
42-
cli.add_command(sync)
19+
def create_parser():
20+
parser = argparse.ArgumentParser(prog="vcspull")
21+
parser.add_argument(
22+
"--version",
23+
"-V",
24+
action="version",
25+
version=f"%(prog)s {__version__}, libvcs {libvcs_version}",
26+
)
27+
parser.add_argument(
28+
"--log-level",
29+
action="store",
30+
default="INFO",
31+
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
32+
)
33+
subparsers = parser.add_subparsers(dest="subparser_name")
34+
sync_parser = subparsers.add_parser("sync")
35+
create_sync_subparser(sync_parser)
36+
37+
return parser
38+
39+
40+
def cli(args=None):
41+
parser = create_parser()
42+
args = parser.parse_args(args)
43+
44+
setup_logger(log=log, level=args.log_level.upper())
45+
46+
if args.subparser_name is None:
47+
parser.print_help()
48+
return
49+
elif args.subparser_name == "sync":
50+
sync(
51+
repo_terms=args.repo_terms,
52+
config=args.config,
53+
exit_on_error=args.exit_on_error,
54+
parser=parser,
55+
)

0 commit comments

Comments
 (0)