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

Allow to exclude files if they contain a specific order of unwanted directories #30

Open
JohannesWiesner opened this issue Apr 26, 2024 · 1 comment

Comments

@JohannesWiesner
Copy link
Owner

Example:

I only want files that include pre/standard_direct in their filepath but I want to drop files that contain pre/standard.

Because the string pre/standard_direct contains pre/standard it's hard to work with exact string matches. If I tell nisupply to exclude all strings that include pre/standard, I would also exclude pre/standard_direct.

This would be basically an extension to the exclude_dirs argument (maybe exclude_nested_dirs would be a good name for this argument?)

@JohannesWiesner
Copy link
Owner Author

This logic was already implemented in the past:

nisupply/nisupply.py

Lines 90 to 107 in fa69fac

# Filter list of found files by deleting filepaths from list whose path
# components do not match any of the given preceding directories
if preceding_dirs:
# if only one preceding_dirs is provided as string, convert to list
# of single string
if isinstance(preceding_dirs,str):
preceding_dirs = [preceding_dirs]
tagged_files_indices = []
for idx,filepath in enumerate(filepath_list):
if not any(path_component in filepath.split(os.sep) for path_component in preceding_dirs):
tagged_files_indices.append(idx)
for idx in sorted(tagged_files_indices,reverse=True):
del filepath_list[idx]

We can split up each filepath into its path components (break on os.sep). We can also split up the user input into it's path components. We can then check if the filepath contains a chain of path components that match the input path components.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant