Fix project pull and push

This commit is contained in:
Matthew Honnibal 2020-09-04 21:15:55 +02:00
parent b3e338d65e
commit 465785a672
2 changed files with 12 additions and 2 deletions

View File

@ -40,5 +40,6 @@ def project_pull(project_dir: Path, remote: str, *, verbose: bool = False):
url = storage.pull(output_path, command_hash=cmd_hash) url = storage.pull(output_path, command_hash=cmd_hash)
yield url, output_path yield url, output_path
if cmd.get("outputs") and all(loc.exists() for loc in cmd["outputs"]): out_locs = [project_dir / out for out in cmd.get("outputs", [])]
if all(loc.exists() for loc in out_locs):
update_lockfile(project_dir, cmd) update_lockfile(project_dir, cmd)

View File

@ -45,10 +45,19 @@ def project_push(project_dir: Path, remote: str):
) )
for output_path in cmd.get("outputs", []): for output_path in cmd.get("outputs", []):
output_loc = project_dir / output_path output_loc = project_dir / output_path
if output_loc.exists(): if output_loc.exists() and _is_not_empty_dir(output_loc):
url = storage.push( url = storage.push(
output_path, output_path,
command_hash=cmd_hash, command_hash=cmd_hash,
content_hash=get_content_hash(output_loc), content_hash=get_content_hash(output_loc),
) )
yield output_path, url yield output_path, url
def _is_not_empty_dir(loc: Path):
if not loc.is_dir():
return True
elif any(_is_not_empty_dir(child) for child in loc.iterdir()):
return True
else:
return False