Skip to content

Commit

Permalink
Fix missing zipapp param in old Python versions.
Browse files Browse the repository at this point in the history
  • Loading branch information
seizethedave committed Jan 30, 2024
1 parent 71d9aa2 commit 7ecdf70
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions cattle/cattle_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,20 @@ def add_filter(item: tarfile.TarInfo):
tar.add(cfg_dir, arcname="config", recursive=True, filter=add_filter)
return t.name

def _make_zipapp_archive(**kwargs):
"""
Work around Py3.6's zipapp.create_archive that didn't yet have a `filter`
param.
"""
try:
zipapp.create_archive(filter="foo")
except TypeError:
try:
del kwargs["filter"]
except KeyError:
pass
zipapp.create_archive(**kwargs)

def make_executable():
this_file = pathlib.Path(__file__)
exclude = {this_file.name, "test_cattle.py"}
Expand All @@ -41,8 +55,8 @@ def should_include(p: pathlib.Path) -> bool:
)

with tempfile.NamedTemporaryFile(prefix="cattle_runtime_", delete=False) as t:
zipapp.create_archive(
this_file.absolute().parent,
_make_zipapp_archive(
source=this_file.absolute().parent,
target=t,
main="cattle_remote:main",
filter=should_include,
Expand Down

0 comments on commit 7ecdf70

Please sign in to comment.