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

commands/update: add --rev option #2993

Closed
wants to merge 18 commits into from

Conversation

ilgooz
Copy link

@ilgooz ilgooz commented Dec 21, 2019

to update with a specific git revision.

please see updates on the docs iterative/dvc.org#890.

resolves #2849.

--

  • ❗ Have you followed the guidelines in the Contributing to DVC list?

  • πŸ“– Check this box if this PR does not require documentation updates, or if it does and you have created a separate PR in dvc.org with such updates (or at least opened an issue about it in that repo). Please link below to your PR (or issue) in the dvc.org repo.

  • ❌ Have you checked DeepSource, CodeClimate, and other sanity checks below? We consider their findings recommendatory and don't expect everything to be addressed. Please review them carefully and fix those that actually improve code or fix bugs.

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™

to update with a specific git revision
@shcheklein shcheklein requested review from Suor and efiop December 21, 2019 23:11
@shcheklein
Copy link
Member

@ilgooz looks like you need to install the pre-commit hook that takes care of the code style - please, take a look at the contributing guide.

@ilgooz
Copy link
Author

ilgooz commented Dec 22, 2019

@ilgooz looks like you need to install the pre-commit hook that takes care of the code style - please, take a look at the contributing guide.

Thanks Ivan, I'll do that and also some fixes, and add some tests!

Copy link
Contributor

@Suor Suor left a comment

Choose a reason for hiding this comment

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

PR is incomplete:

  • format things, e.g. with pre-commit hooks, to run tests
  • need a functional test for dvc update --rev
  • need to check that dvc update --rev ... shows an appropriate error for a import-url stage

dvc/dependency/repo.py Outdated Show resolved Hide resolved
@ilgooz
Copy link
Author

ilgooz commented Jan 2, 2020

@ilgooz looks like you need to install the pre-commit hook that takes care of the code style - please, take a look at the contributing guide.

PR is incomplete:

  • format things, e.g. with pre-commit hooks, to run tests
  • need a functional test for dvc update --rev
  • need to check that dvc update --rev ... shows an appropriate error for a import-url stage

done by 95db0ea

@ilgooz ilgooz marked this pull request as ready for review January 2, 2020 13:20
@ilgooz ilgooz requested a review from Suor January 2, 2020 13:27
dvc/repo/update.py Outdated Show resolved Hide resolved
@ilgooz ilgooz requested a review from efiop January 2, 2020 17:10
dvc/command/update.py Outdated Show resolved Hide resolved
dvc/dependency/base.py Outdated Show resolved Hide resolved
dvc/stage.py Outdated Show resolved Hide resolved
tests/func/test_update.py Outdated Show resolved Hide resolved
tests/func/test_update.py Outdated Show resolved Hide resolved
tests/func/test_update.py Outdated Show resolved Hide resolved
@ilgooz
Copy link
Author

ilgooz commented Jan 4, 2020

Hi guys, big thanks for your encouraging collaboration, I'll do the requested changes. Can you please participate to the discussion at the following link as well? #2849 (comment)

ilgooz and others added 3 commits January 4, 2020 22:45
Copy link
Contributor

@jorgeorpinel jorgeorpinel left a comment

Choose a reason for hiding this comment

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

LGTM

@ilgooz ilgooz requested a review from efiop January 4, 2020 23:46
@ilgooz
Copy link
Author

ilgooz commented Jan 4, 2020

Any ideas of how to get Travis check back? Should I split the string into two lines?

https://travis-ci.com/iterative/dvc/jobs/272434824

tests/unit/command/test_update.py:32:80: E501 line too long (93 > 79 characters)
The command "./scripts/ci/check_patch.sh" exited with 1.

@efiop
Copy link
Contributor

efiop commented Jan 4, 2020

@ilgooz Yes, please split it somehow.

@ilgooz
Copy link
Author

ilgooz commented Jan 5, 2020

cc @Suor up for reviews!

tests/func/test_update.py Outdated Show resolved Hide resolved
@ilgooz
Copy link
Author

ilgooz commented Jan 5, 2020

Tests won't pass again, I'll check this tomorrow!

tests/unit/command/test_update.py Outdated Show resolved Hide resolved
@pared
Copy link
Contributor

pared commented Jan 7, 2020

LGTM, but test_update_rev needs to be modified

@ilgooz ilgooz requested review from efiop, Suor and jorgeorpinel January 15, 2020 17:24
Comment on lines +126 to +127
if not rev:
rev = self.def_repo.get("rev")
Copy link
Contributor

Choose a reason for hiding this comment

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

No need to do that. See _make_rev, where it will merge your args with def_repo anyways.

@@ -53,6 +53,6 @@ def add_parser(subparsers, parent_parser):
"-o", "--out", nargs="?", help="Destination path to download files to"
)
import_parser.add_argument(
"--rev", nargs="?", help="Git revision (e.g. branch, tag, SHA)"
"--rev", nargs="?", help="Git revision in repository to update from."
Copy link

@ghost ghost Jan 15, 2020

Choose a reason for hiding this comment

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

@ilgooz , why removing the examples? Not everyone is familiar with the term revision)

class UpdateWithRevNotPossibleError(DvcException):
def __init__(self):
super(UpdateWithRevNotPossibleError, self).__init__(
"Revision option (`--rev`) is not a feature of non-Git sources."
Copy link

Choose a reason for hiding this comment

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

Usually it is easier to read without double negations:
not a feature of non-Git sources -> only a feature of Git sources

Suggested change
"Revision option (`--rev`) is not a feature of non-Git sources."
"Revision option (`--rev`) is supported only for Git sources."



def test_update_rev(tmp_dir, dvc, erepo_dir, monkeypatch):
with monkeypatch.context() as m:
Copy link

Choose a reason for hiding this comment

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

@ilgooz , if the reason for using monkeypatch is to chdir to erepo_dir, you can use instead:

Suggested change
with monkeypatch.context() as m:
with erepo_dir.chdir():

def test_update_rev(tmp_dir, dvc, erepo_dir, monkeypatch):
with monkeypatch.context() as m:
m.chdir(fspath(erepo_dir))
erepo_dir.scm.checkout("new_branch", create_new=True)
Copy link

@ghost ghost Jan 15, 2020

Choose a reason for hiding this comment

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

Another useful helper to change to a branch temporarily:

Suggested change
erepo_dir.scm.checkout("new_branch", create_new=True)
with erepo_dir.branch("new_branch", new=True):
# ...

erepo_dir.scm.checkout("new_branch", create_new=True)
erepo_dir.dvc_gen("foo", "foo content", commit="create foo on branch")
erepo_dir.scm.checkout("master")
erepo_dir.scm.checkout("new_branch_2", create_new=True)
Copy link

@ghost ghost Jan 15, 2020

Choose a reason for hiding this comment

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

Same here:

Suggested change
erepo_dir.scm.checkout("new_branch_2", create_new=True)
with erepo_dir.branch("new_branch_2", new=True):

assert (tmp_dir / "foo_imported").read_text() == "foo content 2"


def test_update_rev_non_git_failure(repo_dir, dvc_repo):
Copy link

Choose a reason for hiding this comment

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

We are not using repo_dir and dvc_repo anymore, instead, we use tmp_dir or dvc.
This is not crucial, but it would be nice if you could read the docstring from tests/dir_helpers.py.
Sorry for the extra work, @ilgooz 😞

Copy link

Choose a reason for hiding this comment

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

Here's a suggestion, to save you some time:

def test_update_rev_non_git_failure(tmp_dir, dvc):
    tmp_dir.gen("file", "text")
    stage = dvc.imp_url("file", "imported")

    with pytest.raises(UpdateWithRevNotPossibleError):
        dvc_repo.update(stage.path, rev="dev")

Looks neat)

@efiop
Copy link
Contributor

efiop commented Jan 16, 2020

Test changes are caused by this PR existing through the period of us refactoring our test suite πŸ™‚Sorry for the inconvenience.

@efiop
Copy link
Contributor

efiop commented Jan 20, 2020

Closing as stale.

@efiop efiop closed this Jan 20, 2020
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.

Support revisions in dvc update
6 participants