diff --git a/docs/changelog.md b/docs/changelog.md index 009e6ba..423c110 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -8,6 +8,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ## Unreleased +***Added:*** + +- Add support for overriding the installation directory + ***Fixed:*** - Properly handle cases where options contain line feed characters diff --git a/docs/runtime.md b/docs/runtime.md index caa7962..02f1d2f 100644 --- a/docs/runtime.md +++ b/docs/runtime.md @@ -68,6 +68,10 @@ To provide consistent behavior on each user's machine: A single environment variable called `PYAPP` is injected with the value of `1` ([by default](config.md#installation-indicator)) when running applications and may be used to detect this mode of installation versus others. +## Location + +The default location of your application's installation differs based on the operating system and can be overridden at runtime with the `PYAPP_INSTALL_DIR_` environment variable where `` is the uppercased version of the [project name](config.md#project). + ## Commands Built applications have a single top-level command group named `self` ([by default](config.md#management-command)) and all other invocations will be forwarded to your actual [execution logic](config.md#execution-mode). diff --git a/src/app.rs b/src/app.rs index 3303345..6bf3fcb 100644 --- a/src/app.rs +++ b/src/app.rs @@ -28,11 +28,20 @@ pub fn initialize() -> Result<()> { .set(platform_directories) .expect("could not set platform directories"); - let installation_directory = platform_dirs() - .data_local_dir() - .join(project_name()) - .join(distribution_id()) - .join(project_version()); + let install_dir_override = env::var(format!( + "PYAPP_INSTALL_DIR_{}", + project_name().to_uppercase() + )) + .unwrap_or_default(); + let installation_directory = if !install_dir_override.is_empty() { + PathBuf::from(install_dir_override) + } else { + platform_dirs() + .data_local_dir() + .join(project_name()) + .join(distribution_id()) + .join(project_version()) + }; INSTALLATION_DIRECTORY .set(installation_directory) .expect("could not set installation directory");