dvcignore: read ignore patterns from global .dvcignore#8280
Conversation
Read the patterns from system-level .dvcignore and include these as part of the default ignore pattern used while initiating the ignore trie Fixes treeverse#8261
for more information, see https://pre-commit.ci
|
|
||
| key = self._get_key(root_dir) | ||
|
|
||
| sys_root_dvcignore_path = self.fs.path.join( |
There was a problem hiding this comment.
Hey! Thanks for contributing 🚀
Just as a small note: git's behaviour for global gitignore files, is to look for a global gitignore in $XDG_CONFIG_HOME/git/ignore.
For dvc user-level config, we use appdirs.user_config_dir (system_config_dir for system-level):
https://github.com/iterative/dvc/blob/8e5f4a8f35a15e741031bf1c9dbe4728fa55021d/dvc/config.py#L107-L116
So it could make sense to keep the user's dvcignore in appdirs.user_config_dir(cls.APPNAME, cls.APPAUTHOR) (note: no leading .)
There was a problem hiding this comment.
@dtrifiro Thank you for your review!
Happy to make that change but IMHO ~/.dvcignore is more intuitive to maintain than ~/Library/Application Support/dvc/dvcignore (macOS).
I understand that the global config options get stored in ~/Library/Application Support/dvc/config but something to keep in mind is that the documented way of setting and reading global config options is through the command dvc config --global rather than maintaining the config file itself.
Lmk what you think, I'm happy to make it go either way.
There was a problem hiding this comment.
IMO it would be better to handle this the way that git does - you tell git where to look for the file via the core.excludesfile config option.
We should be adding a similar config option in DVC, so the user can do dvc config --global core.excludesfile $HOME/.dvcignore if that's where they want it to go. If the user has not set the option, it should default to looking in the proper DVC user config directories per-platform (~/Library/Application Support on macos, XDG config dirs on linux, and %localappdata% on windows).
There was a problem hiding this comment.
Also note that by default we need to check the global (user) level config location first. But we should also check the system level location as well if there is no global level .dvcignore.
There was a problem hiding this comment.
@pmrowla okay cool thanks. I'll update the code accordingly!
|
LGTM, except for the question discussed above. |
@karajan1001 thank you for the review! Just raised a PR to update the docs here: treeverse/dvc.org#3950 |
| @pytest.fixture(autouse=True) | ||
| def tmp_config_dir(mocker, tmp_path): | ||
| """ | ||
| Fixture to prevent modifying/reading the actual global config | ||
| """ | ||
|
|
||
| for level in ["global", "system"]: | ||
| os.makedirs(_get_tmp_config_dir(tmp_path, level)) | ||
|
|
||
| def get_tmp_config_dir(level): | ||
| return str(_get_tmp_config_dir(tmp_path, level)) | ||
|
|
||
| mocker.patch("dvc.config.Config.get_dir", side_effect=get_tmp_config_dir) |
There was a problem hiding this comment.
This shouldn't be needed, we already isolate the environment in the isolate fixture from tests/conftest.py.
There was a problem hiding this comment.
So when I was writing the tests, the .dvcignore from my system dir (/Library/Application Support/dvc/.dvcignore) was being read in the tests, which is why I ended up mocking Config.get_dir.
Now that I look into it further, the isolate fixture does return an isolated directory for Config.get_dir("global") but does not seem to do so for Config.get_dir("system") and returns /Library/Application Support/dvc instead.
I'll see if I can make the isloate fixture also isolate the system config directory.
There was a problem hiding this comment.
So it turns out that the isolate fixture in it's current state is not completely ready to handle global/system dvc configs. The PR that added the this fixture mentions this fact in a comment: #6857 (comment).
Got it to isolate system and global dvc config directories and tried to cover all cases in the following way:
https://github.com/iterative/dvc/pull/8280/files#diff-e52e4ddd58b7ef887ab03c04116e676f6280b824ab7469d5d3080e5cba4f2128
There were some situations where manipulating env vars was not helpful. In such cases, this PR mocks the functions from appdirs instead.
Lmk what you think of this
for more information, see https://pre-commit.ci
This comment was marked as outdated.
This comment was marked as outdated.
|
@dtrifiro updated the PR as per your suggestions. Lmk what you think now. |
| self.root_dir = root_dir | ||
| self.ignores_trie_fs = Trie() | ||
| self._ignores_trie_subrepos = Trie() | ||
| self.config = Config() |
There was a problem hiding this comment.
This seems to be breaking the scope. Can't we just pass particular options when creating dvcignore in the repo?
There was a problem hiding this comment.
Btw, doing that will allow simplifying tests by not having to monkeypatch global config dir all the time.
|
@meshde @iterative/dvc any progress here folks? |
|
Closing as stale. Please feel free to reopen if you'll find time to address #8280 (comment) This change is useful, but we don't have the capacity to take it over ourselves right now. |
Read the patterns from system/global config level
ignorefile and include these as part ofthe default ignore pattern used while initiating the ignore trie
Fixes #8261
❗ I have followed the Contributing to DVC checklist.
📖 If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.