diff --git a/empack/pack.py b/empack/pack.py index a4292e8..e4440b9 100644 --- a/empack/pack.py +++ b/empack/pack.py @@ -225,17 +225,21 @@ def add_tarfile_to_env_meta(env_meta_filename, tarfile): ) tarfile_name = Path(tarfile).name - package_item = {"name": tarfile_name, "filename": tarfile_name} - # check that the package is not already in the list - for pkg in env_meta["packages"]: - if pkg["filename"] == tarfile_name: - msg = f"package with filename '{tarfile_name}' already in env meta file" + mount_point_item = {"name": tarfile_name, "filename": tarfile_name} + + if "mounts" not in env_meta: + env_meta["mounts"] = [] + + # check that the mount point is not already in the list + for mount_point in env_meta["mounts"]: + if mount_point["filename"] == tarfile_name: + msg = f"mount point with filename '{tarfile_name}' already in env meta file" raise RuntimeError(msg) - if pkg["name"] == package_item["name"]: - msg = f"package with name '{package_item['name']}' already in env meta file" + if mount_point["name"] == mount_point_item["name"]: + msg = f"mount point with name '{mount_point_item['name']}' already in env meta file" raise RuntimeError(msg) - env_meta["packages"].append(package_item) + env_meta["mounts"].append(mount_point_item) with open(env_meta_filename, "w") as f: json.dump(env_meta, f, indent=4) diff --git a/tests/test_cli.py b/tests/test_cli.py index cc266ff..67453de 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -82,15 +82,19 @@ def test_pack_env(self, tmp_path, use_cache): print(result.stdout) assert result.exit_code == 0 - # check that there is a json with all the packages + # check that there is a json in the output env_metadata_json_path = tmp_path / "empack_env_meta.json" assert env_metadata_json_path.exists() + # check the mount point is defined in the lock file with open(env_metadata_json_path) as f: env_meta = json.load(f) + mount_points = env_meta["mounts"] packages = env_meta["packages"] env_meta_dict = dict() + for pkg in mount_points: + env_meta_dict[pkg["name"]] = pkg for pkg in packages: env_meta_dict[pkg["name"]] = pkg diff --git a/tests/test_pack.py b/tests/test_pack.py index 0df594f..f3f6cd0 100644 --- a/tests/test_pack.py +++ b/tests/test_pack.py @@ -86,16 +86,17 @@ def test_append(tmp_path): # append the directory to the env add_tarfile_to_env_meta(env_meta_filename=tmp_path, tarfile=tmp_path / "packaged_dir.tar.gz") - # check that there is a json with all the packages + # check that there is a json in the output env_metadata_json_path = tmp_path / "empack_env_meta.json" assert env_metadata_json_path.exists() + # check the mount point is defined in the lock file with open(env_metadata_json_path) as f: env_meta = json.load(f) - packages = env_meta["packages"] + mount_points = env_meta["mounts"] env_meta_dict = dict() - for pkg in packages: + for pkg in mount_points: env_meta_dict[pkg["filename"]] = pkg assert "packaged_dir.tar.gz" in env_meta_dict