Skip to main content

A Python package to simplify checks for frozen state and executable directory

Project description

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
    
    # Bool items 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)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

freezehelper-1.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

freezehelper-1.1.0-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file freezehelper-1.1.0.tar.gz.

File metadata

  • Download URL: freezehelper-1.1.0.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for freezehelper-1.1.0.tar.gz
Algorithm Hash digest
SHA256 e1fe023c2b6b91a1f9c4abdbe965f87b7e3fbf4e7c38234e76dc51288c8f8223
MD5 8031b49265dfbc7ed7f51142e6a4d8f0
BLAKE2b-256 acc31736f74ffa774811bab5345544c02dfb20816cf519f6fb88c17bd04de6f0

See more details on using hashes here.

File details

Details for the file freezehelper-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: freezehelper-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for freezehelper-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e6c0164de21fd504bfe8e5aefc844442736607226e9d905dd562eac126f2f8e5
MD5 53621b23fdd5ef9c06c58277350f2f1a
BLAKE2b-256 9d535679f5f63f2d5614ae1d8edddbc0ae3356cd895f88e7bb53c92d71ec8dbc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page