Skip to content

Commit

Permalink
Fix distribution embeds and update docs (#80)
Browse files Browse the repository at this point in the history
Co-authored-by: Ofek Lev <[email protected]>
  • Loading branch information
nmay231 and ofek authored Feb 29, 2024
1 parent 7d4b5cd commit 2eba793
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ Cargo.lock
# Documentation
/.cache/
/site/

# Editor configs
.vscode/
7 changes: 6 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 2eba793

Please sign in to comment.