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

Exclude hidden folders when walking through script definitions #697

Open
wants to merge 1 commit into
base: master
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
8 changes: 8 additions & 0 deletions src/config/config_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,17 @@ def load_config_model(self, name, user, parameter_values=None, skip_invalid_para
def _visit_script_configs(self, visitor):
configs_dir = self._script_configs_folder

# We will ignore folders with this prefixes (ie: hidden folders)
exclude_prefixes=('.')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to have a list or tuple of prefixes, you have to use ('.',) (note comma) or ['.'].
But then in the check below, you will have to iterate over prefixes, rather than doing startswith(exclude_prefixes) immediately
I'm fine, if you define just a single string, but please rename the variable then


files = []
# Read config file from within directories too
for _root, _dirs, _files in os.walk(configs_dir, topdown=True):
# In place exlustion of _dirs with exlusion prefixes
_dirs[:] = [_dirs
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't work, I'm afraid, since _files are not dependent on _dirs and python will iterate over all nested files anyway.

Basically, you need to use os.path.dirname(name) below to get a file's relative path (it will be ..data in your case) and check, that it doesnt start with '.'

for _dirs in _dirs
if not _dirs.startswith(exclude_prefixes)]

for name in _files:
files.append(os.path.join(_root, name))

Expand Down