diff --git a/CHANGELOG.md b/CHANGELOG.md index 0aa7e55..e0af644 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Stopped manually creating a `src` directory inside the Pip dependencies layer. Pip will create the directory itself if needed (when there are editable VCS dependencies). ([#228](https://github.com/heroku/buildpacks-python/pull/228)) - Stopped setting `CPATH` and `PKG_CONFIG_PATH` at launch time. ([#231](https://github.com/heroku/buildpacks-python/pull/231)) +- The `bin` directory in the Pip dependencies layer is now always added to `PATH` instead of only when an installed dependency has an entry point script. ([#232](https://github.com/heroku/buildpacks-python/pull/232)) ## [0.12.1] - 2024-07-15 diff --git a/src/layers/pip_dependencies.rs b/src/layers/pip_dependencies.rs index 519ca50..1cf7bd3 100644 --- a/src/layers/pip_dependencies.rs +++ b/src/layers/pip_dependencies.rs @@ -64,9 +64,6 @@ impl Layer for PipDependenciesLayer<'_> { "--cache-dir", &self.pip_cache_dir.to_string_lossy(), "--no-input", - // Prevent warning about the `bin/` directory not being on `PATH`, since it - // will be added automatically by libcnb/lifecycle later. - "--no-warn-script-location", "--progress", "off", // Install dependencies into the user `site-packages` directory (set by `PYTHONUSERBASE`), @@ -110,6 +107,16 @@ impl Layer for PipDependenciesLayer<'_> { /// Environment variables that will be set by this layer. fn generate_layer_env(layer_path: &Path) -> LayerEnv { LayerEnv::new() + // We set `PATH` explicitly, since lifecycle will only add the bin directory to `PATH` if it + // exists - and we want to support the scenario of installing a debugging package with CLI at + // run-time, when none of the dependencies installed at build-time had an entrypoint script. + .chainable_insert( + Scope::All, + ModificationBehavior::Prepend, + "PATH", + layer_path.join("bin"), + ) + .chainable_insert(Scope::All, ModificationBehavior::Delimiter, "PATH", ":") // `PYTHONUSERBASE` overrides the default user base directory, which is used by Python to // compute the path of the user `site-packages` directory: // https://docs.python.org/3/using/cmdline.html#envvar-PYTHONUSERBASE @@ -149,17 +156,24 @@ mod tests { #[test] fn pip_dependencies_layer_env() { let mut base_env = Env::new(); + base_env.insert("PATH", "/base"); base_env.insert("PYTHONUSERBASE", "this-should-be-overridden"); let layer_env = generate_layer_env(Path::new("/layer-dir")); assert_eq!( utils::environment_as_sorted_vector(&layer_env.apply(Scope::Build, &base_env)), - [("PYTHONUSERBASE", "/layer-dir")] + [ + ("PATH", "/layer-dir/bin:/base"), + ("PYTHONUSERBASE", "/layer-dir"), + ] ); assert_eq!( utils::environment_as_sorted_vector(&layer_env.apply(Scope::Launch, &base_env)), - [("PYTHONUSERBASE", "/layer-dir")] + [ + ("PATH", "/layer-dir/bin:/base"), + ("PYTHONUSERBASE", "/layer-dir"), + ] ); } } diff --git a/tests/pip_test.rs b/tests/pip_test.rs index 3d79bd0..1f2f07b 100644 --- a/tests/pip_test.rs +++ b/tests/pip_test.rs @@ -61,7 +61,7 @@ fn pip_basic_install_and_cache_reuse() { &formatdoc! {" LANG=C.UTF-8 LD_LIBRARY_PATH=/layers/heroku_python/python/lib:/layers/heroku_python/dependencies/lib - PATH=/layers/heroku_python/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + PATH=/layers/heroku_python/dependencies/bin:/layers/heroku_python/python/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PIP_DISABLE_PIP_VERSION_CHECK=1 PYTHONHOME=/layers/heroku_python/python PYTHONUNBUFFERED=1