Skip to content

File: Broken/__init__.py

Broken

Runtime

Information about the current runtime environment

Source code in Broken/__init__.py
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class Runtime:
    """Information about the current runtime environment"""

    Version: str = __version__
    """The version of the Broken library, and subsequently all projects"""

    # # Bitness

    Bitness: int = (struct.calcsize("P") * 8)
    """The word size of the Python interpreter (32, 64 bits)"""

    Python32: bool = (Bitness == 32)
    """True if running on a 32-bit Python interpreter"""

    Python64: bool = (Bitness == 64)
    """True if running on a 64-bit Python interpreter"""

    # # Runtime environments

    PyInstaller: bool = bool(getattr(sys, "frozen", False))
    """True if running from a PyInstaller binary build (https://github.com/pyinstaller/pyinstaller)"""

    Nuitka: bool = ("__compiled__" in globals())
    """True if running from a Nuitka binary build (https://github.com/Nuitka/Nuitka)"""

    PyApp: bool = bool(os.getenv("PYAPP", False))
    """True if running as a PyApp release (https://github.com/ofek/pyapp)"""

    PyPI: bool = any((part in __file__.lower() for part in ("site-packages", "dist-packages")))
    """True if running as a installed package from PyPI (https://brokensrc.dev/get/pypi/)"""

    Binary: bool = (PyInstaller or Nuitka or PyApp)
    """True if running from any executable build (PyInstaller, Nuitka, PyApp)"""

    Release: bool = (Binary or PyPI)
    """True if running from any static final release build (PyInstaller, Nuitka, PyApp, PyPI)"""

    Source: bool = (not Release)
    """True if running directly from the source code (https://brokensrc.dev/get/source/)"""

    Method: str = (Source and "Source") or (Binary and "Binary") or (PyPI and "PyPI")
    """The runtime environment of the current project release (Source, Release, PyPI)"""

    # # Special and Containers

    Docker: bool = Path("/.dockerenv").exists()
    """True if running from a Docker container"""

    GitHub: bool = bool(os.getenv("GITHUB_ACTIONS", False))
    """True if running in a GitHub Actions CI environment (https://docs.github.com/en/actions/writing-workflows/quickstart)"""

    WSL: bool = Path("/usr/lib/wsl/lib").exists()
    """True if running in Windows Subsystem for Linux (https://learn.microsoft.com/en-us/windows/wsl/about)"""

    Interactive: bool = sys.stdout.isatty()
    """True if running in an interactive terminal session (user can input)"""

Version

1
Version: str = __version__

The version of the Broken library, and subsequently all projects

Bitness

1
Bitness: int = struct.calcsize('P') * 8

The word size of the Python interpreter (32, 64 bits)

Python32

1
Python32: bool = Bitness == 32

True if running on a 32-bit Python interpreter

Python64

1
Python64: bool = Bitness == 64

True if running on a 64-bit Python interpreter

PyInstaller

1
PyInstaller: bool = bool(getattr(sys, 'frozen', False))

True if running from a PyInstaller binary build (https://github.com/pyinstaller/pyinstaller)

Nuitka

1
Nuitka: bool = '__compiled__' in globals()

True if running from a Nuitka binary build (https://github.com/Nuitka/Nuitka)

PyApp

1
PyApp: bool = bool(os.getenv('PYAPP', False))

True if running as a PyApp release (https://github.com/ofek/pyapp)

PyPI

1
2
3
4
PyPI: bool = any(
    part in __file__.lower()
    for part in ("site-packages", "dist-packages")
)

True if running as a installed package from PyPI (https://brokensrc.dev/get/pypi/)

Binary

1
Binary: bool = PyInstaller or Nuitka or PyApp

True if running from any executable build (PyInstaller, Nuitka, PyApp)

Release

1
Release: bool = Binary or PyPI

True if running from any static final release build (PyInstaller, Nuitka, PyApp, PyPI)

Source

1
Source: bool = not Release

True if running directly from the source code (https://brokensrc.dev/get/source/)

Method

1
2
3
4
5
6
7
8
Method: str = (
    Source
    and "Source"
    or Binary
    and "Binary"
    or PyPI
    and "PyPI"
)

The runtime environment of the current project release (Source, Release, PyPI)

Docker

1
Docker: bool = Path('/.dockerenv').exists()

True if running from a Docker container

GitHub

1
GitHub: bool = bool(os.getenv('GITHUB_ACTIONS', False))

True if running in a GitHub Actions CI environment (https://docs.github.com/en/actions/writing-workflows/quickstart)

WSL

1
WSL: bool = Path('/usr/lib/wsl/lib').exists()

True if running in Windows Subsystem for Linux (https://learn.microsoft.com/en-us/windows/wsl/about)

Interactive

1
Interactive: bool = sys.stdout.isatty()

True if running in an interactive terminal session (user can input)

Native

Source code in Broken/__init__.py
120
121
122
123
124
125
126
127
128
129
class Native:

    python: Path = Path(sys.executable)
    """The current Python interpreter executable"""

    uv: List[Union[str, Path]] = [python, "-m", "uv"]
    """Entry point for the uv package manager (https://github.com/astral-sh/uv)"""

    pip: List[Union[str, Path]] = [python, "-m", "uv", "pip"]
    """Entry point for pip"""

python

1
python: Path = Path(sys.executable)

The current Python interpreter executable

uv

1
uv: List[Union[str, Path]] = [python, '-m', 'uv']

Entry point for the uv package manager (https://github.com/astral-sh/uv)

pip

1
pip: List[Union[str, Path]] = [python, '-m', 'uv', 'pip']

Entry point for pip

BROKEN

1
2
3
4
5
6
BROKEN = BrokenProject(
    PACKAGE=__file__,
    APP_NAME="Broken",
    APP_AUTHOR="BrokenSource",
    RESOURCES=BrokenResources,
)

The main library's BrokenProject instance. Useful for common downloads and resources

PROJECT

1
PROJECT = BROKEN

The first BrokenProject initialized after (but including) BROKEN itself