Skip to content

Commit

Permalink
fix #543
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Mar 28, 2023
1 parent 033b8f2 commit 9fea13c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
7 changes: 7 additions & 0 deletions zntrack/core/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import contextlib
import dataclasses
import functools
import importlib
import logging
import pathlib
Expand Down Expand Up @@ -47,6 +48,12 @@ class NodeStatus:
rev: str = None

def get_file_system(self) -> dvc.api.DVCFileSystem:
"""Get the file system of the Node."""
log.warning("Deprecated. Use 'state.fs' instead.")
return self.fs

@functools.cached_property
def fs(self) -> dvc.api.DVCFileSystem:
"""Get the file system of the Node."""
return dvc.api.DVCFileSystem(
url=self.remote,
Expand Down
2 changes: 1 addition & 1 deletion zntrack/fields/dvc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def get_data(self, instance: "Node") -> any:
The value of the field from the configuration file.
"""
zntrack_dict = json.loads(
instance.state.get_file_system().read_text("zntrack.json"),
instance.state.fs.read_text("zntrack.json"),
)
return json.loads(
json.dumps(zntrack_dict[instance.name][self.name]), cls=znjson.ZnDecoder
Expand Down
4 changes: 2 additions & 2 deletions zntrack/fields/meta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def save(self, instance):

def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
dvc_dict = yaml.safe_load(instance.state.get_file_system().read_text("dvc.yaml"))
dvc_dict = yaml.safe_load(instance.state.fs.read_text("dvc.yaml"))
return dvc_dict["stages"][instance.name]["meta"].get(self.name, None)

def get_stage_add_argument(self, instance) -> typing.List[tuple]:
Expand Down Expand Up @@ -72,7 +72,7 @@ def save(self, instance):

def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
env_dict = yaml.safe_load(instance.state.get_file_system().read_text("env.yaml"))
env_dict = yaml.safe_load(instance.state.fs.read_text("env.yaml"))
return env_dict.get(instance.name, {}).get(self.name, None)

def get_stage_add_argument(self, instance) -> typing.List[tuple]:
Expand Down
10 changes: 4 additions & 6 deletions zntrack/fields/zn/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def save(self, instance: "Node"):
def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
file = self.get_files(instance)[0]
params_dict = yaml.safe_load(instance.state.get_file_system().read_text(file))
params_dict = yaml.safe_load(instance.state.fs.read_text(file))
value = params_dict[instance.name].get(self.name, None)
return json.loads(json.dumps(value), cls=znjson.ZnDecoder)

Expand Down Expand Up @@ -212,7 +212,7 @@ def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
file = self.get_files(instance)[0]
return json.loads(
instance.state.get_file_system().read_text(file.as_posix()),
instance.state.fs.read_text(file.as_posix()),
cls=znjson.ZnDecoder,
)

Expand Down Expand Up @@ -259,9 +259,7 @@ def save(self, instance: "Node"):
def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
file = self.get_files(instance)[0]
return pd.read_csv(
instance.state.get_file_system().open(file.as_posix()), index_col=0
)
return pd.read_csv(instance.state.fs.open(file.as_posix()), index_col=0)

def get_stage_add_argument(self, instance) -> typing.List[tuple]:
"""Get the dvc command for this field."""
Expand Down Expand Up @@ -348,7 +346,7 @@ def save(self, instance: "Node"):
def get_data(self, instance: "Node") -> any:
"""Get the value of the field from the file."""
zntrack_dict = json.loads(
instance.state.get_file_system().read_text("zntrack.json"),
instance.state.fs.read_text("zntrack.json"),
)
value = zntrack_dict[instance.name][self.name]

Expand Down

0 comments on commit 9fea13c

Please sign in to comment.