From ee8502c76d55b557feb0fbab3b965f9da9f83a2e Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 27 Jun 2025 09:32:00 +0200 Subject: [PATCH 1/5] Fix: Do not treat mount points as packages in the empack lock --- empack/pack.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/empack/pack.py b/empack/pack.py index a4292e8..1331e92 100644 --- a/empack/pack.py +++ b/empack/pack.py @@ -226,16 +226,20 @@ def add_tarfile_to_env_meta(env_meta_filename, tarfile): tarfile_name = Path(tarfile).name package_item = {"name": tarfile_name, "filename": tarfile_name} + + if not env_meta["mounts"]: + env_meta["mounts"] = [] + # check that the package is not already in the list - for pkg in env_meta["packages"]: + for pkg in env_meta["mounts"]: if pkg["filename"] == tarfile_name: - msg = f"package with filename '{tarfile_name}' already in env meta file" + 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" + msg = f"mount point with name '{package_item['name']}' already in env meta file" raise RuntimeError(msg) - env_meta["packages"].append(package_item) + env_meta["mounts"].append(package_item) with open(env_meta_filename, "w") as f: json.dump(env_meta, f, indent=4) From 9ceda691c87544538f67fed739f38dfc952bed61 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 27 Jun 2025 09:34:25 +0200 Subject: [PATCH 2/5] Iterate --- empack/pack.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/empack/pack.py b/empack/pack.py index 1331e92..d77973c 100644 --- a/empack/pack.py +++ b/empack/pack.py @@ -225,21 +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} + mount_point_item = {"name": tarfile_name, "filename": tarfile_name} if not env_meta["mounts"]: env_meta["mounts"] = [] - # check that the package is not already in the list + # check that the mount point is not already in the list for pkg in env_meta["mounts"]: if pkg["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"mount point with name '{package_item['name']}' already in env meta file" + if pkg["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["mounts"].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) From 705ece9c03f870412fc8d48441ef10bff35c7d6a Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 27 Jun 2025 09:39:29 +0200 Subject: [PATCH 3/5] Fix --- empack/pack.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/empack/pack.py b/empack/pack.py index d77973c..2f37228 100644 --- a/empack/pack.py +++ b/empack/pack.py @@ -227,7 +227,7 @@ def add_tarfile_to_env_meta(env_meta_filename, tarfile): tarfile_name = Path(tarfile).name mount_point_item = {"name": tarfile_name, "filename": tarfile_name} - if not env_meta["mounts"]: + if "mounts" not in env_meta: env_meta["mounts"] = [] # check that the mount point is not already in the list From 8d85c46bbe36d16ef46eceec3e5e38f4023008c7 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 27 Jun 2025 09:48:24 +0200 Subject: [PATCH 4/5] Fixing tests --- tests/test_cli.py | 8 ++++++-- tests/test_pack.py | 7 ++++--- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index cc266ff..28c2f2c 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -82,17 +82,21 @@ 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["filename"]] = pkg for pkg in packages: - env_meta_dict[pkg["name"]] = pkg + env_meta_dict[pkg["filename"]] = pkg assert "packaged_dir.tar.gz" in env_meta_dict assert "numpy" in env_meta_dict 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 From 80943836c63b84fd6de202a31f8708dd212e2428 Mon Sep 17 00:00:00 2001 From: martinRenou Date: Fri, 27 Jun 2025 10:16:04 +0200 Subject: [PATCH 5/5] Fix --- empack/pack.py | 6 +++--- tests/test_cli.py | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/empack/pack.py b/empack/pack.py index 2f37228..e4440b9 100644 --- a/empack/pack.py +++ b/empack/pack.py @@ -231,11 +231,11 @@ def add_tarfile_to_env_meta(env_meta_filename, tarfile): env_meta["mounts"] = [] # check that the mount point is not already in the list - for pkg in env_meta["mounts"]: - if pkg["filename"] == tarfile_name: + 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"] == mount_point_item["name"]: + 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) diff --git a/tests/test_cli.py b/tests/test_cli.py index 28c2f2c..67453de 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -94,9 +94,9 @@ def test_pack_env(self, tmp_path, use_cache): env_meta_dict = dict() for pkg in mount_points: - env_meta_dict[pkg["filename"]] = pkg + env_meta_dict[pkg["name"]] = pkg for pkg in packages: - env_meta_dict[pkg["filename"]] = pkg + env_meta_dict[pkg["name"]] = pkg assert "packaged_dir.tar.gz" in env_meta_dict assert "numpy" in env_meta_dict