Skip to content

Commit

Permalink
Add PYAPP_ALLOW_UPDATES option (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek authored May 15, 2024
1 parent 2e4bfbf commit b58e45a
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ codegen-units = 1

[package.metadata.cross.build.env]
passthrough = [
"PYAPP_ALLOW_UPDATES",
"PYAPP_DISTRIBUTION_EMBED",
"PYAPP_DISTRIBUTION_FORMAT",
"PYAPP_DISTRIBUTION_PATH",
Expand All @@ -63,6 +64,7 @@ passthrough = [
"PYAPP_EXPOSE_PIP",
"PYAPP_EXPOSE_PYTHON",
"PYAPP_EXPOSE_PYTHON_PATH",
"PYAPP_EXPOSE_UPDATE",
"PYAPP_FULL_ISOLATION",
"PYAPP_IS_GUI",
"PYAPP_METADATA_TEMPLATE",
Expand Down
20 changes: 19 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,6 +892,21 @@ fn set_uv_version() {

fn set_skip_install() {
let variable = "PYAPP_SKIP_INSTALL";
if is_enabled(variable) {
set_runtime_variable(variable, "1");
if is_enabled("PYAPP_ALLOW_UPDATES") {
set_runtime_variable("PYAPP_EXPOSE_UPDATE", "1");
} else {
set_runtime_variable("PYAPP_EXPOSE_UPDATE", "0");
}
} else {
set_runtime_variable(variable, "0");
set_runtime_variable("PYAPP_EXPOSE_UPDATE", "1");
}
}

fn set_allow_updates() {
let variable = "PYAPP_ALLOW_UPDATES";
if is_enabled(variable) {
set_runtime_variable(variable, "1");
} else {
Expand Down Expand Up @@ -999,9 +1014,12 @@ fn main() {
set_uv_enabled();
set_uv_only_bootstrap();
set_uv_version();
set_skip_install();
set_allow_updates();
set_indicator();
set_self_command();
set_exposed_commands();
set_metadata_template();

// This must come last because it might override a command exposure
set_skip_install();
}
8 changes: 8 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

## Unreleased

***Added:***

- Add `PYAPP_ALLOW_UPDATES` option for enabling the `update` management command when project installation is skipped

***Fixed:***

- Properly hide the `update` management command when skipping project installation

## 0.20.1 - 2024-05-14

***Fixed:***
Expand Down
2 changes: 2 additions & 0 deletions docs/config/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ The default location of your application's installation differs based on the ope
## Skipping installation

You may set the `PYAPP_SKIP_INSTALL` option to `true` or `1` to skip installing the project in the distribution. This allows for entirely predefined distributions and thus no network calls at runtime if used in conjunction with [distribution embedding](distribution.md#embedding).

When project installation is skipped, the `update` command will not be available. You may set the `PYAPP_ALLOW_UPDATES` option to `true` or `1` to expose the command anyway. Be sure to set the appropriate [project options](project.md) as configuring a prebuilt distribution does not require those.
4 changes: 4 additions & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ pub fn skip_install() -> bool {
env!("PYAPP_SKIP_INSTALL") == "1"
}

pub fn allow_updates() -> bool {
env!("PYAPP_ALLOW_UPDATES") == "1"
}

pub fn pass_location() -> bool {
env!("PYAPP_PASS_LOCATION") == "1"
}
Expand Down
4 changes: 2 additions & 2 deletions src/commands/self_cmd/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::{app, distribution, terminal};

/// Install the latest version
#[derive(Args, Debug)]
#[command()]
#[command(hide = env!("PYAPP_EXPOSE_UPDATE") == "0")]
pub struct Cli {
/// Allow pre-release and development versions
#[arg(long)]
Expand All @@ -21,7 +21,7 @@ pub struct Cli {

impl Cli {
pub fn exec(self) -> Result<()> {
if app::skip_install() {
if app::skip_install() && !app::allow_updates() {
println!("Cannot update as installation is disabled");
exit(1);
}
Expand Down

0 comments on commit b58e45a

Please sign in to comment.