From 4a73e6c234f33d8a4dafcd7f84a77f7d43c6564a Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Mon, 31 May 2021 13:28:27 +0530 Subject: [PATCH 01/12] cleanup __main__.py Printing help message when no args are passed on CLI. WIP making it usable for .py scripts --- src/gitcomp/__main__.py | 56 ++++++++++++++++++++--------------------- src/gitcomp/ser_de.py | 2 +- 2 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/gitcomp/__main__.py b/src/gitcomp/__main__.py index 4a1be9b..4fa9042 100644 --- a/src/gitcomp/__main__.py +++ b/src/gitcomp/__main__.py @@ -15,70 +15,70 @@ def __get_arg_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser(description=''' gitcomp A CLI utility to compare the vital stats of GitHub repositories - ''') + ''', formatter_class=argparse.RawTextHelpFormatter) mutually_exclusive = parser.add_mutually_exclusive_group() mutually_exclusive.add_argument('-u', '--user', type=str, nargs='+', metavar='user_name', default=None, dest='user_names', help=''' - -u, --user \n - The GitHub username(s) to query against.\n + -u, --user + The GitHub username(s) to query against. Multiple usernames can be queried at a time by providing a space separated - argument list.\n + argument list. ''') mutually_exclusive.add_argument('-r', '--repo', type=str, nargs='+', metavar='repo', default=None, dest='repo_names', help=''' - -r, --repo \n - The public GitHub repository to query against where repo takes the form:\n - .\n - Example: -r octocat/Spoon-Knife\n + -r, --repo + The public GitHub repository to query against where repo takes the form: + . + Example: -r octocat/Spoon-Knife ''') parser.add_argument('-t', '--type', type=str, nargs=1, choices=['json', 'csv', 'ascii', 'html'], metavar='output_t', default=['ascii'], dest='out_type', help=''' - -t, --type \n - Default: ascii\n + -t, --type + Default: ascii Choose the format of output. All output is dumped to STDOUT unless output file - is specified using -o, --output flag.\n - The types available are:\n - json: Show the result as JSON.\n - csv: Show the output as csv.\n - ascii: Show the result as an ASCII table.\n - html: Show output as HTML table.\n + is specified using -o, --output flag. + The types available are: + json: Show the result as JSON. + csv: Show the output as csv. + ascii: Show the result as an ASCII table. + html: Show output as HTML table. ''') - parser.add_argument('-o', '--output', type=str, nargs=1, metavar='out', dest='output_file', + parser.add_argument('-o', '--output', type=str, nargs=1, default=[None], metavar='out', dest='output_file', help=''' - -o, --output \n - Output to out_file, defaults to STDOUT.\n + -o, --output + Output to out_file, defaults to STDOUT. ''' ) return parser +def safe_exit(parser: argparse.ArgumentParser): + parser.print_help() + exit(2) + + def main(): arg_parser = __get_arg_parser() args = arg_parser.parse_args() + if args.user_names is None and args.repo_names is None: + safe_exit(arg_parser) g = GitComp(users=args.user_names, repos=args.repo_names) - # TODO cleanup - # start cleanup prop = None - tp = None - out = None if args.user_names is not None: prop = PROP['users'].value elif args.repo_names is not None: prop = PROP['repos'].value - if args.out_type is not None: - tp = args.out_type[0] - if args.output_file is not None: - out = args.output_file[0] - # end cleanup + tp = args.out_type[0] + out = args.output_file[0] w = Writer(obj=g, out_type=tp, out_file=out, prop=prop) w.write() diff --git a/src/gitcomp/ser_de.py b/src/gitcomp/ser_de.py index 5c4edad..afc4458 100644 --- a/src/gitcomp/ser_de.py +++ b/src/gitcomp/ser_de.py @@ -44,7 +44,7 @@ class Writer: display_rows: List[str] __ascii_threshold = 4 - def __init__(self, prop, obj, out_type, out_file): + def __init__(self, prop, obj, out_type, out_file=None): self.obj = obj self.prop = prop self.type = out_type From 10cfe5c36aaf958a71e5e32321e246e2ee95f4a4 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Mon, 31 May 2021 15:29:42 +0530 Subject: [PATCH 02/12] Fix ascii table sorting issue, refactor ascii table methods --- src/gitcomp/ser_de.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/gitcomp/ser_de.py b/src/gitcomp/ser_de.py index afc4458..a593c94 100644 --- a/src/gitcomp/ser_de.py +++ b/src/gitcomp/ser_de.py @@ -118,18 +118,21 @@ def __get_headers(g: Dict[str, Any]) -> List[str]: @staticmethod def __get_table_transpose(g: Dict[str, Union[User, Repository]]): - dict_repr = Writer.__to_dict(g) - headers = Writer.__get_headers(dict_repr) - rows = Writer.__get_entries_as_rows(dict_repr) + headers, rows = Writer.__get_table_content(g) new_headers, new_rows = Writer.__get_transpose(g, rows, headers) return tabulate(new_rows, headers=new_headers, tablefmt='pretty') @staticmethod def __get_table(g: Dict[str, Union[User, Repository]]): + headers, rows = Writer.__get_table_content(g) + return tabulate(rows, headers=headers, tablefmt='plain') + + @staticmethod + def __get_table_content(g: Dict[str, Union[User, Repository]]): dict_repr = Writer.__to_dict(g) headers = Writer.__get_headers(dict_repr) rows = Writer.__get_entries_as_rows(dict_repr) - return tabulate(rows, headers=headers, tablefmt='plain') + return headers, rows @staticmethod def __get_entries_as_rows(g: Dict[str, Any]) -> List[Any]: @@ -141,7 +144,7 @@ def __get_entries_as_rows(g: Dict[str, Any]) -> List[Any]: @staticmethod def __get_transpose(g: Dict[str, Union[User, Repository]], rows, headers): new_rows = [] - new_headers = ['Argument'] + list(g.keys()) + new_headers = ['Argument'] + sorted(list(g.keys())) for i in range(len(rows[0])): new_rows.append([rows[j][i] for j in range(len(rows))]) for i in range(len(new_rows)): From 5bf1045df789b7b045c403cc1dd4b345a22e181b Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Mon, 31 May 2021 21:30:59 +0530 Subject: [PATCH 03/12] not sorting fields working on fix --- src/gitcomp/ser_de.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gitcomp/ser_de.py b/src/gitcomp/ser_de.py index a593c94..0842a9c 100644 --- a/src/gitcomp/ser_de.py +++ b/src/gitcomp/ser_de.py @@ -92,9 +92,9 @@ def __to_ascii_table(self, g: Dict[str, Union[User, Repository]]): def __to_html_table(self, g: Dict[str, Union[User, Repository]]): file_handle = self.__get_file_handle() - table_writer = self.__get_table(g) - table_writer.format = True - file_handle.write(table_writer.get_html_string(fields=self.display_rows)) + headers, rows = self.__get_table_content(g) + table_writer = tabulate(rows, headers=headers, tablefmt='html') + file_handle.write(table_writer) Writer.__close_file_handle(file_handle) def __get_file_handle(self): @@ -144,7 +144,7 @@ def __get_entries_as_rows(g: Dict[str, Any]) -> List[Any]: @staticmethod def __get_transpose(g: Dict[str, Union[User, Repository]], rows, headers): new_rows = [] - new_headers = ['Argument'] + sorted(list(g.keys())) + new_headers = ['Argument'] + list(g.keys()) for i in range(len(rows[0])): new_rows.append([rows[j][i] for j in range(len(rows))]) for i in range(len(new_rows)): From e13a1cc4ace84c6fd4eb269a55cbd19c89275c79 Mon Sep 17 00:00:00 2001 From: avaish1409 Date: Tue, 13 Jul 2021 21:21:47 +0530 Subject: [PATCH 04/12] add basic tests --- tests/basic_test.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/basic_test.py diff --git a/tests/basic_test.py b/tests/basic_test.py new file mode 100644 index 0000000..9e179cb --- /dev/null +++ b/tests/basic_test.py @@ -0,0 +1,27 @@ +import gitcomp + +""" +Baisc test cases dependent on GitComp class output (as caputured in capsys) +- usernames +- reponames +- null args +""" + +def test_user(capsys): + gitcomp.GitComp(['avaish1409']) + + out, err = capsys.readouterr() + print(out) + assert err == '' + +def test_repo(capsys): + gitcomp.GitComp(repos=['avaish1409/VideoChatBot']) + + out, err = capsys.readouterr() + assert err == '' + +def test_null(capsys): + gitcomp.GitComp() + + out, err = capsys.readouterr() + assert err == '' From 3357004cde34d2a256a10618716b9e036520d579 Mon Sep 17 00:00:00 2001 From: avaish1409 Date: Wed, 14 Jul 2021 10:40:09 +0530 Subject: [PATCH 05/12] basic config for tox --- tox.ini | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 tox.ini diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e4a1e36 --- /dev/null +++ b/tox.ini @@ -0,0 +1,14 @@ +[tox] +envlist = py36 + +[testenv] +deps = -rrequirements.txt + +whitelist_externals = pytest +passenv = DISPLAY XAUTHORITY + +commands = + # NOTE: you can run any command line tool here - not just tests + #workon testenv + python -m pip uninstall gitcomp + From c1864c31080f7813e031bf741ded71d06494192f Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Thu, 15 Jul 2021 22:29:39 +0530 Subject: [PATCH 06/12] remove extra newline --- src/gitcomp/__main__.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/gitcomp/__main__.py b/src/gitcomp/__main__.py index dbe2598..5ebccfa 100644 --- a/src/gitcomp/__main__.py +++ b/src/gitcomp/__main__.py @@ -55,8 +55,7 @@ def __get_arg_parser() -> argparse.ArgumentParser: help=''' -o, --output Output to out_file, defaults to STDOUT. - ''' - ) + ''') return parser From f1611b614f60bc25978c6141dd08b25d53a12f10 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Thu, 15 Jul 2021 22:32:23 +0530 Subject: [PATCH 07/12] reformat to follow pep 8 --- tests/basic_test.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/tests/basic_test.py b/tests/basic_test.py index 9e179cb..49e02ac 100644 --- a/tests/basic_test.py +++ b/tests/basic_test.py @@ -7,21 +7,24 @@ - null args """ + def test_user(capsys): gitcomp.GitComp(['avaish1409']) - + out, err = capsys.readouterr() print(out) assert err == '' + def test_repo(capsys): gitcomp.GitComp(repos=['avaish1409/VideoChatBot']) - + out, err = capsys.readouterr() assert err == '' + def test_null(capsys): gitcomp.GitComp() - + out, err = capsys.readouterr() assert err == '' From 2b6be6b38efa8fc1b7d7fa1378aebda39d7db532 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Fri, 16 Jul 2021 19:37:53 +0530 Subject: [PATCH 08/12] tests using tox working --- .gitignore | 6 +++++- pyproject.toml | 3 --- setup.py | 29 ++++++++++++++++++----------- tox.ini | 15 ++++----------- 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/.gitignore b/.gitignore index 76627ed..821ec43 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,8 @@ venv/ .vscode/ __pycache__ *.pyc -*.egg-info \ No newline at end of file +*.egg-info +.tox +dist +build +gitcomp.egg-info \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 656bc44..b5a3c46 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,8 +1,5 @@ [build-system] requires = [ - "prettytable==2.1.0", - "wcwidth==0.1.8", - "urllib3==1.25.8", "setuptools>=42", "wheel" ] diff --git a/setup.py b/setup.py index 2998e26..d0f34e6 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,16 @@ from setuptools import setup, find_packages -with open('requirements.txt') as f: - requirements = f.readlines() +try: + with open('requirements.txt') as f: + requirements = f.readlines() +except FileNotFoundError: + requirements = [ + 'tabulate == 0.8.9', + 'urllib3 == 1.25.8', + 'wcwidth == 0.1.8' + ] -with open("README.md", "r", encoding="utf-8") as fh: +with open('README.md', 'r', encoding='utf-8') as fh: long_description = fh.read() setup( @@ -14,27 +21,27 @@ url='https://github.com/avaish1409/gitcomp', description='A python based command line tool to compare Github Users or Repositories.', long_description=long_description, - long_description_content_type="text/markdown", + long_description_content_type='text/markdown', license='MIT', - package_dir={"": "src"}, - packages=find_packages(where="src"), + package_dir={'': 'src'}, + packages=find_packages(where='src'), entry_points={ 'console_scripts': [ 'gitcomp = gitcomp.__main__:main' ] }, project_urls={ - "Bug Tracker": "https://github.com/avaish1409/gitcomp/issues", + 'Bug Tracker': 'https://github.com/avaish1409/gitcomp/issues', 'Documentation': 'https://avaish1409.github.io/gitcomp/', 'Source': 'https://github.com/avaish1409/gitcomp' }, classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', ], keywords='command-line-tools cli gitcomp python package compare git github', install_requires=requirements, - python_requires=">=3.6", + python_requires='>=3.6', zip_safe=False ) diff --git a/tox.ini b/tox.ini index e4a1e36..7db4d35 100644 --- a/tox.ini +++ b/tox.ini @@ -1,14 +1,7 @@ [tox] -envlist = py36 +envlist = py39 +isolated_build=true [testenv] -deps = -rrequirements.txt - -whitelist_externals = pytest -passenv = DISPLAY XAUTHORITY - -commands = - # NOTE: you can run any command line tool here - not just tests - #workon testenv - python -m pip uninstall gitcomp - +deps = pytest +commands = pytest From 34881376f46f181bc9ddb08b5a18623769e4d939 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Fri, 16 Jul 2021 19:43:07 +0530 Subject: [PATCH 09/12] adding development deps --- requirements.dev.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 requirements.dev.txt diff --git a/requirements.dev.txt b/requirements.dev.txt new file mode 100644 index 0000000..1335fc9 --- /dev/null +++ b/requirements.dev.txt @@ -0,0 +1 @@ +tox==3.24.0 \ No newline at end of file From 82ef8697498b745dbdb5325093b63bd1f9a2f500 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Fri, 16 Jul 2021 19:50:02 +0530 Subject: [PATCH 10/12] add tox --- requirements.dev.txt | 1 - requirements.txt | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 requirements.dev.txt diff --git a/requirements.dev.txt b/requirements.dev.txt deleted file mode 100644 index 1335fc9..0000000 --- a/requirements.dev.txt +++ /dev/null @@ -1 +0,0 @@ -tox==3.24.0 \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 91f298b..6eabe08 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,4 @@ tabulate==0.8.9 urllib3==1.25.8 wcwidth==0.1.8 +tox==3.24.0 From 4b0f1660cc28646a7debe4b984f27b8208c00d39 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Fri, 16 Jul 2021 19:51:06 +0530 Subject: [PATCH 11/12] not reading requirements.txt --- setup.py | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index d0f34e6..057511d 100644 --- a/setup.py +++ b/setup.py @@ -1,14 +1,10 @@ from setuptools import setup, find_packages -try: - with open('requirements.txt') as f: - requirements = f.readlines() -except FileNotFoundError: - requirements = [ - 'tabulate == 0.8.9', - 'urllib3 == 1.25.8', - 'wcwidth == 0.1.8' - ] +requirements = [ + 'tabulate == 0.8.9', + 'urllib3 == 1.25.8', + 'wcwidth == 0.1.8' +] with open('README.md', 'r', encoding='utf-8') as fh: long_description = fh.read() From b54b45a919af5bc4e95af03a02b6cb6f9d5c6a55 Mon Sep 17 00:00:00 2001 From: Rohitrajak1807 Date: Fri, 16 Jul 2021 20:17:57 +0530 Subject: [PATCH 12/12] update urllib3 version --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 6eabe08..71ea1a9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ tabulate==0.8.9 -urllib3==1.25.8 +urllib3==1.26.5 wcwidth==0.1.8 tox==3.24.0 diff --git a/setup.py b/setup.py index 057511d..c584016 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ requirements = [ 'tabulate == 0.8.9', - 'urllib3 == 1.25.8', + 'urllib3 == 1.26.5', 'wcwidth == 0.1.8' ]