Skip to content

Commit eb05b77

Browse files
committed
Update the list command
1 parent fa3ec89 commit eb05b77

8 files changed

Lines changed: 49 additions & 119 deletions

File tree

‎python_appimage/commands/build/manylinux.py‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
import shutil
44

55
from ...appimage import build_appimage
6-
from ...manylinux import Arch, Downloader, ImageExtractor, LinuxTag, \
7-
PythonExtractor
6+
from ...manylinux import ensure_image, PythonExtractor
87
from ...utils.tmp import TemporaryDirectory
98

109

@@ -21,21 +20,13 @@ def execute(tag, abi):
2120
'''Build a Python AppImage using a Manylinux image
2221
'''
2322

24-
tag, arch = tag.split('_', 1)
25-
tag = LinuxTag.from_brief(tag)
26-
arch = Arch.from_str(arch)
27-
28-
downloader = Downloader(tag=tag, arch=arch)
29-
downloader.download()
30-
31-
image_extractor = ImageExtractor(downloader.default_destination())
32-
image_extractor.extract()
23+
image = ensure_image(tag)
3324

3425
pwd = os.getcwd()
3526
with TemporaryDirectory() as tmpdir:
3627
python_extractor = PythonExtractor(
37-
arch = arch,
38-
prefix = image_extractor.default_destination(),
28+
arch = image.arch,
29+
prefix = image.path,
3930
tag = abi
4031
)
4132
appdir = Path(tmpdir) / 'AppDir'
@@ -44,15 +35,15 @@ def execute(tag, abi):
4435
fullname = '-'.join((
4536
f'{python_extractor.impl}{python_extractor.version.long()}',
4637
abi,
47-
f'{tag}_{arch}'
38+
f'{image.tag}_{image.arch}'
4839
))
4940

5041
destination = f'{fullname}.AppImage'
5142
build_appimage(
5243
appdir = str(appdir),
5344
destination = destination
5445
)
55-
shutil.move(
46+
shutil.copy(
5647
Path(tmpdir) / destination,
5748
Path(pwd) / destination
5849
)

‎python_appimage/commands/list.py‎

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import os
1+
import glob
2+
from pathlib import Path
23

3-
from ..utils.docker import docker_run
4+
from ..manylinux import ensure_image, PythonVersion
45
from ..utils.log import log
5-
from ..utils.tmp import TemporaryDirectory
66

77

88
__all__ = ['execute']
@@ -18,26 +18,16 @@ def execute(tag):
1818
'''List python versions installed in a manylinux image
1919
'''
2020

21-
with TemporaryDirectory() as tmpdir:
22-
script = (
23-
'for dir in $(ls /opt/python | grep "^cp[0-9]"); do',
24-
' version=$(/opt/python/$dir/bin/python -c "import sys; ' \
25-
'sys.stdout.write(sys.version.split()[0])")',
26-
' echo "$dir $version"',
27-
'done',
28-
)
29-
if tag.startswith('2_'):
30-
image = 'manylinux_' + tag
31-
else:
32-
image = 'manylinux' + tag
33-
result = docker_run(
34-
'quay.io/pypa/' + image,
35-
script,
36-
capture = True
37-
)
38-
pythons = [line.split() for line in result.split(os.linesep) if line]
39-
40-
for (abi, version) in pythons:
41-
log('LIST', "{:7} -> /opt/python/{:}".format(version, abi))
42-
43-
return pythons
21+
image = ensure_image(tag)
22+
23+
pythons = []
24+
for path in glob.glob(str(image.path / 'opt/python/cp*')):
25+
path = Path(path)
26+
version = PythonVersion.from_str(path.readlink().name[8:]).long()
27+
pythons.append((path.name, version))
28+
pythons = sorted(pythons)
29+
30+
for (abi, version) in pythons:
31+
log('LIST', "{:8} -> /opt/python/{:}".format(version, abi))
32+
33+
return pythons
Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
1+
from types import SimpleNamespace
2+
13
from .config import Arch, LinuxTag, PythonImpl, PythonVersion
24
from .download import Downloader
35
from .extract import ImageExtractor, PythonExtractor
46

57

6-
__all__ = ['Arch', 'Downloader', 'ImageExtractor', 'LinuxTag',
8+
__all__ = ['Arch', 'Downloader', 'ensure_image', 'ImageExtractor', 'LinuxTag',
79
'PythonExtractor', 'PythonImpl', 'PythonVersion']
10+
11+
12+
def ensure_image(tag):
13+
'''Extract a manylinux image to the cache'''
14+
15+
tag, arch = tag.split('_', 1)
16+
tag = LinuxTag.from_brief(tag)
17+
arch = Arch.from_str(arch)
18+
19+
downloader = Downloader(tag=tag, arch=arch)
20+
downloader.download()
21+
22+
image_extractor = ImageExtractor(downloader.default_destination())
23+
image_extractor.extract()
24+
25+
return SimpleNamespace(
26+
arch = arch,
27+
tag = tag,
28+
path = image_extractor.default_destination(),
29+
)

‎python_appimage/manylinux/download.py‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ class DownloadError(Exception):
2222
pass
2323

2424

25-
class TarError(Exception):
26-
pass
27-
28-
2925
@dataclass(frozen=True)
3026
class Downloader:
3127

@@ -68,6 +64,7 @@ def download(
6864

6965
# Authenticate to quay.io.
7066
repository = f'pypa/{self.image}'
67+
log('PULL', f'{self.image}:{tag}')
7168
url = 'https://quay.io/v2/auth'
7269
url = f'{url}?service=quay.io&scope=repository:{repository}:pull'
7370
debug('GET', url)

‎python_appimage/manylinux/extract.py‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ def cleanup(destination):
346346
shutil.rmtree(destination, ignore_errors=True)
347347
atexit.register(cleanup, destination)
348348

349+
log('EXTRACT', f'{self.prefix.name}:{self.tag}')
350+
349351
with open(self.prefix / f'tags/{self.tag}.json') as f:
350352
meta = json.load(f)
351353
layers = meta['layers']

‎python_appimage/utils/docker.py‎

Lines changed: 0 additions & 58 deletions
This file was deleted.

‎python_appimage/utils/manylinux.py‎

Lines changed: 0 additions & 14 deletions
This file was deleted.

‎scripts/test-appimage.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def list_content(path=None):
162162

163163
# Test SSL (see issue #24).
164164
if version.major > 2:
165-
Script(f'''
165+
Script('''
166166
from http import HTTPStatus
167167
import urllib.request
168168
with urllib.request.urlopen('https://wikipedia.org') as r:

0 commit comments

Comments
 (0)