-
Notifications
You must be signed in to change notification settings - Fork 244
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-r Recursive option #129
-r Recursive option #129
Changes from 11 commits
2ebe595
ef3a21d
38be6e2
759f632
ed38dbb
fcf4638
3ac883c
e246104
2cbac72
7875c82
ca0b2d7
d9db9dd
c35ae81
9c54d8c
40c0f8f
42759f0
5931faf
5546c3d
8d1d805
35b8001
2e4d07a
0c6b082
ae84a44
1944b4a
ba3d438
6a25e25
f42d283
c7b2f73
2afc177
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,24 @@ | |
) | ||
|
||
|
||
def discover_files(targets, excluded_files, recursive=False): | ||
included_files = list() | ||
excluded_list = excluded_files.split(",") | ||
|
||
for target in targets: | ||
if os.path.isdir(target): | ||
if recursive: | ||
for root, dirs, files in os.walk(target): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this line, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i will try to do better for returning "included_files" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: You can de-dent from line |
||
for f in files: | ||
fullpath = os.path.join(root, f) | ||
if os.path.splitext(fullpath)[1] == '.py' and fullpath.split("/")[-1] not in excluded_list: | ||
included_files.append(fullpath) | ||
else: | ||
if targets not in excluded_list: | ||
included_files.append(targets[0]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if targets is a list of files, e.g. |
||
return(included_files) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you change this to |
||
|
||
|
||
def main(command_line_args=sys.argv[1:]): | ||
args = parse_args(command_line_args) | ||
|
||
|
@@ -39,6 +57,14 @@ def main(command_line_args=sys.argv[1:]): | |
elif args.trim_reassigned_in: | ||
ui_mode = UImode.TRIM | ||
|
||
|
||
|
||
targets = args.targets | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it might be more DRY if you did files = discover_files(
args.targets,
args.excluded_paths,
args.recursive
) |
||
excluded_files = args.excluded_paths | ||
recursive = args.recursive | ||
test = discover_files(targets, excluded_files, recursive) #just for see files in directory | ||
print(test) | ||
|
||
path = os.path.normpath(args.filepath) | ||
|
||
if args.ignore_nosec: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,11 +29,11 @@ def valid_date(s): | |
|
||
def _add_required_group(parser): | ||
required_group = parser.add_argument_group('required arguments') | ||
required_group.add_argument( | ||
'''required_group.add_argument( | ||
'-f', '--filepath', | ||
help='Path to the file that should be analysed.', | ||
type=str | ||
) | ||
)''' | ||
|
||
|
||
def _add_optional_group(parser): | ||
|
@@ -91,7 +91,21 @@ def _add_optional_group(parser): | |
action='store_true', | ||
help='do not skip lines with # nosec comments' | ||
) | ||
|
||
optional_group.add_argument( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe make it
|
||
'-r', '--recursive', dest='recursive', | ||
action='store_true', help='find and process files in subdirectories' | ||
) | ||
optional_group.add_argument( | ||
'-x', '--exclude', | ||
dest='excluded_paths', | ||
action='store', | ||
default='', | ||
help='Separate files with commas' | ||
) | ||
optional_group.add_argument( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess targets will be part of |
||
'targets', metavar='targets', type=str, nargs='*', | ||
help='source file(s) or directory(s) to be tested' | ||
) | ||
|
||
def _add_print_group(parser): | ||
print_group = parser.add_argument_group('print arguments') | ||
|
@@ -110,8 +124,8 @@ def _add_print_group(parser): | |
|
||
|
||
def _check_required_and_mutually_exclusive_args(parser, args): | ||
if args.filepath is None: | ||
parser.error('The -f/--filepath argument is required') | ||
if args.targets is None: | ||
parser.error('The target argument is required') | ||
|
||
|
||
def parse_args(args): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So having
if recursive:
here it will make it so that if you don't have-r
then you won't search directories.You can change it to: