Skip to content

Commit 702e592

Browse files
committed
Merge branch 'release-0.0.6'
2 parents daf688d + f583658 commit 702e592

File tree

7 files changed

+96
-25
lines changed

7 files changed

+96
-25
lines changed

.gitlab-ci.yml

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,24 @@
11
---
22

33

4-
'.test_common': &job_test_common
4+
'.review':
55
script:
6+
- 'export TOXENV="${CI_JOB_NAME##review}"'
67
- 'python3 -m pip install tox'
78
- 'python3 -m tox'
89
- 'python3 -m tox -e package'
910

10-
'test py36':
11-
<<: *job_test_common
11+
'review py36':
12+
extends: '.review'
1213
image: 'python:3.6'
13-
variables:
14-
'TOXENV': 'py36'
1514

16-
'test py37':
17-
<<: *job_test_common
15+
'review py37':
16+
extends: '.review'
1817
image: 'python:3.7'
19-
variables:
20-
'TOXENV': 'py37'
18+
19+
'review py38':
20+
extends: '.review'
21+
image: 'python:3.8'
2122

2223

2324
... EOF

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ language: 'python'
88
python:
99
- '3.6'
1010
- '3.7'
11+
- '3.8'
1112

1213
install:
1314
- 'python3 -m pip install tox tox-travis tox-venv'

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
33

44
.. Keep the current version number on line number 5
5+
0.0.6
6+
=====
7+
8+
2020-03-30
9+
10+
* Add support for 'requirements.txt' files
11+
12+
513
0.0.5
614
=====
715

README.rst

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
Introduction
55
============
66

7-
Build ``zipapp`` single file Python applications easily.
7+
Build `zipapp`_ (`PEP 441`_) single file Python applications easily.
88

99

1010
Repositories
1111
------------
1212

13-
Binary distributions:
13+
Distributions:
1414

1515
* https://pypi.org/project/zapp/
1616

@@ -26,9 +26,26 @@ Usage
2626
Standalone application
2727
----------------------
2828

29+
.. code::
30+
31+
usage: zapp [-h] [--version] [--requirement requirements.txt]
32+
output_file entry_point [requirement [requirement ...]]
33+
34+
positional arguments:
35+
output_file
36+
entry_point
37+
requirement
38+
39+
optional arguments:
40+
-h, --help show this help message and exit
41+
--version show program's version number and exit
42+
--requirement requirements.txt, -r requirements.txt
43+
44+
2945
.. code::
3046
3147
zapp ~/bin/myapp myapp.cli:main 'myapp==1.2.3' 'mylib==3.2.1'
48+
zapp ~/bin/myapp myapp.cli:main --requirement requirements.txt
3249
3350
python3 -m zapp ~/bin/myapp myapp.cli:main 'myapp==1.2.3' 'mylib==3.2.1'
3451
@@ -48,12 +65,13 @@ Library
4865
import zapp
4966
5067
zapp.core.build_zapp(
51-
[
68+
'myapp.pyz', # output_file
69+
'myapp.cli:main', # entry_point
70+
requirements=[
5271
'myapp==1.2.3',
5372
'mylib==3.2.1',
5473
],
55-
'myapp.cli:main',
56-
'myapp.pyz',
74+
requirements_txt='requirements.txt',
5775
)
5876
5977
@@ -80,7 +98,9 @@ Similar applications
8098
8199
.. _`shiv`: https://pypi.org/project/shiv/
82100
.. _`pex`: https://pypi.org/project/pex/
101+
.. _`PEP 441`: https://www.python.org/dev/peps/pep-0441/
83102
.. _`superzippy`: https://pypi.org/project/superzippy/
103+
.. _`zipapp`: https://docs.python.org/3/library/zipapp.html
84104

85105

86106
.. EOF

src/zapp/cli.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,20 @@ def main():
2020
parser.add_argument('output_file')
2121
parser.add_argument('entry_point')
2222
parser.add_argument('requirements', metavar='requirement', nargs='*')
23+
parser.add_argument(
24+
'--requirement',
25+
'-r',
26+
dest='requirements_txt',
27+
metavar='requirements.txt',
28+
type=argparse.FileType(),
29+
)
2330
args = parser.parse_args()
24-
core.build_zapp(args.requirements, args.entry_point, args.output_file)
31+
core.build_zapp(
32+
args.output_file,
33+
args.entry_point,
34+
args.requirements,
35+
getattr(args.requirements_txt, 'name', None),
36+
)
2537

2638

2739
# EOF

src/zapp/core.py

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@
1414
import setuptools
1515

1616

17+
class ZappException(Exception):
18+
"""Base exception class"""
19+
20+
21+
class BdistWheelMissing(ZappException):
22+
"""The 'setuptools' command 'bdist_wheel' can not be found"""
23+
24+
1725
class _EnvBuilder(venv.EnvBuilder):
1826

1927
def __init__(self, *args, **kwargs):
@@ -32,27 +40,40 @@ def _venv_create(venv_dir):
3240
return venv_context
3341

3442

35-
def _pip_install(venv_context, requirements, target_dir=None):
43+
def _pip_install(
44+
venv_context,
45+
requirements=None,
46+
requirements_txt=None,
47+
target_dir=None,
48+
):
3649
command = [
3750
venv_context.env_exe,
3851
'-m', 'pip',
3952
'install',
4053
]
4154
if target_dir:
4255
command.extend(['--target', target_dir])
43-
command.extend(requirements)
56+
if requirements:
57+
command.extend(requirements)
58+
if requirements_txt:
59+
command.extend(['--requirement', requirements_txt])
4460
subprocess.check_call(command)
4561

4662

47-
def _install_to_dir(target_dir, requirements):
63+
def _install_to_dir(target_dir, requirements=None, requirements_txt=None):
4864
""" Use pip to install the requirements into a specific directory
4965
"""
5066
# pip is not usable as a library, so it is much simpler and safer to just
5167
# create a virtual environment and run a pip process from there
5268
with tempfile.TemporaryDirectory() as venv_dir:
5369
venv_context = _venv_create(venv_dir)
5470
_pip_install(venv_context, ['wheel'])
55-
_pip_install(venv_context, requirements, target_dir)
71+
_pip_install(
72+
venv_context,
73+
requirements=requirements,
74+
requirements_txt=requirements_txt,
75+
target_dir=target_dir,
76+
)
5677

5778

5879
def _create_zipapp_archive(source_dir, entry_point, output_file):
@@ -64,12 +85,21 @@ def _create_zipapp_archive(source_dir, entry_point, output_file):
6485
)
6586

6687

67-
def build_zapp(requirements, entry_point, output_file):
88+
def build_zapp(
89+
output_file,
90+
entry_point,
91+
requirements=None,
92+
requirements_txt=None,
93+
):
6894
""" Build a zapp binary archive
6995
"""
7096
with tempfile.TemporaryDirectory() as install_dir:
71-
if requirements:
72-
_install_to_dir(install_dir, requirements)
97+
if requirements or requirements_txt:
98+
_install_to_dir(
99+
install_dir,
100+
requirements=requirements,
101+
requirements_txt=requirements_txt,
102+
)
73103
_create_zipapp_archive(install_dir, entry_point, output_file)
74104

75105

@@ -164,9 +194,7 @@ def run(self):
164194
if dist[0] == 'bdist_wheel':
165195
dist_file = dist[2]
166196
if not dist_file:
167-
raise distutils.errors.DistutilsInternalError(
168-
"can not find bdist_wheel",
169-
)
197+
raise BdistWheelMissing()
170198
_install_to_dir(self.bdist_dir, [dist_file])
171199
self.mkpath(self.dist_dir)
172200
_create_zipapp_archive(

tox.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ requires =
1111

1212
[testenv]
1313
commands =
14+
python3 --version
1415
make review
1516
extras =
1617
test

0 commit comments

Comments
 (0)