Skip to content

Commit 70bcff5

Browse files
committed
Merge branch 'release-0.0.2'
2 parents 1e29798 + f4802d5 commit 70bcff5

File tree

9 files changed

+80
-28
lines changed

9 files changed

+80
-28
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
'test py38 dev':
2323
<<: *job_test_common
24+
allow_failure: true
2425
image: 'python:3.8-rc'
2526
variables:
2627
'TOXENV': 'py38'

CHANGELOG.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,19 @@
22
33

44
.. Keep the current version number on line number 5
5+
0.0.2
6+
==========
7+
8+
2019-06-11
9+
10+
* Code refactored for easier usage as a library
11+
12+
513
0.0.1
614
=====
715

16+
2019-05-07
17+
818
Initial version
919

1020

Makefile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ develop:
1414

1515

1616
.PHONY: package
17-
package: sdist wheel check zapp
17+
package: sdist wheel zapp
1818

1919

2020
.PHONY: sdist
2121
sdist:
2222
python3 setup.py sdist
23+
python3 -m twine check dist/*.tar.gz
2324

2425

2526
.PHONY: wheel
2627
wheel:
2728
python3 setup.py bdist_wheel
29+
python3 -m twine check dist/*.whl
2830

2931

3032
.PHONY: zapp
@@ -33,9 +35,8 @@ zapp:
3335

3436

3537
.PHONY: check
36-
check: sdist wheel
37-
python3 -m twine check dist/*.tar.gz
38-
python3 -m twine check dist/*.whl
38+
check:
39+
python3 setup.py check
3940

4041

4142
.PHONY: lint
@@ -63,7 +64,7 @@ pytest:
6364

6465

6566
.PHONY: review
66-
review:
67+
review: check
6768
python3 -m pytest --pep8 --pylint
6869

6970

README.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,41 @@ Standalone application
1515

1616
.. code::
1717
18-
zapp myapp.pyz myapp.core:main myapp
18+
zapp ~/bin/myapp myapp.cli:main 'myapp==1.2.3' 'mylib==3.2.1'
19+
20+
python3 -m zapp ~/bin/myapp myapp.cli:main 'myapp==1.2.3' 'mylib==3.2.1'
21+
22+
zapp toolmaker.pyz toolmaker.cli:main toolmaker
23+
zapp pipdeptree.pyz pipdeptree:main pipdeptree
24+
zapp ~/bin/httpie httpie.__main__:main httpie
25+
26+
# Without requirements
27+
zapp zipfile.pyz zipfile:main
28+
29+
30+
Library
31+
-------
32+
33+
.. code::
34+
35+
import zapp
36+
37+
zapp.core.build_zapp(
38+
[
39+
'myapp==1.2.3',
40+
'mylib==3.2.1',
41+
],
42+
'myapp.cli:main',
43+
'myapp.pyz',
44+
)
1945
2046
2147
Setuptools command
2248
------------------
2349

2450
.. code::
2551
26-
python3 setup.py bdist_zapp --entry-point myapp.core:main
52+
python3 setup.py bdist_zapp --entry-point myapp.cli:main
2753
2854
2955
Details

setup.cfg

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,32 @@
11
#
22

33

4+
[bdist_zapp]
5+
entry_point = zapp.cli:main
6+
7+
8+
[check]
9+
metadata = 1
10+
strict = 1
11+
12+
413
[metadata]
514
name = zapp
615
author = sinoroc
716
author_email = sinoroc.code+python@gmail.com
817
description = zapp application
918
license = Apache-2.0
1019
long_description = file: README.rst
20+
long_description_content_type = text/x-rst
1121
url = https://pypi.org/project/zapp
1222

1323

1424
[options]
1525
install_requires =
16-
setuptools
26+
importlib_metadata
1727
wheel
1828
package_dir =
19-
=src
29+
= src
2030
packages = find:
2131

2232

@@ -41,10 +51,6 @@ test =
4151
where = src
4252

4353

44-
[bdist_zapp]
45-
entry_point = zapp.cli:main
46-
47-
4854
[tool:pytest]
4955
addopts =
5056
--pylint-error-types='CEFIRW'

src/zapp/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
""" Module initializer """
55

66

7+
from . import core
78
from . import meta
89

910

src/zapp/cli.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66

77
import argparse
8-
import tempfile
98

109
from . import core
1110
from . import meta
@@ -22,10 +21,7 @@ def main():
2221
parser.add_argument('entry_point')
2322
parser.add_argument('requirements', metavar='requirement', nargs='*')
2423
args = parser.parse_args()
25-
with tempfile.TemporaryDirectory() as install_dir:
26-
if args.requirements:
27-
core.install_to_dir(install_dir, args.requirements)
28-
core.build_zipapp(install_dir, args.entry_point, args.output_file)
24+
core.build_zapp(args.requirements, args.entry_point, args.output_file)
2925

3026

3127
# EOF

src/zapp/core.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def _venv_create(venv_dir):
3232
return venv_context
3333

3434

35-
def install_to_dir(target_dir, requirements):
35+
def _install_to_dir(target_dir, requirements):
3636
""" Use pip to install the requirements into a specific directory
3737
"""
3838
# pip is not usable as a library, so it is much simpler and safer to just
@@ -48,9 +48,7 @@ def install_to_dir(target_dir, requirements):
4848
subprocess.run(command)
4949

5050

51-
def build_zipapp(source_dir, entry_point, output_file):
52-
""" Build the 'zipapp' file
53-
"""
51+
def _create_zipapp_archive(source_dir, entry_point, output_file):
5452
zipapp.create_archive(
5553
source_dir,
5654
interpreter='/usr/bin/env python3',
@@ -59,6 +57,15 @@ def build_zipapp(source_dir, entry_point, output_file):
5957
)
6058

6159

60+
def build_zapp(requirements, entry_point, output_file):
61+
""" Build a zapp binary archive
62+
"""
63+
with tempfile.TemporaryDirectory() as install_dir:
64+
if requirements:
65+
_install_to_dir(install_dir, requirements)
66+
_create_zipapp_archive(install_dir, entry_point, output_file)
67+
68+
6269
class bdist_zapp(setuptools.Command): # pylint: disable=invalid-name
6370
""" Custom 'setuptools' command to build a zipapp
6471
"""
@@ -93,12 +100,12 @@ class bdist_zapp(setuptools.Command): # pylint: disable=invalid-name
93100
'keep-temp',
94101
]
95102

96-
def __init__(self, *argv, **kwargs):
103+
def __init__(self, *args, **kwargs):
97104
self.bdist_dir = None
98105
self.dist_dir = None
99106
self.entry_point = None
100107
self.keep_temp = 0
101-
super().__init__(*argv, **kwargs)
108+
super().__init__(*args, **kwargs)
102109

103110
def initialize_options(self):
104111
""" Override """
@@ -153,9 +160,13 @@ def run(self):
153160
raise distutils.errors.DistutilsInternalError(
154161
"can not find bdist_wheel",
155162
)
156-
install_to_dir(self.bdist_dir, [dist_file])
163+
_install_to_dir(self.bdist_dir, [dist_file])
157164
self.mkpath(self.dist_dir)
158-
build_zipapp(self.bdist_dir, self.entry_point, output_file)
165+
_create_zipapp_archive(
166+
self.bdist_dir,
167+
self.entry_point,
168+
output_file,
169+
)
159170
if not self.keep_temp:
160171
distutils.dir_util.remove_tree(
161172
self.bdist_dir,

src/zapp/meta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
""" Meta information """
55

66

7-
import pkg_resources
7+
import importlib_metadata
88

99

10-
VERSION = pkg_resources.get_distribution('zapp').version
10+
VERSION = importlib_metadata.version('zapp')
1111

1212

1313
# EOF

0 commit comments

Comments
 (0)