Skip to content

Commit

Permalink
Add support for overriding the installation directory
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Jun 25, 2023
1 parent 2d7724b commit 468606d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<PROJECT_NAME>` environment variable where `<PROJECT_NAME>` 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).
Expand Down
19 changes: 14 additions & 5 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 468606d

Please sign in to comment.