Skip to content

Commit bf50257

Browse files
committed
fix --layer-mode-prefix not work for -a files
1 parent 90be7ed commit bf50257

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ Details:
403403
1. Install packages with pip while first running, which means requirements will not be install into pyz file.
404404
17. `--ensure-pip`
405405
1. Add the ensurepip package to your pyz file, works for **embed-python**(windows) or other python versions without `pip` installed but `lazy-install` mode is enabled. [EXPERIMENTAL]
406-
18. all the other (or `unknown`) args will be used by "pip install"
406+
18. `--layer-mode`
407+
1. Layer mode for the `serverless` use case, `__main__.py / ensure_zipapps.py / activate_zipapps.py` files will not be set in this mode.
408+
2. `--layer-mode-prefix`
409+
1. Only work while `--layer-mode` is set, will move the files in the given prefix folder.
410+
19. all the other (or `unknown`) args will be used by `pip install`
407411
1. such as `-r requirements.txt`
408412
2. such as `bottle aiohttp`
409413
3. the `pip_args` arg of `zipapps.create_app`

changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
# Changelogs
33

4+
- 2021.09.22
5+
- fix `--layer-mode-prefix` not work for `-a` files
46
- 2021.09.21
57
- `layer-mode` for serverless layers
68
- https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html

test_utils.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -459,12 +459,14 @@ def test_create_app_function():
459459

460460
# test layer-mode
461461
_clean_paths()
462-
old_file = create_app(layer_mode=True,
462+
old_file = create_app(includes='setup.py',
463+
layer_mode=True,
463464
layer_mode_prefix='python3',
464465
pip_args=['six'])
465466
from zipfile import ZipFile
466467
with ZipFile(old_file) as zf:
467-
assert zf.namelist() == ['python3/', 'python3/six.py']
468+
namelist = {'python3/', 'python3/setup.py', 'python3/six.py'}
469+
assert set(zf.namelist()) == namelist, zf.namelist()
468470

469471

470472
def main():

zipapps/__main__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def main():
202202
'--layer-mode-prefix',
203203
default='python',
204204
dest='layer_mode_prefix',
205-
help='Layer mode for the serverless use case, __main__.py / ensure_zipapps.py / activate_zipapps.py files will not be set in this mode.')
205+
help='Only work while --layer-mode is set, will move the files in the given prefix folder.')
206206
if len(sys.argv) == 1:
207207
return parser.print_help()
208208
args, pip_args = parser.parse_known_args()

zipapps/main.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from pkgutil import get_data
1616
from zipfile import ZIP_DEFLATED, ZIP_STORED, BadZipFile, ZipFile
1717

18-
__version__ = '2021.09.21'
18+
__version__ = '2021.09.22'
1919

2020

2121
class ZipApp(object):
@@ -91,6 +91,10 @@ def __init__(
9191
:type python_version_slice: int, optional
9292
:param ensure_pip: Add the ensurepip package to your pyz file, works for embed-python(windows) or other python versions without `pip` installed but `lazy-install` mode is enabled.
9393
:type includes: bool, optional
94+
:param layer_mode: Layer mode for the serverless use case, __main__.py / ensure_zipapps.py / activate_zipapps.py files will not be set in this mode, which means it will skip the activative process.
95+
:type includes: bool, optional
96+
:param layer_mode_prefix: Only work while --layer-mode is set, will move the files in the given prefix folder.
97+
:type includes: str, optional
9498
"""
9599
self.includes = includes
96100
self.cache_path = cache_path
@@ -348,14 +352,17 @@ def clean_pip_pycache(self):
348352
def prepare_includes(self):
349353
if not self.includes:
350354
return
355+
if self.layer_mode:
356+
_target_dir = self._cache_path.absolute() / self.layer_mode_prefix
357+
else:
358+
_target_dir = self._cache_path.absolute()
359+
_target_dir.mkdir(parents=True, exist_ok=True)
351360
for _include_path in self.includes.split(self.PATH_SPLIT_TAG):
352361
include_path = Path(_include_path)
353362
if include_path.is_dir():
354-
shutil.copytree(include_path,
355-
self._cache_path / include_path.name)
363+
shutil.copytree(include_path, _target_dir / include_path.name)
356364
elif include_path.is_file():
357-
shutil.copyfile(include_path,
358-
self._cache_path / include_path.name)
365+
shutil.copyfile(include_path, _target_dir / include_path.name)
359366
else:
360367
raise RuntimeError('%s is not exist' % include_path.absolute())
361368

0 commit comments

Comments
 (0)