From d443bc565f5106867ca490c19abb5262e68fd5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Martinez?= Date: Wed, 9 Aug 2023 10:30:43 +0200 Subject: [PATCH 01/12] add filter argument fix #32 --- gepetuto/main.py | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 840c3c2..233eaf5 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -40,6 +40,14 @@ def parse_args(args=None) -> argparse.Namespace: nargs="*", help="choose which files to process.", ) + parser.add_argument( + "-F", + "--filter", + default=[], + type=str, + nargs="*", + help="filter files to process.", + ) parser.add_argument( "tp_id", default=[], @@ -97,26 +105,32 @@ def retrieve_python_interpreter(): return sys.executable -def get_file_list(tp_id, file): +def get_file_list(args): """Get the list of files we use action on.""" - file = [Path(f) for f in file] + if args.tp_id == []: + args.tp_id = get_tp_id() + if args.file != []: + args.file = [Path(f) for f in args.file] file_list = [] - if tp_id == []: - tp_id = get_tp_id() - for n in tp_id: + for n in args.tp_id: folder = Path(f"tp{n}") - if file == []: - file_list += folder.glob("*.py") - else: - file_list += list(filter(lambda f: f in file, folder.glob("*.py"))) + tp_files = folder.glob("*.py") + if args.file != []: + tp_files = [f for f in tp_files if f in args.file] + if args.filter != []: + tp_files = [ + f + for f in tp_files + if any(filter_str in str(f) for filter_str in args.filter) + ] + file_list += tp_files return file_list def main(): """Run command.""" - print("here2") args = parse_args() - files = get_file_list(args.tp_id, args.file) + files = get_file_list(args.tp_id, args.file, args.filter) if args.action == "generate": generate(**vars(args)) elif args.action == "lint": From 196ab0672931515f97e7c8c3bdf05d98d6a669cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Martinez?= Date: Wed, 9 Aug 2023 10:39:53 +0200 Subject: [PATCH 02/12] add new unit tests --- tests/unit_tests.py | 48 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/tests/unit_tests.py b/tests/unit_tests.py index cc22d9e..5ffdcb7 100644 --- a/tests/unit_tests.py +++ b/tests/unit_tests.py @@ -11,7 +11,7 @@ class TestGepetutoArguments(unittest.TestCase): def test_no_arg(self): """Check files we work on when no arguments are given.""" arguments = parse_args() - file_list = get_file_list(arguments.tp_id, arguments.file) + file_list = get_file_list(arguments) self.assertTrue(Path("tp1/cholesky.py") in file_list) self.assertTrue(Path("tp1/example_script.py") in file_list) self.assertTrue(Path("tp2/cholesky.py") in file_list) @@ -20,7 +20,7 @@ def test_no_arg(self): def test_tp_id_1(self): """Check files we work on when we specify tp_id = 1.""" arguments = parse_args(["1"]) - file_list = get_file_list(arguments.tp_id, arguments.file) + file_list = get_file_list(arguments) self.assertTrue(Path("tp1/cholesky.py") in file_list) self.assertTrue(Path("tp1/example_script.py") in file_list) self.assertTrue(Path("tp2/cholesky.py") not in file_list) @@ -29,7 +29,7 @@ def test_tp_id_1(self): def test_file_cholesky(self): """Check files we work on when we specify a file with --file.""" arguments = parse_args(["--file", "tp1/cholesky.py"]) - file_list = get_file_list(arguments.tp_id, arguments.file) + file_list = get_file_list(arguments) self.assertTrue(Path("tp1/cholesky.py") in file_list) self.assertTrue(Path("tp1/example_script.py") not in file_list) self.assertTrue(Path("tp2/cholesky.py") not in file_list) @@ -38,7 +38,7 @@ def test_file_cholesky(self): def test_tp_id_1_file_cholesky(self): """Check files we work on when we specify tp_id = 1 and a file in tp1 folder.""" arguments = parse_args(["1", "--file", "tp1/cholesky.py"]) - file_list = get_file_list(arguments.tp_id, arguments.file) + file_list = get_file_list(arguments) self.assertTrue(Path("tp1/cholesky.py") in file_list) self.assertTrue(Path("tp1/example_script.py") not in file_list) self.assertTrue(Path("tp2/cholesky.py") not in file_list) @@ -47,7 +47,45 @@ def test_tp_id_1_file_cholesky(self): def test_no_file_matching(self): """Check files we work on when tp_id and --file has no files in common.""" arguments = parse_args(["2", "--file", "tp1/cholesky.py"]) - file_list = get_file_list(arguments.tp_id, arguments.file) + file_list = get_file_list(arguments) + self.assertTrue(Path("tp1/cholesky.py") not in file_list) + self.assertTrue(Path("tp1/example_script.py") not in file_list) + self.assertTrue(Path("tp2/cholesky.py") not in file_list) + self.assertTrue(Path("tp2/another_script.py") not in file_list) + + def test_filter_cholesky(self): + """Check files we work on with --filter cholesky argument.""" + arguments = parse_args(["--filter", "cholesky"]) + file_list = get_file_list(arguments) + self.assertTrue(Path("tp1/cholesky.py") in file_list) + self.assertTrue(Path("tp1/example_script.py") not in file_list) + self.assertTrue(Path("tp2/cholesky.py") in file_list) + self.assertTrue(Path("tp2/another_script.py") not in file_list) + + def test_tp_id_1_filter_cholesky(self): + """Check files we work on with --filter cholesky argument.""" + arguments = parse_args(["1", "--filter", "cholesky"]) + file_list = get_file_list(arguments) + self.assertTrue(Path("tp1/cholesky.py") in file_list) + self.assertTrue(Path("tp1/example_script.py") not in file_list) + self.assertTrue(Path("tp2/cholesky.py") not in file_list) + self.assertTrue(Path("tp2/another_script.py") not in file_list) + + def test_file_cholesky_filter_cholesky(self): + """Check files we work on with --filter cholesky and --file on cholesky file.""" + arguments = parse_args(["--file", "tp1/cholesky.py", "--filter", "cholesky"]) + file_list = get_file_list(arguments) + self.assertTrue(Path("tp1/cholesky.py") in file_list) + self.assertTrue(Path("tp1/example_script.py") not in file_list) + self.assertTrue(Path("tp2/cholesky.py") not in file_list) + self.assertTrue(Path("tp2/another_script.py") not in file_list) + + def test_no_file_matching_2(self): + """Check files we work on when --file and --filter has no files in common.""" + arguments = parse_args( + ["--file", "tp1/example_script.py", "--filter", "cholesky"], + ) + file_list = get_file_list(arguments) self.assertTrue(Path("tp1/cholesky.py") not in file_list) self.assertTrue(Path("tp1/example_script.py") not in file_list) self.assertTrue(Path("tp2/cholesky.py") not in file_list) From 039abeff53c2d89835be607541090f96e298bbf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Martinez?= Date: Wed, 9 Aug 2023 11:13:08 +0200 Subject: [PATCH 03/12] add changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d453da..15d28ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,5 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - project initialisation +• add the -F/--filter argument [Unreleased]: https://github.com/gepetto/gepetuto From fc4a06c7402c25f687f5ae71fb7ffc721d0ad192 Mon Sep 17 00:00:00 2001 From: TheoMF <140606863+TheoMF@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:21:50 +0200 Subject: [PATCH 04/12] Update CHANGELOG.md Co-authored-by: Guilhem Saurel --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 15d28ec..3fec766 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] - project initialisation -• add the -F/--filter argument +- add the -F/--filter argument [Unreleased]: https://github.com/gepetto/gepetuto From 2d44e63f737e0cc358497bff3189a40a9a0e6f04 Mon Sep 17 00:00:00 2001 From: TheoMF <140606863+TheoMF@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:21:57 +0200 Subject: [PATCH 05/12] Update gepetuto/main.py Co-authored-by: Guilhem Saurel --- gepetuto/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 233eaf5..499de9e 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -130,7 +130,7 @@ def get_file_list(args): def main(): """Run command.""" args = parse_args() - files = get_file_list(args.tp_id, args.file, args.filter) + files = get_file_list(args) if args.action == "generate": generate(**vars(args)) elif args.action == "lint": From 2268e6bc0f688fb15e7769121ada7d16dbaa0bd8 Mon Sep 17 00:00:00 2001 From: TheoMF <140606863+TheoMF@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:22:03 +0200 Subject: [PATCH 06/12] Update gepetuto/main.py Co-authored-by: Guilhem Saurel --- gepetuto/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 499de9e..f65b01b 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -108,7 +108,7 @@ def retrieve_python_interpreter(): def get_file_list(args): """Get the list of files we use action on.""" if args.tp_id == []: - args.tp_id = get_tp_id() + tp_id = get_tp_id() if args.file != []: args.file = [Path(f) for f in args.file] file_list = [] From 70c5c486bcf7ae70b5dabe3a2d727a43aa1de92c Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 09:22:31 +0000 Subject: [PATCH 07/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- gepetuto/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index f65b01b..3efcf11 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -108,7 +108,7 @@ def retrieve_python_interpreter(): def get_file_list(args): """Get the list of files we use action on.""" if args.tp_id == []: - tp_id = get_tp_id() + get_tp_id() if args.file != []: args.file = [Path(f) for f in args.file] file_list = [] From e6d76ab324c67831b73ae884078c24c3dbabb8ff Mon Sep 17 00:00:00 2001 From: TheoMF <140606863+TheoMF@users.noreply.github.com> Date: Wed, 9 Aug 2023 11:22:41 +0200 Subject: [PATCH 08/12] Update gepetuto/main.py Co-authored-by: Guilhem Saurel --- gepetuto/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 3efcf11..02fd5ee 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -110,7 +110,7 @@ def get_file_list(args): if args.tp_id == []: get_tp_id() if args.file != []: - args.file = [Path(f) for f in args.file] + file = [Path(f) for f in args.file] file_list = [] for n in args.tp_id: folder = Path(f"tp{n}") From 1fd9cd4cf6da26c05c5a69eef3915c46dd03b64f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 9 Aug 2023 09:23:56 +0000 Subject: [PATCH 09/12] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- gepetuto/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 02fd5ee..62728f3 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -110,7 +110,7 @@ def get_file_list(args): if args.tp_id == []: get_tp_id() if args.file != []: - file = [Path(f) for f in args.file] + [Path(f) for f in args.file] file_list = [] for n in args.tp_id: folder = Path(f"tp{n}") From 7b1017328f426f9637f6dead37ac7dc36376cd1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20Martinez?= Date: Wed, 9 Aug 2023 12:20:47 +0200 Subject: [PATCH 10/12] fix get_file_list function --- gepetuto/main.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 62728f3..8ef7600 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -108,15 +108,19 @@ def retrieve_python_interpreter(): def get_file_list(args): """Get the list of files we use action on.""" if args.tp_id == []: - get_tp_id() - if args.file != []: - [Path(f) for f in args.file] + tp_id = get_tp_id() + else: + tp_id = args.tp_id + if args.file == []: + file = [] + else: + file = [Path(f) for f in args.file] file_list = [] - for n in args.tp_id: + for n in tp_id: folder = Path(f"tp{n}") tp_files = folder.glob("*.py") - if args.file != []: - tp_files = [f for f in tp_files if f in args.file] + if file != []: + tp_files = [f for f in tp_files if f in file] if args.filter != []: tp_files = [ f From 2f6ff5574077cdafc92a768d4649c6781ab0abd4 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 9 Aug 2023 12:31:09 +0200 Subject: [PATCH 11/12] Update gepetuto/main.py --- gepetuto/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index 8ef7600..fcfffd2 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -107,10 +107,7 @@ def retrieve_python_interpreter(): def get_file_list(args): """Get the list of files we use action on.""" - if args.tp_id == []: - tp_id = get_tp_id() - else: - tp_id = args.tp_id + tp_id = args.tp_id or get_tp_id() if args.file == []: file = [] else: From 650b1c6ac8aea7f61187b9899fae1b66c7793671 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 9 Aug 2023 12:31:17 +0200 Subject: [PATCH 12/12] Update gepetuto/main.py --- gepetuto/main.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/gepetuto/main.py b/gepetuto/main.py index fcfffd2..86cdd29 100644 --- a/gepetuto/main.py +++ b/gepetuto/main.py @@ -108,10 +108,7 @@ def retrieve_python_interpreter(): def get_file_list(args): """Get the list of files we use action on.""" tp_id = args.tp_id or get_tp_id() - if args.file == []: - file = [] - else: - file = [Path(f) for f in args.file] + file = [Path(f) for f in args.file] file_list = [] for n in tp_id: folder = Path(f"tp{n}")