File: pyi_arbitrary_ext.foo

package info (click to toggle)
pyinstaller 6.18.0%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,820 kB
  • sloc: python: 41,828; ansic: 12,123; makefile: 171; sh: 131; xml: 19
file content (24 lines) | stat: -rw-r--r-- 1,017 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Verify that PyInstaller can load a script from a file with an arbitrary extension, not just from ``.py`` files.
#
# Also check that both `__file__` attribute and the `co_filename` attribute of the code object have correct suffix.
import os
import sys

print('Hello!')

# Look up and display all relevant attributes...
print(f"__file__: {__file__}")
loader = sys.modules[__name__].__loader__
print(f"loader: {loader}")
co = loader.get_code(__name__)
print(f"co_filename: {co.co_filename}")

# ... before validating them.
# We expect the original suffix to be found on both attributes.
# NOTE: alas, the PKG archive stores the entry-point script entries without suffix, and the bootloader currently has no
# way of restoring those, so it always sets the `__file__` attribute with .py suffix. For now, codify this behavior.
if getattr(sys, 'frozen', False):
    assert os.path.splitext(__file__)[1] == '.py'
else:
    assert os.path.splitext(__file__)[1] == '.foo'
assert os.path.splitext(co.co_filename)[1] == '.foo'