Repository navigation
Expand file tree
/
Copy pathpython3.yaml
More file actions
executable file
·81 lines (69 loc) · 2.87 KB
/
Copy pathpython3.yaml
File metadata and controls
executable file
·81 lines (69 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
schemaVersion: "1.0.0"
commandTests:
- name: hello
command: ["/usr/bin/python3", "-c", "print('Hello World')"]
expectedOutput: ['Hello World']
# ensure there is no shell
- name: no_shell
command: ["/usr/bin/python3", "-c",
"import subprocess, sys; subprocess.check_call(sys.executable + ' -h', shell=True)"]
exitCode: 1
# debian's default python3 includes a partial version of distutils causing virtualenv to fail
# ensure we have the full version so virtualenvs work with distroless
- name: distutils_works
command: ["/usr/bin/python3", "-c", "import distutils.dist"]
exitCode: 0
# file names are UTF-8: default for modern Linux systems
# The \xe9 backslash must be double-escaped to avoid YAML string parsing weirdness
- name: filesystem_utf8
command: ["/usr/bin/python3", "-c", "open(u'h\\xe9llo', 'w'); import sys; print(sys.getfilesystemencoding())"]
expectedOutput: ['utf-8']
# the print function should output UTF-8
- name: print_utf8
command: ["/usr/bin/python3", "-c", "print(u'h\\xe9llo.txt')"]
expectedOutput: ['h\xe9llo']
# import every module installed with the Python package
- name: import_everything
exitCode: 0
expectedOutput: ['FINISHED ENTIRE SCRIPT']
command:
- "/usr/bin/python3"
- "-c"
# multi-line YAML string with Python script that imports all modules that are installed.
# This ensures we have the right native library dependencies.
- |
import pkgutil
skip_modules = frozenset((
# Windows-specific modules
'asyncio.windows_events',
'asyncio.windows_utils',
'ctypes.wintypes',
'distutils._msvccompiler',
'distutils.command.bdist_msi',
'distutils.msvc9compiler',
'encodings.cp65001',
'encodings.mbcs',
'encodings.oem',
'multiprocessing.popen_spawn_win32',
'winreg',
# Python regression tests "for internal use by Python only"
'test',
# calls sys.exit
'unittest.__main__',
'venv.__main__',
# depends on things not installed by default on Debian
'dbm.gnu',
'lib2to3.pgen2.conv',
'turtle',
))
# pass an error handler so the test fails if there are broken standard library packages
def walk_packages_onerror(failed_module_name):
raise Exception('failed to import module: {}'.format(repr(failed_module_name)))
for module_info in pkgutil.walk_packages(onerror=walk_packages_onerror):
module_name = module_info.name
if module_name in skip_modules or module_name.startswith('test.'):
continue
__import__(module_name)
print('imported {}'.format(module_name))
# ensures some module does not exit early (e.g unittest.__main__)
print('FINISHED ENTIRE SCRIPT')