diff --git a/Cargo.toml b/Cargo.toml index d732d44..00172a0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -49,6 +49,7 @@ passthrough = [ "PYAPP_DISTRIBUTION_EMBED", "PYAPP_DISTRIBUTION_FORMAT", "PYAPP_DISTRIBUTION_PATH", + "PYAPP_DISTRIBUTION_PATH_PREFIX", "PYAPP_DISTRIBUTION_PIP_AVAILABLE", "PYAPP_DISTRIBUTION_PYTHON_PATH", "PYAPP_DISTRIBUTION_SITE_PACKAGES_PATH", diff --git a/build.rs b/build.rs index 98994fc..80d815b 100644 --- a/build.rs +++ b/build.rs @@ -572,7 +572,7 @@ fn set_python_path(distribution_source: &str) { let distribution_variable = "PYAPP_DISTRIBUTION_PYTHON_PATH"; let on_windows = env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows"; let python_path = env::var(distribution_variable).unwrap_or_default(); - let relative_path = if !python_path.is_empty() { + let mut relative_path = if !python_path.is_empty() { python_path } else if !env::var("PYAPP_DISTRIBUTION_PATH") .unwrap_or_default() @@ -608,6 +608,15 @@ fn set_python_path(distribution_source: &str) { } else { "bin/python3".to_string() }; + + let path_prefix = env::var("PYAPP_DISTRIBUTION_PATH_PREFIX").unwrap_or_default(); + if !path_prefix.is_empty() { + if on_windows { + relative_path = format!(r"{}\{}", path_prefix, relative_path); + } else { + relative_path = format!("{}/{}", path_prefix, relative_path); + } + } set_runtime_variable(distribution_variable, &relative_path); let installation_variable = "PYAPP__INSTALLATION_PYTHON_PATH"; @@ -625,7 +634,7 @@ fn set_site_packages_path(distribution_source: &str) { let on_windows = env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows"; let python_version = get_python_version(); let site_packages_path = env::var(distribution_variable).unwrap_or_default(); - let relative_path = if !site_packages_path.is_empty() { + let mut relative_path = if !site_packages_path.is_empty() { site_packages_path } else if distribution_source.starts_with(DEFAULT_CPYTHON_SOURCE) { if python_version == "3.7" { @@ -662,6 +671,15 @@ fn set_site_packages_path(distribution_source: &str) { } else { format!("lib/python{}/site-packages", python_version) }; + + let path_prefix = env::var("PYAPP_DISTRIBUTION_PATH_PREFIX").unwrap_or_default(); + if !path_prefix.is_empty() { + if on_windows { + relative_path = format!(r"{}\{}", path_prefix, relative_path); + } else { + relative_path = format!("{}/{}", path_prefix, relative_path); + } + } set_runtime_variable(distribution_variable, &relative_path); let installation_variable = "PYAPP__INSTALLATION_SITE_PACKAGES_PATH"; diff --git a/docs/changelog.md b/docs/changelog.md index 5364b18..b8c96ac 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), ***Added:*** +- Add `PYAPP_DISTRIBUTION_PATH_PREFIX` option for easier configuring of custom distribution internal paths - Add `PYAPP_ALLOW_UPDATES` option for enabling the `update` management command when project installation is skipped ***Fixed:*** diff --git a/docs/config/distribution.md b/docs/config/distribution.md index ba20dd0..07095fe 100644 --- a/docs/config/distribution.md +++ b/docs/config/distribution.md @@ -60,6 +60,10 @@ You may set the relative path to the Python executable after unpacking the archi You may set the relative path to the [`site-packages`](https://docs.python.org/3/library/site.html) directory after unpacking the archive with the `PYAPP_DISTRIBUTION_SITE_PACKAGES_PATH` option. The default is `Lib\site-packages` on Windows and `lib/python/site-packages` on all other platforms where `` is the defined [distribution ID](#known). +### Path prefix + +If the [Python executable](#python-location) and the [`site-packages` directory](#site-packages-location) are not in the root of the archive, you may set the `PYAPP_DISTRIBUTION_PATH_PREFIX` option to the common prefix of the two paths. + ### pip availability You may indicate whether pip is already installed by setting the `PYAPP_DISTRIBUTION_PIP_AVAILABLE` option to `true` or `1`. This elides the check for installation when [upgraded virtual environments](installation.md#virtual-environments) are enabled.