List command for manylinux images

This commit is contained in:
Valentin Niess
2023-11-08 18:06:02 +01:00
parent db5d91e0dd
commit e596fec38b
3 changed files with 56 additions and 3 deletions

View File

@@ -75,6 +75,11 @@ def main():
action='store_true',
default=False)
list_parser = subparsers.add_parser('list',
description='List Python versions installed in a manylinux image')
list_parser.add_argument('tag',
help='manylinux image tag (e.g. 2010_x86_64)')
which_parser = subparsers.add_parser('which',
description='Locate a binary dependency')
which_parser.add_argument('binary', choices=binaries,

View File

@@ -0,0 +1,41 @@
import os
from ..utils.docker import docker_run
from ..utils.log import log
from ..utils.tmp import TemporaryDirectory
__all__ = ['execute']
def _unpack_args(args):
'''Unpack command line arguments
'''
return (args.tag,)
def execute(tag):
'''List python versions installed in a manylinux image
'''
with TemporaryDirectory() as tmpdir:
script = (
'for dir in $(ls /opt/python | grep "^cp[0-9]"); do',
' version=$(/opt/python/$dir/bin/python -c "import sys; ' \
'sys.stdout.write(sys.version.split()[0])")',
' echo "$dir $version"',
'done',
)
if tag.startswith('2_'):
image = 'manylinux_' + tag
else:
image = 'manylinux' + tag
result = docker_run(
'quay.io/pypa/' + image,
script,
capture = True
)
for line in result.split(os.linesep):
if line:
log('LIST', "{1:7} -> /opt/python/{0:}".format(
*line.split()))

View File

@@ -4,11 +4,12 @@ import stat
import subprocess
import sys
from .compat import decode
from .log import log
from .system import system
def docker_run(image, extra_cmds):
def docker_run(image, extra_cmds, capture=False):
'''Execute commands within a docker container
'''
@@ -42,10 +43,16 @@ def docker_run(image, extra_cmds):
'type=bind,source={:},target=/pwd'.format(os.getcwd()),
image, '/bin/bash', bash_arg))
if capture:
opts = {'stderr': subprocess.PIPE, 'stdout': subprocess.PIPE}
else:
opts = {}
log('RUN', image)
p = subprocess.Popen(cmd, shell=True)
p.communicate()
p = subprocess.Popen(cmd, shell=True, **opts)
r = p.communicate()
if p.returncode != 0:
if p.returncode == 139:
sys.stderr.write("segmentation fault when running Docker (139)\n")
sys.exit(p.returncode)
if capture:
return decode(r[0])