Skip to content

Commit

Permalink
Add a PYAPP_EXPOSE_ALL_COMMANDS environment variable to expose all …
Browse files Browse the repository at this point in the history
…the management commands by default (#134)

Co-authored-by: Ofek Lev <ofekmeister@gmail.com>
  • Loading branch information
FlorentClarret and ofek authored May 23, 2024
1 parent ca77824 commit 4aed37f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ passthrough = [
"PYAPP_EXEC_NOTEBOOK",
"PYAPP_EXEC_SCRIPT",
"PYAPP_EXEC_SPEC",
"PYAPP_EXPOSE_ALL_COMMANDS",
"PYAPP_EXPOSE_CACHE",
"PYAPP_EXPOSE_METADATA",
"PYAPP_EXPOSE_PIP",
Expand Down
8 changes: 7 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ fn is_enabled(name: &str) -> bool {
["true", "1"].contains(&env::var(name).unwrap_or_default().as_str())
}

fn is_explicitly_disabled(name: &str) -> bool {
["false", "0"].contains(&env::var(name).unwrap_or_default().as_str())
}

fn normalize_project_name(name: &String) -> String {
// https://peps.python.org/pep-0508/#names
if !Regex::new(r"^([[:alnum:]]|[[:alnum:]][[:alnum:]._-]*[[:alnum:]])$")
Expand Down Expand Up @@ -1001,7 +1005,9 @@ fn set_exposed_command(path: &Path, command_name: &str, indicator: &Regex) {
let command_source = fs::read_to_string(command_path).unwrap();
if indicator.is_match(&command_source) {
let variable = format!("PYAPP_EXPOSE_{}", command_name.to_uppercase());
if is_enabled(&variable) {
if is_enabled(&variable)
|| (is_enabled("PYAPP_EXPOSE_ALL_COMMANDS") && !is_explicitly_disabled(&variable))
{
set_runtime_variable(&variable, "1");
} else {
set_runtime_variable(&variable, "0");
Expand Down
2 changes: 2 additions & 0 deletions docs/runtime.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ This will update the project to the latest available version in the currently us

These commands are hidden by default and each can be individually exposed by setting its corresponding `PYAPP_EXPOSE_<COMMAND>` option (e.g. `PYAPP_EXPOSE_METADATA`) to `true` or `1`.

You can enable all of them at once by setting the `PYAPP_EXPOSE_ALL_COMMANDS` option to `true` or `1`. Individual commands that are explicitly disabled (`PYAPP_EXPOSE_<COMMAND>` set to `false` or `0`) will not be exposed.

#### Cache

```
Expand Down

0 comments on commit 4aed37f

Please sign in to comment.