Skip to content
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

Update expand_source_files( ) #36

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions importlab/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ def collect_files(path, extension):
out = []
# glob would be faster (see PEP471) but python glob doesn't do **/*
for root, _, files in os.walk(path):
out += [os.path.join(root, f) for f in files if f.endswith(extension)]
if extension is None:
out += [os.path.join(root, f) for f in files]
else:
out += [os.path.join(root, f) for f in files if f.endswith(extension)]
return out


Expand All @@ -66,26 +69,27 @@ def expand_source_files(filenames, cwd=None):
This is a helper function for handling command line arguments that specify a
list of source files and directories.

Any directories in filenames will be scanned recursively for .py files.
Any files that do not end with ".py" will be dropped.
Any directories in filenames will be scanned recursively for files.

Args:
filenames: A list of filenames to process.
cwd: An optional working directory to expand relative paths
Returns:
A list of sorted full paths to .py files
"""
out = []
for f in expand_paths(filenames, cwd):
if os.path.isdir(f):
# If we have a directory, collect all the .py files within it.
out += collect_files(f, ".py")
# If we have a directory, collect all the files within it.
out += collect_files(f, None)
else:
out.append(f)
return set(out)
if f.endswith(".py"):
out.append(f)
return sorted(set(out))



def split_version(version):
return tuple([int(v) for v in version.split('.')])

Expand Down