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_with_mkdir module
AppDirs subclass adds mkdir side effect.
- class easy_as_pypi_appdirs.app_dirs_with_mkdir.AppDirsWithMkdir(*args, **kwargs)[source]
Bases:
AppDirsSingleton AppDirs with
mkdirside 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:
Creating a singleton in Python:
https://stackoverflow.com/questions/6760685/creating-a-singleton-in-python
- 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.expand_and_mkdirs module
Helper function tries to make AppDirs path directories, if necessary, or raises.
easy_as_pypi_appdirs.singleton module
Singleton metaclass.
Module contents
Top-level package for this CLI-based application.