Skip to content

run: raise error when command is not specified#3850

Merged
efiop merged 8 commits into
treeverse:masterfrom
skshetry:msg-on-no-cmd
May 27, 2020
Merged

run: raise error when command is not specified#3850
efiop merged 8 commits into
treeverse:masterfrom
skshetry:msg-on-no-cmd

Conversation

@skshetry
Copy link
Copy Markdown
Collaborator

  • ❗ 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. If the CLI API is changed, I have updated tab completion scripts.

  • ❌ I will check DeepSource, CodeClimate, and other sanity checks below. (We consider them recommendatory and don't expect everything to be addressed. Please fix things that actually improve code or fix bugs.)

Thank you for the contribution - we'll try to review it as soon as possible. 🙏

Previously, run used to show misleading MissingOutputError when no command was specified.

@skshetry skshetry added c1-quick-fix ui user interface / interaction labels May 22, 2020
@skshetry skshetry requested review from dmpetrov and efiop May 22, 2020 08:04
@skshetry skshetry self-assigned this May 22, 2020
Comment thread dvc/repo/run.py Outdated
@skshetry skshetry marked this pull request as draft May 22, 2020 08:14
@skshetry skshetry changed the title run: raise error when command is not specified [WIP] run: raise error when command is not specified May 22, 2020
Comment thread tests/func/test_ls.py
dvc.run(
**{
"command": "python script.py",
"cmd": "python script.py {}".format(os.path.join("out", "file")),
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

The command never ran before, and never worked.

@@ -0,0 +1 @@
from tests.func.plots import run_copy_metrics # noqa: F401
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Created a run_copy_metrics fixture, that'd copy files, mostly used as copying temporarily-dumped file into metrics/plots file. Also, as metrics/params mostly work with tags and commits, run_copy_metrics can set tags and commits itself.

Comment on lines +8 to +9
tmp_dir.gen({"m_temp.yaml": str(val)})
run_copy_metrics("m_temp.yaml", "m.yaml", metrics=["m.yaml"])
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Similar code exists on metrics/params. A temp file with suffix _temp/_t is created which is copied (to have some cmd and generate metrics/plots as in the real usage).

Comment thread tests/func/test_repro.py
Comment on lines +416 to +418
*deps,
"ls {}".format(
" ".join(dep for i, dep in enumerate(deps) if i % 2)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

On above code, deps are saved as list with sequence of -d, dep items (flattened out), i just extract every second element of the list.

Comment thread tests/func/test_repro.py
last_stage = tmp_dir / "dir" / DVC_FILE
deps = [os.fspath(origin_copy_2), os.fspath(dir_file_copy)]
stage = dvc.run(
cmd="echo {}".format(" ".join(deps)),
Copy link
Copy Markdown
Collaborator Author

@skshetry skshetry May 27, 2020

Choose a reason for hiding this comment

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

For these kind of stage that does not generate any outs, I have used echo or ls or cat as a cmd.

Comment on lines +306 to +316
@pytest.mark.parametrize(
"kwargs",
[
{"outs": ["foo"], "deps": ["bar"]},
{"outs": ["foo"], "deps": ["bar"], "name": "copy-foo-bar"},
],
)
def test_run_without_cmd(kwargs):
with pytest.raises(InvalidArgumentError) as exc:
Repo().run(**kwargs)
assert "command is not specified" == str(exc.value)
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This is the actual test for the code change.

with self.assertRaises(DependencyDoesNotExistError):
self.dvc.run(
cmd="",
cmd="command",
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

A lot of tests here were cmd is never run (they eventually raise Exception before running the command), I have used command.

def test_cwd(self):
self.dvc.run(
cmd="", deps=[], outs=[self.DATA_DIR], single_stage=True,
cmd=f"mkdir {self.DATA_DIR}",
Copy link
Copy Markdown
Collaborator Author

@skshetry skshetry May 27, 2020

Choose a reason for hiding this comment

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

There should not be too many of the cases were there are no deps but only outs, but in those cases I have used mkdir or touch as cmd.

@skshetry skshetry changed the title [WIP] run: raise error when command is not specified run: raise error when command is not specified May 27, 2020
@skshetry skshetry marked this pull request as ready for review May 27, 2020 04:17
@skshetry skshetry requested a review from pared May 27, 2020 04:18
@skshetry skshetry requested a review from pmrowla May 27, 2020 04:18
@skshetry
Copy link
Copy Markdown
Collaborator Author

skshetry commented May 27, 2020

Noticed that python scripts running on Windows uses different python interpreter, possibly 2.7, as exist_ok usage on makedirs failed on a test, it is available from python>3.2).

Copy link
Copy Markdown
Contributor

@pmrowla pmrowla left a comment

Choose a reason for hiding this comment

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

LGTM

@efiop
Copy link
Copy Markdown
Contributor

efiop commented May 27, 2020

Noticed that python scripts running on Windows uses different python interpreter, possibly 2.7, as exist_ok usage on makedirs failed on a test, it is available from python>3.2).

@skshetry Oh, probably some env issues. Let's create an issue for it please to investigate further later.

@efiop efiop merged commit e8f6cd7 into treeverse:master May 27, 2020
@skshetry skshetry deleted the msg-on-no-cmd branch May 27, 2020 09:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ui user interface / interaction

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants