diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f1da4f..f22ffe3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Updated setuptools from 67.5.0 to 67.6.1. ([#24](https://github.com/heroku/buildpacks-python/pull/24)) - Updated wheel from 0.38.4 to 0.40.0. ([#24](https://github.com/heroku/buildpacks-python/pull/24)) +### Fixed + +- The `PYTHONHOME` environment variable is now set to work around uWSGI not handling relocated Python installs correctly. ([#25](https://github.com/heroku/buildpacks-python/pull/25)) + ## [0.1.0] - 2023-03-06 ### Added diff --git a/src/layers/python.rs b/src/layers/python.rs index 55b8a90..5dbf371 100644 --- a/src/layers/python.rs +++ b/src/layers/python.rs @@ -315,6 +315,19 @@ fn generate_layer_env(layer_path: &Path, python_version: &PythonVersion) -> Laye "PKG_CONFIG_PATH", ":", ) + // Our Python runtime is relocated (installed into a different location to which is was + // originally compiled) which Python itself handles well, since it recalculates its actual + // location at startup: + // https://docs.python.org/3.11/library/sys_path_init.html + // However, the uWSGI package uses the wrong `sysconfig` APIs so tries to reference the old + // compile location, unless we override that by setting `PYTHONHOME`: + // https://github.com/unbit/uwsgi/issues/2525 + .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, @@ -520,6 +533,7 @@ mod tests { ("LANG", "C.UTF-8"), ("PIP_DISABLE_PIP_VERSION_CHECK", "1"), ("PKG_CONFIG_PATH", "/layers/python/lib/pkgconfig"), + ("PYTHONHOME", "/layers/python"), ("PYTHONUNBUFFERED", "1"), ("SOURCE_DATE_EPOCH", "315532801"), ] @@ -531,6 +545,7 @@ mod tests { ("LANG", "C.UTF-8"), ("PIP_DISABLE_PIP_VERSION_CHECK", "1"), ("PKG_CONFIG_PATH", "/layers/python/lib/pkgconfig"), + ("PYTHONHOME", "/layers/python"), ("PYTHONUNBUFFERED", "1"), ] ); @@ -543,6 +558,7 @@ mod tests { base_env.insert("LANG", "this-should-be-overridden"); base_env.insert("PIP_DISABLE_PIP_VERSION_CHECK", "this-should-be-overridden"); base_env.insert("PKG_CONFIG_PATH", "/base"); + base_env.insert("PYTHONHOME", "this-should-be-overridden"); base_env.insert("PYTHONUNBUFFERED", "this-should-be-overridden"); base_env.insert("SOURCE_DATE_EPOCH", "this-should-be-preserved"); @@ -563,6 +579,7 @@ mod tests { ("LANG", "C.UTF-8"), ("PIP_DISABLE_PIP_VERSION_CHECK", "1"), ("PKG_CONFIG_PATH", "/layers/python/lib/pkgconfig:/base"), + ("PYTHONHOME", "/layers/python"), ("PYTHONUNBUFFERED", "1"), ("SOURCE_DATE_EPOCH", "this-should-be-preserved"), ] @@ -574,6 +591,7 @@ mod tests { ("LANG", "C.UTF-8"), ("PIP_DISABLE_PIP_VERSION_CHECK", "1"), ("PKG_CONFIG_PATH", "/layers/python/lib/pkgconfig:/base"), + ("PYTHONHOME", "/layers/python"), ("PYTHONUNBUFFERED", "1"), ("SOURCE_DATE_EPOCH", "this-should-be-preserved"), ]