Skip to content

Commit 3d96b77

Browse files
authored
Fix: Do not treat mount points as packages in the empack lock (#126)
* Fix: Do not treat mount points as packages in the empack lock * Iterate * Fix * Fixing tests * Fix
1 parent 434fade commit 3d96b77

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

empack/pack.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,17 +225,21 @@ def add_tarfile_to_env_meta(env_meta_filename, tarfile):
225225
)
226226

227227
tarfile_name = Path(tarfile).name
228-
package_item = {"name": tarfile_name, "filename": tarfile_name}
229-
# check that the package is not already in the list
230-
for pkg in env_meta["packages"]:
231-
if pkg["filename"] == tarfile_name:
232-
msg = f"package with filename '{tarfile_name}' already in env meta file"
228+
mount_point_item = {"name": tarfile_name, "filename": tarfile_name}
229+
230+
if "mounts" not in env_meta:
231+
env_meta["mounts"] = []
232+
233+
# check that the mount point is not already in the list
234+
for mount_point in env_meta["mounts"]:
235+
if mount_point["filename"] == tarfile_name:
236+
msg = f"mount point with filename '{tarfile_name}' already in env meta file"
233237
raise RuntimeError(msg)
234-
if pkg["name"] == package_item["name"]:
235-
msg = f"package with name '{package_item['name']}' already in env meta file"
238+
if mount_point["name"] == mount_point_item["name"]:
239+
msg = f"mount point with name '{mount_point_item['name']}' already in env meta file"
236240
raise RuntimeError(msg)
237241

238-
env_meta["packages"].append(package_item)
242+
env_meta["mounts"].append(mount_point_item)
239243
with open(env_meta_filename, "w") as f:
240244
json.dump(env_meta, f, indent=4)
241245

tests/test_cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,19 @@ def test_pack_env(self, tmp_path, use_cache):
8282
print(result.stdout)
8383
assert result.exit_code == 0
8484

85-
# check that there is a json with all the packages
85+
# check that there is a json in the output
8686
env_metadata_json_path = tmp_path / "empack_env_meta.json"
8787
assert env_metadata_json_path.exists()
8888

89+
# check the mount point is defined in the lock file
8990
with open(env_metadata_json_path) as f:
9091
env_meta = json.load(f)
92+
mount_points = env_meta["mounts"]
9193
packages = env_meta["packages"]
9294
env_meta_dict = dict()
9395

96+
for pkg in mount_points:
97+
env_meta_dict[pkg["name"]] = pkg
9498
for pkg in packages:
9599
env_meta_dict[pkg["name"]] = pkg
96100

tests/test_pack.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,16 +86,17 @@ def test_append(tmp_path):
8686
# append the directory to the env
8787
add_tarfile_to_env_meta(env_meta_filename=tmp_path, tarfile=tmp_path / "packaged_dir.tar.gz")
8888

89-
# check that there is a json with all the packages
89+
# check that there is a json in the output
9090
env_metadata_json_path = tmp_path / "empack_env_meta.json"
9191
assert env_metadata_json_path.exists()
9292

93+
# check the mount point is defined in the lock file
9394
with open(env_metadata_json_path) as f:
9495
env_meta = json.load(f)
95-
packages = env_meta["packages"]
96+
mount_points = env_meta["mounts"]
9697
env_meta_dict = dict()
9798

98-
for pkg in packages:
99+
for pkg in mount_points:
99100
env_meta_dict[pkg["filename"]] = pkg
100101

101102
assert "packaged_dir.tar.gz" in env_meta_dict

0 commit comments

Comments
 (0)