Skip to main content

freezehelper: A Python package to simplify checks for frozen state and executable directory (such as when using PyInstaller)

It provides:
  • attributes to check platform, freeze state, and whether running in a child or parent process

Original use case:
  • Python program that is deployed frozen (using PyInstaller) but is run from source while developed

  • When running from source I wanted to perform extra actions/checks on startup, e.g.:

    • setting a different log level/log to console or replacing sys.excepthook

    • changing what gets run in a child process on start when using multiprocessing

Installation:
  • pip install freezehelper

    (Tested for Python >=3.6.5 on Linux (Ubuntu) and Windows 10)

Usage:
  • quick-start overview:

    # import the package
    import freezehelper
    
    ## Package Attributes
    
    # A bool to check if running from source:
    freezehelper.from_source
    
    # A bool to check if frozen:
    freezehelper.frozen
    
    # More bool items for platform:
    freezehelper.is_linux
    freezehelper.is_not_linux
    freezehelper.is_mac
    freezehelper.is_not_mac
    freezehelper.is_windows
    freezehelper.is_not_windows
    
    # Functions to check for process context:
    freezehelper.is_child_process()
    freezehelper.is_main_process()
    
    # Path string for directory containing the main executable:
    freezehelper.executable_dir
    
    # Path string for the main executable:
    freezehelper.executable_path
    
    # NOTE: If your script is ever executed from a module, such as pytest, then that module will be the executable path.
    # Be sure to account for such cases if necessary. For example:
    # If invoked by 'python -m pytest', then freezehelper.executable_path would be the path to the pytest package.
    # One way to account for this from the main program file:
    import os
    if freezehelper.executable_dir.endswith("pytest"):
        PROGRAM_DIR = os.path.dirname(os.path.realpath(__name__))
    else:
        PROGRAM_DIR = freezehelper.executable_path
    
    ## Functions
    
    # Functions for getting directory of executable or path to main executable:
    # These accept a bool resolve_links keyword argument.
    # When True (default), any symbolic links in the path are resolved in order to get the real path.
    freezehelper.get_executable_dir()
    freezehelper.get_executable_path()
    
    
    ## Examples
    if freezehelper.frozen:
        print(f"{freezehelper.executable_path} go brrr")
    
    # create separate logs for parent and child processes
    import logcontrol
    import os
    
    log_dir = os.path.join(freezehelper.executable_dir, "logs")
    child_log_dir = os.path.join(log_dir, "workers")
    
    if freezehelper.is_main_process():
        log_file = os.path.join(log_dir, "main_process.log")
    else:
        log_file = os.path.join(child_log_dir, f"{os.getpid()}_worker.log")
    
    logcontrol.set_log_file(log_file)

Metadata

Release files for freezehelper 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for freezehelper 2.0.0
File Size Uploaded Provenance
freezehelper-2.0.0.tar.gz 17.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for freezehelper 2.0.0
File Interpreter ABI Platform
freezehelper-2.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 37.7 kB

Release files / freezehelper-2.0.0.tar.gz

Download URL freezehelper-2.0.0.tar.gz
Size 17.6 kB
Tags Source
SHA-256 checksum
How to use checksums
803bb92a6633233801fc84931bbae725bbe3839ac1e6e9dc5a8341a4dde1ea1d
BLAKE2b-256 checksum
How to use checksums
f1302b1b11e423cccdeded8537e4a65f28cb36f31affabee27c6b0b130398d71
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

Release files / freezehelper-2.0.0-py3-none-any.whl

Download URL freezehelper-2.0.0-py3-none-any.whl
Size 20.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
72cffbef669c0fa9d0ced386c1c6440ab3e1a0dfa82de5bd0e264e0352aab366
BLAKE2b-256 checksum
How to use checksums
44d5abbdd8f0aab48f6f84115a09b22e0e001173d43d9c005b3436a83124cd03
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.6.9

Security for freezehelper 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page