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

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-2.0.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: freezehelper-2.0.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-2.0.0.tar.gz
Algorithm Hash digest
SHA256 803bb92a6633233801fc84931bbae725bbe3839ac1e6e9dc5a8341a4dde1ea1d
MD5 4c02cfad8a946696ff59c420bb0dd46a
BLAKE2b-256 f1302b1b11e423cccdeded8537e4a65f28cb36f31affabee27c6b0b130398d71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: freezehelper-2.0.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-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 72cffbef669c0fa9d0ced386c1c6440ab3e1a0dfa82de5bd0e264e0352aab366
MD5 b1c6ee4c6e777cf5bc5e0e0a19b74763
BLAKE2b-256 44d5abbdd8f0aab48f6f84115a09b22e0e001173d43d9c005b3436a83124cd03

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