Skip to content

Commit 32bb68a

Browse files
committed
add example test_lib_versions
1 parent 544a586 commit 32bb68a

File tree

4 files changed

+92
-7
lines changed

4 files changed

+92
-7
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
# Changelogs
33

44

5+
- 2021.03.02
6+
- fix #16 pip import at old version
7+
- add environment variable `CLEAR_ZIPAPPS_CACHE` for arg `clear_zipapps_cache`
8+
- `zipapps.create_app` now has the exact parameters
59
- 2021.02.27
610
- add `--unzip-exclude, -ue`
711
- The opposite of `--unzip` / `-u` which will not be unzipped, should be used with `--unzip` / `-u`.

examples/test_lib_versions.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import zipapps
2+
import sys
3+
4+
zipapps.ZipApp.LOGGING = False
5+
6+
7+
def test_six_1_16():
8+
app = zipapps.ZipApp(pip_args=['six==1.16.0', '-q'],
9+
output='six_16.pyz').build()
10+
sys.path.insert(0, app.as_posix())
11+
sys.modules.pop('six', None)
12+
import six
13+
print(six.__file__)
14+
assert 'six_16.pyz' in six.__file__
15+
app.unlink()
16+
17+
18+
def test_six_1_15():
19+
app = zipapps.ZipApp(pip_args=['six==1.15.0', '-q'],
20+
output='six_15.pyz').build()
21+
sys.path.insert(0, app.as_posix())
22+
sys.modules.pop('six', None)
23+
import six
24+
print(six.__file__)
25+
assert 'six_15.pyz' in six.__file__
26+
app.unlink()
27+
28+
29+
def main():
30+
test_six_1_16()
31+
test_six_1_15()
32+
33+
34+
if __name__ == "__main__":
35+
main()

zipapps/ensure_zipapps_template.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
pip_args_md5 = '{pip_args_md5}'
2121
py_version = '.'.join(map(str, sys.version_info[:{python_version_slice}]))
2222
_new_sys_paths = r'''{sys_paths}'''.strip()
23-
clear_zipapps_cache = os.environ.get('CLEAR_ZIPAPPS_CACHE') or {
24-
clear_zipapps_cache
25-
}
23+
clear_zipapps_cache = os.environ.get('CLEAR_ZIPAPPS_CACHE') or {clear_zipapps_cache}
2624

2725

2826
def ensure_path(path):

zipapps/main.py

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,8 +433,57 @@ def get_build_id_name(self):
433433
return f'_build_id_{md5_id}'
434434

435435
@classmethod
436-
def create_app(cls, *args, **kwargs):
437-
app = cls(*args, **kwargs)
436+
def create_app(
437+
cls,
438+
includes: str = '',
439+
cache_path: str = None,
440+
main: str = '',
441+
output: str = None,
442+
interpreter: str = None,
443+
compressed: bool = False,
444+
shell: bool = False,
445+
unzip: str = '',
446+
unzip_path: str = '',
447+
ignore_system_python_path=False,
448+
main_shell=False,
449+
pip_args: list = None,
450+
compiled: bool = False,
451+
build_id: str = '',
452+
env_paths: str = '',
453+
lazy_install: bool = False,
454+
sys_paths: str = '',
455+
python_version_slice: int = 2,
456+
ensure_pip: bool = False,
457+
layer_mode: bool = False,
458+
layer_mode_prefix: str = 'python',
459+
clear_zipapps_cache: bool = False,
460+
unzip_exclude: str = '',
461+
):
462+
app = cls(
463+
includes=includes,
464+
cache_path=cache_path,
465+
main=main,
466+
output=output,
467+
interpreter=interpreter,
468+
compressed=compressed,
469+
shell=shell,
470+
unzip=unzip,
471+
unzip_path=unzip_path,
472+
ignore_system_python_path=ignore_system_python_path,
473+
main_shell=main_shell,
474+
pip_args=pip_args,
475+
compiled=compiled,
476+
build_id=build_id,
477+
env_paths=env_paths,
478+
lazy_install=lazy_install,
479+
sys_paths=sys_paths,
480+
python_version_slice=python_version_slice,
481+
ensure_pip=ensure_pip,
482+
layer_mode=layer_mode,
483+
layer_mode_prefix=layer_mode_prefix,
484+
clear_zipapps_cache=clear_zipapps_cache,
485+
unzip_exclude=unzip_exclude,
486+
)
438487
return app.build()
439488

440489
@classmethod
@@ -455,5 +504,4 @@ def __del__(self):
455504
self._log(f'[ERROR]: {"=" * 10} Build failed {"=" * 10}')
456505

457506

458-
def create_app(*args, **kwargs):
459-
return ZipApp.create_app(*args, **kwargs)
507+
create_app = ZipApp.create_app

0 commit comments

Comments
 (0)