Skip to content

Commit 2ef620e

Browse files
committed
[FEATURE] Added extended ruleset for option parsing. This fixes
This fixes #91, fixes #93, Fixes #94, Fixes #98 and fixes #99
1 parent 16f7a80 commit 2ef620e

File tree

3 files changed

+111
-37
lines changed

3 files changed

+111
-37
lines changed

42PyChecker.py

Lines changed: 103 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,105 @@
66
import argparse
77
import platform
88
from PyChecker.projects import libft, ft_commandements, other, fillit
9+
import sys
10+
11+
12+
def check_args_rules(parser, args):
13+
"""
14+
--verbose: Optionnal, no rules there.
15+
--no-gui: Enabled by default,
16+
--project: Required, Has a choice.
17+
--path: Required.
18+
19+
--no-author: Optionnal, no rules here expect 42commandements
20+
--no-forbidden-functions: Optionnal, can only be set when project=fdf|fillit|ft_ls|ft_p|ft_printf|gnl\libft|libftasm|minishell|pushswap
21+
--no-makefile: Optionnal, no rules here expect 42commandements
22+
--no-norm: Optionnal, no rules here expect 42commandements
23+
--no-static: Optionnal, can only be set when project=libft
24+
--no-extra: Optionnal, can only be set when project=libft
25+
--no-required: Optionnal, can only be set when project=libft
26+
--no-bonus: Optionnal, can only be set when project=libft
27+
--do-benchmark: Optionnal, can only be set when project=libft
28+
--no-tests: Optionnal, can only be set when project is not other.
29+
--no-libftest: Optionnal, can only be set when project=libft
30+
--no-maintest: Optionnal, can only be set when project=libft|gnl|ft_ls
31+
--no-moulitest: Optionnal, can only be set when project=libft|gnl|ft_ls|ft_printf|libftasm
32+
--no-fillit-checker: Optionnal, can only be set when project=fillit
33+
--no-libft-unit-test: Optionnal, can only be set when project=libft
34+
35+
:param args: the parsed arguments passed to the program
36+
"""
37+
38+
# If no project is given the parser sends an error.
39+
if args.project is None:
40+
parser.error("You need to specify a project.")
41+
# If the path of the selected project is empty, the parser prints an error.
42+
if args.path == "":
43+
parser.error("`--path' needs to be specified in order for 42PyChecker"
44+
" to know where your project is.")
45+
if args.path[0] != '/':
46+
parser.error("`--path' needs to have an absolute path")
47+
# If a test is disabled and the libft project is selected, the parser will
48+
# return an error.
49+
50+
# Here, if the `--no-tests` option is set, all the testing suites will be
51+
# disabled, no matter the project.
52+
if args.project == "other" and args.no_tests:
53+
parser.error("`--no-tests' Can only be applied on projects, not when 'other' is selected.")
54+
if args.no_tests:
55+
args.no_libftest = True
56+
args.no_maintest = True
57+
args.no_moulitest = True
58+
args.no_libft_unit_test = True
59+
args.no_fillit_checker = True
60+
61+
if args.no_author and args.project == "42commandements":
62+
parser.error("`--no-author' Can only be applied on project, but not on 42commandements.")
63+
64+
forbidden_functions_projects = ['fdf', 'fillit', 'ft_ls', 'ft_p', 'ft_printf', 'gnl', 'get_next_line', 'libft', 'libftasm', 'libft_asm', 'minishell', 'pushswap', 'push_swap']
65+
if args.no_forbidden_functions and args.project not in forbidden_functions_projects:
66+
parser.error("`--no-forbidden-functions' Cannot be set if project isn't one of " + str(forbidden_functions_projects))
67+
68+
if args.no_makefile and args.project == "42commandements":
69+
parser.error("`--no-makefile' Can only be applied on project, but not on 42commandements.")
70+
71+
if args.no_norm and args.project == "42commandements":
72+
parser.error("`--no-norm' Can only be applied on project, but not on 42commandements.")
73+
74+
if args.no_static and args.project != "libft":
75+
parser.error("`--no-static' Can only be applied project `libft'")
76+
77+
if args.no_extra and args.project != "libft":
78+
parser.error("`--no-extra' Can only be applied project `libft'")
79+
80+
if args.no_required and args.project != "libft":
81+
parser.error("`--no-required' Can only be applied project `libft'")
82+
83+
if args.no_bonus and args.project != "libft":
84+
parser.error("`--no-bonus' Can only be applied project `libft'")
85+
86+
if args.do_benchmark and args.project != "libft":
87+
parser.error("`--do-benchmark' Can only be applied project `libft'")
88+
89+
if args.no_libftest and args.project != "libft":
90+
parser.error("`--no-libftest' can only be applied if libft is selected "
91+
"with `--project'")
92+
93+
if args.no_maintest and args.project != "libft":
94+
parser.error("`--no-maintest' can only be applied if libft is selected "
95+
"with `--project'")
96+
97+
if args.no_moulitest and args.project != "libft":
98+
parser.error("`--no-moulitest' can only be applied if libft is selected"
99+
" with `--project'")
100+
101+
if args.no_libft_unit_test and args.project != "libft":
102+
parser.error("`--no-libft-unit-test' can only be applied if libft is selected"
103+
" with `--project'")
104+
105+
if args.no_fillit_checker and args.project != "fillit":
106+
parser.error("`--no-fillit-checker' can only be applied if fillit is selected"
107+
" with `--project'")
9108

10109

11110
def print_header():
@@ -49,12 +148,11 @@ def main():
49148
parser.add_argument("--show-w", help="Displays the warranty warning from the license.", action="store_true")
50149
parser.add_argument("--show-c", help="Displays the conditions warning from the license.", action="store_true")
51150
parser.add_argument("--no-tests", help="Disables all the testing suites for the project.", action="store_true")
52-
# @todo: Check what option is given based on the selected project.
53151
parser.add_argument("--no-required", help="Disables required functions check", action="store_true")
54152
parser.add_argument("--no-libft-unit-test", help="Disables libft-unit-test", action="store_true")
55153
parser.add_argument("--do-benchmark", help="Enables libft-unit-test benchmarking", action="store_true")
56154
parser.add_argument("--no-fillit-checker", help="Disables fillit_checker", action="store_true")
57-
155+
parser.add_argument("--no-bonus", help="Disables the bonus check for the libft", action="store_true")
58156
# Calls the parser for the arguments we asked to implement.
59157
args = parser.parse_args()
60158

@@ -70,51 +168,22 @@ def main():
70168
" ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS"
71169
" WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME\n"
72170
" THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.")
73-
return
171+
sys.exit()
74172

75173
# If the `--show-c` argument is passed, the program will display the License
76174
# and exit.
77175
if args.show_c:
78176
with open(root_path + '/.github/LICENSE.lesser', 'r') as file:
79177
print(file.read())
80-
return
81-
82-
# Here, if the `--no-tests` option is set, all the testing suites will be
83-
# disabled, no matter the project.
84-
if args.no_tests:
85-
args.no_libftest = True
86-
args.no_maintest = True
87-
args.no_moulitest = True
88-
args.no_libft_unit_test = True
178+
sys.exit()
89179

90-
# If no project is given the parser sends an error.
91-
if args.project is None:
92-
parser.error("You need to specify a project.")
93-
# If the path of the selected project is empty, the parser prints an error.
94-
if args.path == "":
95-
parser.error("`--path' needs to be specified in order for 42PyChecker"
96-
" to know where your project is.")
97-
if args.path[0] != '/':
98-
parser.error("`--path' needs to have an absolute path")
99-
# If a test is disabled and the libft project is selected, the parser will
100-
# return an error.
101-
if args.no_libftest and args.project != "libft":
102-
parser.error("`--no-libftest' can only be applied if libft is selected "
103-
"with `--project'")
104-
if args.no_maintest and args.project != "libft":
105-
parser.error("`--no-maintest' can only be applied if libft is selected "
106-
"with `--project'")
107-
if args.no_moulitest and args.project != "libft":
108-
parser.error("`--no-moulitest' can only be applied if libft is selected"
109-
" with `--project'")
180+
check_args_rules(parser, args)
110181

111182
# Here we select the project and start the check based on the argument `--project`
112183
if args.project == "libft":
113184
libft.check(root_path, args)
114-
# @todo: Handle options for 42commandements: No option can be passed (like --no-norm)
115185
if args.project == "42commandements":
116186
ft_commandements.check(args)
117-
# @todo: Handle options for other: No option can be passed (like --no-norm)
118187
if args.project == "other":
119188
other.check(root_path, args)
120189
if args.project == "fillit":

PyChecker/projects/libft.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ def check(root_path: str, args):
6969
author_results = author.check(args.path)
7070
if not args.no_required:
7171
required_results = check_required(args.path, required_functions)
72-
has_libft_bonuses, bonus_result = check_bonuses(args.path, bonus_functions)
72+
if not args.no_bonus:
73+
has_libft_bonuses, bonus_result = check_bonuses(args.path, bonus_functions)
7374
if not args.no_extra:
7475
extra_functions = count_extras(args.path, required_functions, bonus_functions)
7576
if not args.no_norm:
@@ -97,7 +98,8 @@ def check(root_path: str, args):
9798
print("Author File: \n" + author_results + '\n')
9899
if not args.no_required:
99100
print("Required Functions: \n" + required_results + '\n')
100-
print("Bonus Functions: \n" + bonus_result + '\n')
101+
if not args.no_bonus:
102+
print("Bonus Functions: \n" + bonus_result + '\n')
101103
if not args.no_extra:
102104
# @todo: Stats on all c/h files of project, like with `cloc' ?
103105
print("Extra Functions: -- You have {}\n".format(len(extra_functions)))

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,16 @@ This option has no effect when used without the option `--project`.
5959
Specify the absolute path of directory of your project.
6060
e.g.: `python3 ./42PyChecker.py --project=libft --path=/Users/admin/Projects/libft/`.
6161

62-
##### `--no-author`, `--no-norm`, `--no-makefile`, `--no-forbidden-functions`, `--no-static`, `--no-moulitest`, `--no-maintest`, `--no-libftest`, `--no-extra`
62+
##### `--no-author`, `--no-norm`, `--no-makefile`, `--no-forbidden-functions`, `--no-static`, `--no-moulitest`, `--no-maintest`, `--no-libftest`, `--no-extra` `--no-required`, `--no-libft-unit-test`, `--no-fillit-checker`, `--no-bonus`
6363

6464
Disable a specific test.
6565

6666
##### `--no-tests`
6767
This will disable all testing suites but run the other tests.
6868

69+
##### `--do-benchmark`
70+
Enables speed benchmark for libft
71+
6972
#### `--show-c` and `--show-w`
7073
These options will display respectively the License and the Warranty.
7174

0 commit comments

Comments
 (0)