Skip to content

Commit

Permalink
Make resource override more lenient
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanluoyc committed Feb 12, 2024
1 parent c993a8c commit 908bff7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lxm3/xm_cluster/packaging/archive_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
import filecmp
import glob
import os
import shutil
Expand Down Expand Up @@ -74,9 +75,13 @@ def create_python_archive(
if not os.path.exists(target_file):
shutil.copy(src, target_file)
else:
raise ValueError(
"Additional resource overwrites existing file: %s", src
)
# Trying to override a file in the archive,
# check if the file contents are the same
if not filecmp.cmp(src, target_file):
# Raise if contents differ
raise ValueError(
"Additional resource overwrites existing file: %s", src
)

if os.path.exists(os.path.join(tmpdir, "bin")):
console.log('Removing "bin/" directory as these are not yet portable.')
Expand Down
26 changes: 26 additions & 0 deletions tests/packaging_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,32 @@ def test_package_python(self, pkg_fun):
)
self.assertIsInstance(executable, xm_cluster.Command)

# @parameterized.parameters((cluster._package_python_package,))
# def test_package_python_resource_overwrites(self, pkg_fun):
# resource = xm_cluster.Fileset(
# files={
# os.path.join(
# _HERE, "testdata/test_pkg/py_package/main.py"
# ): "py_package/main.py",
# }
# )
# spec = xm_cluster.PythonPackage(
# entrypoint=xm_cluster.ModuleName("py_package.main"),
# path=os.path.join(_HERE, "testdata/test_pkg"),
# resources=[resource],
# )

# tmpdir = self.create_tempdir().full_path
# store = artifacts.LocalArtifactStore(tmpdir, "test")
# pkg_fun(
# spec,
# xm.Packageable(
# spec,
# xm_cluster.Local().Spec(),
# ),
# store,
# )

def test_package_default_pip_args(self):
spec = xm_cluster.PythonPackage(
entrypoint=xm_cluster.ModuleName("py_package.main"),
Expand Down

0 comments on commit 908bff7

Please sign in to comment.