From 2eba793c8761791b1bdcc64e3d68e17058456af9 Mon Sep 17 00:00:00 2001 From: Noah Date: Thu, 29 Feb 2024 16:53:15 -0600 Subject: [PATCH] Fix distribution embeds and update docs (#80) Co-authored-by: Ofek Lev --- .gitignore | 3 +++ build.rs | 7 ++++++- docs/config.md | 6 ++++-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 52e2f3b..0434227 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ Cargo.lock # Documentation /.cache/ /site/ + +# Editor configs +.vscode/ diff --git a/build.rs b/build.rs index b157790..0a0625f 100644 --- a/build.rs +++ b/build.rs @@ -505,7 +505,7 @@ fn set_distribution() { let mut file = File::open(&embed_path).unwrap(); std::io::copy(&mut file, &mut hasher).unwrap(); - "".to_string() + local_path } else if is_enabled("PYAPP_DISTRIBUTION_EMBED") { let distribution_source = get_distribution_source(); let bytes = reqwest::blocking::get(&distribution_source) @@ -575,6 +575,11 @@ fn set_python_path(distribution_source: &str) { let python_path = env::var(distribution_variable).unwrap_or_default(); let relative_path = if !python_path.is_empty() { python_path + } else if !env::var("PYAPP_DISTRIBUTION_PATH") + .unwrap_or_default() + .is_empty() + { + panic!("\n\nThe following option must be set when embedding a custom distribution: {distribution_variable}\n\n"); } else if distribution_source.starts_with(DEFAULT_CPYTHON_SOURCE) { if get_python_version() == "3.7" { if on_windows { diff --git a/docs/config.md b/docs/config.md index d6d9f07..8fa2b77 100644 --- a/docs/config.md +++ b/docs/config.md @@ -60,7 +60,7 @@ Setting the `PYAPP_PYTHON_VERSION` option will determine the distribution used a | `3.10` | | `3.11` | -The source of distributions is the [python-build-standalone](https://github.com/indygreg/python-build-standalone) project. +The source for pre-built distributions is the [python-build-standalone](https://github.com/indygreg/python-build-standalone) project. Some distributions have [variants](https://gregoryszorc.com/docs/python-build-standalone/main/running.html) that may be configured with the `PYAPP_DISTRIBUTION_VARIANT` option: @@ -110,7 +110,9 @@ You may indicate whether pip is already installed by setting the `PYAPP_DISTRIBU ### Embedding ### {: #distribution-embedding } -You may set the `PYAPP_DISTRIBUTION_EMBED` option to `true` or `1` to embed the distribution in the executable at build time to avoid fetching it at runtime. You can set the `PYAPP_DISTRIBUTION_PATH` option to use a local path rather than fetching the source, which implicitly enables embedding. +You may set the `PYAPP_DISTRIBUTION_EMBED` option to `true` or `1` to embed the distribution in the executable at build time to avoid fetching it at runtime. + +You can set the `PYAPP_DISTRIBUTION_PATH` option to use a local path rather than fetching the source, which implicitly enables embedding. The local archive should be similar to the [default distributions](#python-distribution) in that there should be a Python interpreter ready for use. ## pip