Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for overriding the installation directory #45

Merged
merged 1 commit into from
Jun 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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