From d8ff74007248edb5e8d6e9ae487d8c043dac9b16 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Fri, 13 Dec 2024 20:34:28 +0000 Subject: [PATCH] Add metrics for the existence of a uv lockfile To help gauge how often a uv lockfile exists. (Either from someone trying to use uv and the build failing, or when a third-party buildpack is used to export the uv lockfile to a requirements file etc). Towards #1616. GUS-W-17431743. --- CHANGELOG.md | 1 + bin/report | 1 + lib/package_manager.sh | 9 ++++ spec/fixtures/uv_lockfile_only/pyproject.toml | 0 spec/fixtures/uv_lockfile_only/uv.lock | 0 spec/hatchet/package_manager_spec.rb | 47 +++++++++++++++++++ 6 files changed, 58 insertions(+) create mode 100644 spec/fixtures/uv_lockfile_only/pyproject.toml create mode 100644 spec/fixtures/uv_lockfile_only/uv.lock diff --git a/CHANGELOG.md b/CHANGELOG.md index eae0bf86e..be0f589cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## [Unreleased] - Fixed Dev Center links to reflect recent article URL changes. ([#1723](https://github.com/heroku/heroku-buildpack-python/pull/1723)) +- Added metrics for the existence of a uv lockfile. ([#1725](https://github.com/heroku/heroku-buildpack-python/pull/1725)) ## [v271] - 2024-12-12 diff --git a/bin/report b/bin/report index dcba72ef2..eb354bdbc 100755 --- a/bin/report +++ b/bin/report @@ -94,6 +94,7 @@ ALL_OTHER_FIELDS=( setup_py_only sqlite_install_duration total_duration + uv_lockfile ) for field in "${STRING_FIELDS[@]}"; do diff --git a/lib/package_manager.sh b/lib/package_manager.sh index eee49ab42..cc0bb6afc 100644 --- a/lib/package_manager.sh +++ b/lib/package_manager.sh @@ -59,6 +59,10 @@ function package_manager::determine_package_manager() { meta_set "setup_py_only" "false" fi + if [[ -f "${build_dir}/uv.lock" ]]; then + meta_set "uv_lockfile" "true" + fi + local num_package_managers_found=${#package_managers_found[@]} case "${num_package_managers_found}" in @@ -87,6 +91,11 @@ function package_manager::determine_package_manager() { Otherwise, add a package manager file to your app. If your app has no dependencies, then create an empty 'requirements.txt' file. + If you would like to see support for the package manager uv, + please vote and comment on these GitHub issues: + https://github.com/heroku/heroku-buildpack-python/issues/1616 + https://github.com/heroku/roadmap/issues/323 + For help with using Python on Heroku, see: https://devcenter.heroku.com/articles/getting-started-with-python https://devcenter.heroku.com/articles/python-support diff --git a/spec/fixtures/uv_lockfile_only/pyproject.toml b/spec/fixtures/uv_lockfile_only/pyproject.toml new file mode 100644 index 000000000..e69de29bb diff --git a/spec/fixtures/uv_lockfile_only/uv.lock b/spec/fixtures/uv_lockfile_only/uv.lock new file mode 100644 index 000000000..e69de29bb diff --git a/spec/hatchet/package_manager_spec.rb b/spec/hatchet/package_manager_spec.rb index e390d62e8..1b2e0ffe1 100644 --- a/spec/hatchet/package_manager_spec.rb +++ b/spec/hatchet/package_manager_spec.rb @@ -31,6 +31,53 @@ remote: ! Otherwise, add a package manager file to your app. If your app has remote: ! no dependencies, then create an empty 'requirements.txt' file. remote: ! + remote: ! If you would like to see support for the package manager uv, + remote: ! please vote and comment on these GitHub issues: + remote: ! https://github.com/heroku/heroku-buildpack-python/issues/1616 + remote: ! https://github.com/heroku/roadmap/issues/323 + remote: ! + remote: ! For help with using Python on Heroku, see: + remote: ! https://devcenter.heroku.com/articles/getting-started-with-python + remote: ! https://devcenter.heroku.com/articles/python-support + remote: + remote: ! Push rejected, failed to compile Python app. + OUTPUT + end + end + end + + context 'when there is a uv.lock' do + let(:app) { Hatchet::Runner.new('spec/fixtures/uv_lockfile_only', allow_failure: true) } + + it 'fails the build with an informative error message' do + app.deploy do |app| + expect(clean_output(app.output)).to include(<<~OUTPUT) + remote: -----> Python app detected + remote: + remote: ! Error: Couldn't find any supported Python package manager files. + remote: ! + remote: ! A Python app on Heroku must have either a 'requirements.txt', + remote: ! 'Pipfile' or 'poetry.lock' package manager file in the root + remote: ! directory of its source code. + remote: ! + remote: ! Currently the root directory of your app contains: + remote: ! + remote: ! uv.lock + remote: ! + remote: ! If your app already has a package manager file, check that it: + remote: ! + remote: ! 1. Is in the top level directory (not a subdirectory). + remote: ! 2. Has the correct spelling (the filenames are case-sensitive). + remote: ! 3. Isn't listed in '.gitignore' or '.slugignore'. + remote: ! + remote: ! Otherwise, add a package manager file to your app. If your app has + remote: ! no dependencies, then create an empty 'requirements.txt' file. + remote: ! + remote: ! If you would like to see support for the package manager uv, + remote: ! please vote and comment on these GitHub issues: + remote: ! https://github.com/heroku/heroku-buildpack-python/issues/1616 + remote: ! https://github.com/heroku/roadmap/issues/323 + remote: ! remote: ! For help with using Python on Heroku, see: remote: ! https://devcenter.heroku.com/articles/getting-started-with-python remote: ! https://devcenter.heroku.com/articles/python-support