From 484faf1fd93d96e467d8093d26190c34bd20bb5a Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Tue, 31 Dec 2019 18:40:17 +0100 Subject: [PATCH] Drop the click dependency This reduces the number of external dependencies and relies more on Python's standard library. It drops the --no-push option since argparse doesn't support having a --option / --no-option. That's also the default and this makes it clearer to the user what the default is. The help text's formatting is slightly different. Mostly visible are that the description and epilog are no longer indented. --- PyGitUp/gitup.py | 43 ++++++++++++++++++++----------------------- poetry.lock | 16 ---------------- pyproject.toml | 1 - 3 files changed, 20 insertions(+), 40 deletions(-) diff --git a/PyGitUp/gitup.py b/PyGitUp/gitup.py index a5d4748..c86b3e9 100644 --- a/PyGitUp/gitup.py +++ b/PyGitUp/gitup.py @@ -8,6 +8,7 @@ ############################################################################### # Python libs +import argparse import codecs import errno import sys @@ -29,7 +30,6 @@ else: # pragma: no cover NO_DISTRIBUTE = False -import click import colorama from git import Repo, GitCmdObjectDB from termcolor import colored @@ -534,21 +534,24 @@ def print_error(self, error): ''' -@click.command(epilog=EPILOG) -@click.option('-V', '--version', is_flag=True, - help='Show version (and if there is a newer version).') -@click.option('-q', '--quiet', is_flag=True, - help='Be quiet, only print error messages.') -@click.option('--no-fetch', '--no-f', is_flag=True, - help='Don\'t try to fetch from origin.') -@click.option('-p', '--push/--no-push', default=None, - help='Push the changes after pulling successfully.') -@click.help_option('-h', '--help') -def run(version, quiet, no_fetch, push, **kwargs): # pragma: no cover +def run(): # pragma: no cover """ A nicer `git pull`. """ - if version: + + parser = argparse.ArgumentParser(description="A nicer `git pull`.", epilog=EPILOG) + parser.add_argument('-V', '--version', action='store_true', + help='Show version (and if there is a newer version).') + parser.add_argument('-q', '--quiet', action='store_true', + help='Be quiet, only print error messages.') + parser.add_argument('--no-fetch', '--no-f', dest='fetch', action='store_false', + help='Don\'t try to fetch from origin.') + parser.add_argument('-p', '--push', action='store_true', + help='Push the changes after pulling successfully.') + + args = parser.parse_args() + + if args.version: if NO_DISTRIBUTE: print(colored('Please install \'git-up\' via pip in order to ' 'get version information.', 'yellow')) @@ -556,19 +559,13 @@ def run(version, quiet, no_fetch, push, **kwargs): # pragma: no cover GitUp(sparse=True).version_info() return - if quiet: + if args.quiet: sys.stdout = StringIO() try: gitup = GitUp() - - if push is not None: - gitup.settings['push.auto'] = push - - # if arguments['--no-fetch'] or arguments['--no-f']: - if no_fetch: - gitup.should_fetch = False - + gitup.settings['push.auto'] = args.push + gitup.should_fetch = args.fetch except GitError: sys.exit(1) # Error in constructor else: @@ -576,4 +573,4 @@ def run(version, quiet, no_fetch, push, **kwargs): # pragma: no cover if __name__ == '__main__': # pragma: no cover - run(help_option_names=['-h']) + run() diff --git a/poetry.lock b/poetry.lock index 70bfc85..a493b71 100644 --- a/poetry.lock +++ b/poetry.lock @@ -63,18 +63,6 @@ python-versions = ">=3.5.0" [package.extras] unicode_backport = ["unicodedata2"] -[[package]] -name = "click" -version = "8.0.1" -description = "Composable command line interface toolkit" -category = "main" -optional = false -python-versions = ">=3.6" - -[package.dependencies] -colorama = {version = "*", markers = "platform_system == \"Windows\""} -importlib-metadata = {version = "*", markers = "python_version < \"3.8\""} - [[package]] name = "colorama" version = "0.4.4" @@ -596,10 +584,6 @@ charset-normalizer = [ {file = "charset-normalizer-2.0.6.tar.gz", hash = "sha256:5ec46d183433dcbd0ab716f2d7f29d8dee50505b3fdb40c6b985c7c4f5a3591f"}, {file = "charset_normalizer-2.0.6-py3-none-any.whl", hash = "sha256:5d209c0a931f215cee683b6445e2d77677e7e75e159f78def0db09d68fafcaa6"}, ] -click = [ - {file = "click-8.0.1-py3-none-any.whl", hash = "sha256:fba402a4a47334742d782209a7c79bc448911afe1149d07bdabdf480b3e2f4b6"}, - {file = "click-8.0.1.tar.gz", hash = "sha256:8c04c11192119b1ef78ea049e0a6f0463e4c48ef00a30160c704337586f3ad7a"}, -] colorama = [ {file = "colorama-0.4.4-py2.py3-none-any.whl", hash = "sha256:9f47eda37229f68eee03b24b9748937c7dc3868f906e8ba69fbcbdd3bc5dc3e2"}, {file = "colorama-0.4.4.tar.gz", hash = "sha256:5941b2b48a20143d2267e95b1c2a7603ce057ee39fd88e7329b0c292aa16869b"}, diff --git a/pyproject.toml b/pyproject.toml index dafe0dd..f2185cf 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,7 +29,6 @@ classifiers = [ [tool.poetry.dependencies] python = "^3.7" GitPython = "^3.0.0" -click = "^8.0" colorama = "^0.4.0" termcolor = "^1.1.0"