Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/layers/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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"),
]
Expand All @@ -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"),
]
);
Expand All @@ -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");

Expand All @@ -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"),
]
Expand All @@ -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"),
]
Expand Down