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_mac
    freezehelper.is_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
    
    ## 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.0.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

freezehelper-1.0.0-py3-none-any.whl (19.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: freezehelper-1.0.0.tar.gz
  • Upload date:
  • Size: 17.3 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.0.0.tar.gz
Algorithm Hash digest
SHA256 78f442d3a16bd14f773ccc3a7683db951fc272d2177463b311f56c0623e760f7
MD5 50a431951bfa70f1c4fa9f676a32ebea
BLAKE2b-256 f29f2cc445e0b42177fe086d2cb41cb2d3e332d10a2bfb09b2ab85e05a3f9853

See more details on using hashes here.

File details

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

File metadata

  • Download URL: freezehelper-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.8 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.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e5bfad9b8cc036364ca5bc8f186b509d82a42edc0463279e3088faccdb64393
MD5 9ad8bee17f070b9c6dc8af9fcbfe720f
BLAKE2b-256 2d6742b9efe4b4e07d0123cc4086e2720e8f2f3a110d0ca2e07dfc01fb83a654

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