Skip to content

Commit

Permalink
remove empty dirs in link path
Browse files Browse the repository at this point in the history
  • Loading branch information
ajberdy committed Oct 14, 2023
1 parent 6bc5750 commit 2d4ab33
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/braket/jobs/_entry_point_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def make_link(input_link_path, input_data_path, links):
def link_input():
links = {{}}
dirs = set()
# map of data sources to lists of matched local files
prefix_matches = {prefix_matches}
Expand Down Expand Up @@ -67,4 +68,12 @@ def clean_links(links):
for link, target in links.items():
if link.is_symlink and link.readlink() == target:
link.unlink()
if link.is_relative_to(Path()):
for dir in link.parents[:-1]:
try:
dir.rmdir()
except:
# directory not empty
pass
'''
9 changes: 5 additions & 4 deletions test/integ_tests/test_create_quantum_job.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def decorator_job(a, b: int, c=0, d: float = 1.0, **extras):
"extra_arg": "extra_value",
}

with open("output_file.txt", "w") as f:
with open("test/output_file.txt", "w") as f:
f.write("hello")

job = decorator_job(MyClass(), 2, d=5, extra_arg="extra_value")
Expand All @@ -237,12 +237,13 @@ def decorator_job(a, b: int, c=0, d: float = 1.0, **extras):
with tempfile.TemporaryDirectory() as temp_dir:
os.chdir(temp_dir)
job.download_result()
with open(Path(job.name, "test", "output_file.txt"), "r") as f:
assert f.read() == "hello"
assert (
Path(job.name, "results.json").exists()
and not Path(job.name, "test", "integ_tests", "requirements.txt").exists()
and Path(job.name, "test").exists()
and not Path(job.name, "test", "integ_tests").exists()
)
with open(Path(job.name, "output_file.txt"), "r") as f:
assert f.read() == "hello"
os.chdir(current_dir)


Expand Down

0 comments on commit 2d4ab33

Please sign in to comment.