Skip to content

Commit

Permalink
Propagate fs between local targets in parent and child methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
riga committed Oct 17, 2022
1 parent 438212a commit fbba65c
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions law/target/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,12 @@ def __init__(self, path=None, fs=LocalFileSystem.default_instance, is_tmp=False,
# handle tmp paths manually since luigi uses the env tmp dir
if not path:
if not is_tmp:
raise Exception("either path or is_tmp must be set")
raise Exception("when no target path is defined, is_tmp must be set")
if fs.base != "/":
raise Exception(
"when is_tmp is set, the base of the underlying file system must be root, but "
"found '{}'".format(fs.base),
)

# if not set, get the tmp dir from the config and ensure that it exists
cfg = Config.instance()
Expand All @@ -345,11 +350,8 @@ def __init__(self, path=None, fs=LocalFileSystem.default_instance, is_tmp=False,
is_tmp = "." + is_tmp
path += is_tmp
else:
# ensure path is not a target and does not contain a scheme
path = fs._unscheme(get_path(path))
# make absolute when not starting with a variable
if not path.startswith(("$", "~")):
path = os.path.abspath(path)
# ensure path is not a target, does not contain a scheme and starts with /
path = os.path.join(os.sep, fs._unscheme(get_path(path)))

super(LocalTarget, self).__init__(path=path, is_tmp=is_tmp, fs=fs, **kwargs)

Expand All @@ -359,6 +361,11 @@ def _repr_flags(self):
flags.append("temporary")
return flags

def _parent_args(self):
args, kwargs = super(LocalTarget, self)._parent_args()
kwargs["fs"] = self.fs
return args, kwargs

def uri(self, scheme=True, return_all=False, **kwargs):
uri = self.fs.abspath(self.path)
if scheme:
Expand Down Expand Up @@ -447,7 +454,10 @@ def localize(self, mode="r", perm=None, dir_perm=None, tmp_dir=None, **kwargs):

class LocalDirectoryTarget(FileSystemDirectoryTarget, LocalTarget):

pass
def _child_args(self, path):
args, kwargs = super(LocalDirectoryTarget, self)._child_args(path)
kwargs["fs"] = self.fs
return args, kwargs


LocalTarget.file_class = LocalFileTarget
Expand Down

0 comments on commit fbba65c

Please sign in to comment.