Skip to content

dvcignore: read ignore patterns from global .dvcignore#8280

Closed
meshde wants to merge 28 commits into
treeverse:mainfrom
meshde:system-dvcignore
Closed

dvcignore: read ignore patterns from global .dvcignore#8280
meshde wants to merge 28 commits into
treeverse:mainfrom
meshde:system-dvcignore

Conversation

@meshde
Copy link
Copy Markdown

@meshde meshde commented Sep 11, 2022

Read the patterns from system/global config level ignore file and include these as part of
the default ignore pattern used while initiating the ignore trie

Fixes #8261

meshde and others added 3 commits September 11, 2022 09:12
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
@meshde meshde marked this pull request as ready for review September 11, 2022 05:40
@karajan1001 karajan1001 self-requested a review September 11, 2022 12:00
Comment thread dvc/ignore.py Outdated

key = self._get_key(root_dir)

sys_root_dvcignore_path = self.fs.path.join(
Copy link
Copy Markdown
Contributor

@dtrifiro dtrifiro Sep 12, 2022

Choose a reason for hiding this comment

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

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 .)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@pmrowla okay cool thanks. I'll update the code accordingly!

@dtrifiro dtrifiro self-requested a review September 12, 2022 16:04
@pmrowla pmrowla changed the title dvcignore: read ignore patterns from system level .dvcignore dvcignore: read ignore patterns from global .dvcignore Sep 13, 2022
@karajan1001
Copy link
Copy Markdown
Contributor

LGTM, except for the question discussed above.
Still need an update on the doc side.

@meshde
Copy link
Copy Markdown
Author

meshde commented Sep 15, 2022

Still need an update on the doc side.

@karajan1001 thank you for the review!

Just raised a PR to update the docs here: treeverse/dvc.org#3950

@meshde
Copy link
Copy Markdown
Author

meshde commented Sep 15, 2022

@pmrowla @dtrifiro just updated the code based on your comments.

lmk what you think of these changes.

@meshde meshde requested review from dtrifiro and pmrowla and removed request for dtrifiro, karajan1001 and pmrowla September 15, 2022 09:39
Comment thread tests/func/test_check_ignore.py Outdated
Comment on lines +14 to +26
@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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This shouldn't be needed, we already isolate the environment in the isolate fixture from tests/conftest.py.

Copy link
Copy Markdown
Author

@meshde meshde Sep 16, 2022

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Author

@meshde meshde Sep 18, 2022

Choose a reason for hiding this comment

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

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

@meshde

This comment was marked as outdated.

@meshde meshde requested review from pmrowla and removed request for dtrifiro September 18, 2022 16:11
Comment thread dvc/ignore.py Outdated
Comment thread dvc/ignore.py Outdated
Copy link
Copy Markdown
Contributor

@dtrifiro dtrifiro left a comment

Choose a reason for hiding this comment

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

See comments above

@meshde meshde requested review from dtrifiro and removed request for pmrowla September 30, 2022 03:46
@meshde
Copy link
Copy Markdown
Author

meshde commented Sep 30, 2022

@dtrifiro updated the PR as per your suggestions.

Lmk what you think now.

@efiop efiop requested a review from karajan1001 October 5, 2022 10:40
Comment thread dvc/ignore.py
self.root_dir = root_dir
self.ignores_trie_fs = Trie()
self._ignores_trie_subrepos = Trie()
self.config = Config()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This seems to be breaking the scope. Can't we just pass particular options when creating dvcignore in the repo?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Btw, doing that will allow simplifying tests by not having to monkeypatch global config dir all the time.

@shcheklein
Copy link
Copy Markdown
Contributor

@meshde @iterative/dvc any progress here folks?

@efiop
Copy link
Copy Markdown
Contributor

efiop commented Jan 9, 2023

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.

@efiop efiop closed this Jan 9, 2023
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

Successfully merging this pull request may close these issues.

feature: System-level .dvcignore

6 participants