Skip to content

Commit

Permalink
bugfix, but not using external Node with params (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ authored Jul 13, 2023
1 parent 808ad39 commit 8d1f776
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
29 changes: 27 additions & 2 deletions tests/integration/test_from_rev.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,31 @@ def test_connect_from_remote(proj_path):
node = AddOne(number=node_b.random_number)

project.run()
node.load()
# We can not use node.load() here and build again,
# because it will convert connections to e.g. type int
# and then we can not connect to the node anymore.
# node.load()

assert zntrack.from_rev(node.name).outs == node_b.random_number + 1

project.build()


def test_two_nodes_connect_external(proj_path):
node_a = zntrack.from_rev(
"HelloWorld",
remote="https://github.com/PythonFZ/ZnTrackExamples.git",
rev="fbb6ada",
)

with zntrack.Project(automatic_node_names=True) as project:
node1 = AddOne(number=node_a.random_number)
node2 = AddOne(number=node_a.random_number)

project.run()

node1.load()
node2.load()

assert node.outs == node_b.random_number + 1
assert node1.outs == node_a.random_number + 1
assert node2.outs == node_a.random_number + 1
6 changes: 5 additions & 1 deletion zntrack/fields/zn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,9 @@ def get_files(self, instance) -> list:
deps_file = pathlib.Path("external", f"{node.uuid}.json")
deps_file.parent.mkdir(exist_ok=True, parents=True)

# zntrack run node.name --external \
# --remote node.state.remote --rev node.state.rev

# when combining with zn.nodes this should be used
# dvc stage add <name> --params params.yaml:<name>
# --outs nodes/<name>/node-meta.json zntrack run <name> --external
Expand All @@ -367,7 +370,8 @@ def get_files(self, instance) -> list:
if node.state.rev is not None:
cmd.extend(["--rev", node.state.rev])
# TODO how can we test, that the loaded file truly is the correct one?
run_dvc_cmd(cmd)
if not deps_file.exists():
run_dvc_cmd(cmd)
files.append(deps_file.as_posix())
# dvc import node-meta.json + add as dependency file
continue
Expand Down
3 changes: 2 additions & 1 deletion zntrack/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ def run_dvc_cmd(script):
return_code = dvc.cli.main(script)
if return_code != 0:
raise DVCProcessError(
f"DVC CLI failed ({return_code}) for cmd: \n \"{' '.join(script)}\" "
f'DVC CLI failed ({return_code}) for cmd: \n "dvc'
f' {" ".join(x for x in script if x != "--quiet")}" '
)
# fix for https://github.com/iterative/dvc/issues/8631
for logger_name, logger in logging.root.manager.loggerDict.items():
Expand Down

0 comments on commit 8d1f776

Please sign in to comment.