easy_as_pypi_appdirs package

Submodules

easy_as_pypi_appdirs.app_dirs module

Register an application and receive a handle to the singleton.

easy_as_pypi_appdirs.app_dirs.register_application(package_name)[source]

Register appname for future uses of AppDirsWithMkdir.

easy_as_pypi_appdirs.app_dirs_with_mkdir module

AppDirs subclass adds mkdir side effect.

class easy_as_pypi_appdirs.app_dirs_with_mkdir.AppDirsWithMkdir(*args, **kwargs)[source]

Bases: AppDirs

Singleton AppDirs with mkdir side effect.

  • As a Singleton, this class can be instantiated and used without knowing the appname, provided some bootstrap code registers it.

    E.g., when the app is first loaded, have it call:

    first_instance = AppDirsWithMkdir(appname='my-awesome-app')
    

    and then, later, access the same instance by instantiating anew:

    user_data_dir = AppDirsWithMkdir().user_data_dir

  • Has a Side effect, which is that, just by querying a directory path, this class creates that path, or ensures it exists.

    The author (lb) isn’t super jazzed by this “feature”, but it was useful to get a downstream app up and running more easily without having to manage mkdir’ing application directories… and now it’s been baked in so long I don’t want to spend the time changing it… it’s just something of which to be aware:

    • Asking for an application directory path may create that path.

  • Regarding Singleton (again), which is not the most respected pattern (some might say it’s always a smell), consider this classic discussion on ways to implement Singleton in Python, and whether or not they’re a good idea:

is_ready = None
property safe

Return parent object, without mkdirs -p side effect.

property site_config_dir

Return site_config_dir.

property site_data_dir

Return site_data_dir.

property user_cache_dir

Return user_cache_dir.

property user_config_dir

Return user_config_dir.

property user_data_dir

Return user_data_dir.

property user_log_dir

Return user_log_dir.

property user_state_dir

Return user_state_dir.

easy_as_pypi_appdirs.exists_or_mkdirs module

Functions to ensure directories exist.

easy_as_pypi_appdirs.exists_or_mkdirs.must_ensure_directory_exists(directory)[source]

Ensure that the passed path to a directory exists.

easy_as_pypi_appdirs.exists_or_mkdirs.must_ensure_file_path_dirred(filename)[source]

Ensure parent directory for passed path exists, if not just a filename.

easy_as_pypi_appdirs.expand_and_mkdirs module

Helper function tries to make AppDirs path directories, if necessary, or raises.

easy_as_pypi_appdirs.expand_and_mkdirs.must_ensure_appdirs_path(file_basename, dir_dirname, appdirs_dir=None, basename_fmt='{}')[source]

Return the path to a file stored in a subdirectory of an AppDirs directory.

easy_as_pypi_appdirs.singleton module

Singleton metaclass.

class easy_as_pypi_appdirs.singleton.Singleton[source]

Bases: type

A Singleton metaclass.

For a healthy discussion on ways to implement Singleton in Python, and whether or not they’re a good tool to use, read the long-standing and still-rolling Creating a singleton in Python article:

Module contents

Top-level package for this CLI-based application.