From d8032fbecf0f2e4f9bf88993bc434b66076f2c57 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Tue, 17 Dec 2024 15:15:57 +0000 Subject: [PATCH] Stop setting the `PYTHONHOME` env var Since it was only set to work around a uWSGI bug, and that bug does not occur when using a venv (which we now use as of #257). Closes #265. GUS-W-17454520. --- CHANGELOG.md | 1 + src/layers/python.rs | 17 ----------------- tests/pip_test.rs | 2 -- tests/poetry_test.rs | 2 -- 4 files changed, 1 insertion(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6565704..13f34cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Removed - Stopped setting the `LANG` env var. ([#306](https://github.com/heroku/buildpacks-python/pull/306)) +- Stopped setting the `PYTHONHOME` env var. ([#309](https://github.com/heroku/buildpacks-python/pull/309)) ## [0.20.1] - 2024-12-13 diff --git a/src/layers/python.rs b/src/layers/python.rs index 81d1587..fbd1c29 100644 --- a/src/layers/python.rs +++ b/src/layers/python.rs @@ -190,20 +190,6 @@ fn generate_layer_env(layer_path: &Path, python_version: &PythonVersion) -> Laye "PKG_CONFIG_PATH", ":", ) - // We relocate Python (install into a different location to which it was compiled), which - // Python handles fine since it recalculates its actual location at startup. However, the - // uWSGI package uses the wrong `sysconfig` APIs so tries to reference the old compile - // location, unless we override that by setting `PYTHONHOME`. See: - // https://docs.python.org/3/library/sys_path_init.html - // https://github.com/unbit/uwsgi/issues/2525 - // In addition, some legacy apps have `PYTHONHOME` set to an invalid value, so if we did not - // set it explicitly here, they would fail to run both during the build and at run-time. - .chainable_insert( - Scope::All, - ModificationBehavior::Override, - "PYTHONHOME", - layer_path, - ) // Disable Python's output buffering to ensure logs aren't dropped if an app crashes. .chainable_insert( Scope::All, @@ -323,7 +309,6 @@ mod tests { let mut base_env = Env::new(); base_env.insert("CPATH", "/base"); base_env.insert("PKG_CONFIG_PATH", "/base"); - base_env.insert("PYTHONHOME", "this-should-be-overridden"); base_env.insert("PYTHONUNBUFFERED", "this-should-be-overridden"); let layer_env = generate_layer_env(Path::new("/layer-dir"), &PythonVersion::new(3, 11, 1)); @@ -333,7 +318,6 @@ mod tests { [ ("CPATH", "/layer-dir/include/python3.11:/base"), ("PKG_CONFIG_PATH", "/layer-dir/lib/pkgconfig:/base"), - ("PYTHONHOME", "/layer-dir"), ("PYTHONUNBUFFERED", "1"), ("SOURCE_DATE_EPOCH", "315532801"), ] @@ -343,7 +327,6 @@ mod tests { [ ("CPATH", "/base"), ("PKG_CONFIG_PATH", "/base"), - ("PYTHONHOME", "/layer-dir"), ("PYTHONUNBUFFERED", "1"), ] ); diff --git a/tests/pip_test.rs b/tests/pip_test.rs index 00e5dc0..40d0b02 100644 --- a/tests/pip_test.rs +++ b/tests/pip_test.rs @@ -47,7 +47,6 @@ fn pip_basic_install_and_cache_reuse() { PIP_DISABLE_PIP_VERSION_CHECK=1 PIP_PYTHON=/layers/heroku_python/venv PKG_CONFIG_PATH=/layers/heroku_python/python/lib/pkgconfig - PYTHONHOME=/layers/heroku_python/python PYTHONUNBUFFERED=1 PYTHONUSERBASE=/layers/heroku_python/pip SOURCE_DATE_EPOCH=315532801 @@ -85,7 +84,6 @@ fn pip_basic_install_and_cache_reuse() { formatdoc! {" LD_LIBRARY_PATH=/layers/heroku_python/venv/lib:/layers/heroku_python/python/lib PATH=/layers/heroku_python/venv/bin:/layers/heroku_python/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - PYTHONHOME=/layers/heroku_python/python PYTHONUNBUFFERED=1 VIRTUAL_ENV=/layers/heroku_python/venv "} diff --git a/tests/poetry_test.rs b/tests/poetry_test.rs index 05887af..d822b39 100644 --- a/tests/poetry_test.rs +++ b/tests/poetry_test.rs @@ -42,7 +42,6 @@ fn poetry_basic_install_and_cache_reuse() { LIBRARY_PATH=/layers/heroku_python/venv/lib:/layers/heroku_python/python/lib:/layers/heroku_python/poetry/lib PATH=/layers/heroku_python/venv/bin:/layers/heroku_python/python/bin:/layers/heroku_python/poetry/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PKG_CONFIG_PATH=/layers/heroku_python/python/lib/pkgconfig - PYTHONHOME=/layers/heroku_python/python PYTHONUNBUFFERED=1 PYTHONUSERBASE=/layers/heroku_python/poetry SOURCE_DATE_EPOCH=315532801 @@ -78,7 +77,6 @@ fn poetry_basic_install_and_cache_reuse() { formatdoc! {" LD_LIBRARY_PATH=/layers/heroku_python/venv/lib:/layers/heroku_python/python/lib PATH=/layers/heroku_python/venv/bin:/layers/heroku_python/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin - PYTHONHOME=/layers/heroku_python/python PYTHONUNBUFFERED=1 VIRTUAL_ENV=/layers/heroku_python/venv "}