Page MenuHomePhabricator

Python buildpack does not detect requirements from pyproject.toml
Open, Stalled, Needs TriagePublicBUG REPORT

Description

Modern Python packaging is quite flexible and arguably un-pythonic in that there is no longer one obvious way to do it. For many of my projects I have chosen to use Hatchling as a more reliable build backend than setuptools. One of the benefits of Hatchling is that it consolidates configuration into a pyproject.toml file including project dependencies.

Toolforge build seems to be using https://github.com/heroku/buildpacks-python/tree/v0.8.0 as its Python buildpack. This buildpack detects that it should be used when a pyproject.toml file is present, but when the builder runs it fails the build if it cannot also find a requirements.txt file:

[step-build] 2023-12-19T23:04:07.119771032Z [Error: No Python package manager files were found]
[step-build] 2023-12-19T23:04:07.119780610Z A Pip requirements file was not found in your application's source code.
[step-build] 2023-12-19T23:04:07.119787689Z This file is required so that your application's dependencies can be installed.
[step-build] 2023-12-19T23:04:07.119794349Z
[step-build] 2023-12-19T23:04:07.119800469Z Please add a file named exactly 'requirements.txt' to the root directory of your
[step-build] 2023-12-19T23:04:07.119807049Z application, containing a list of the packages required by your application.
[step-build] 2023-12-19T23:04:07.119813382Z
[step-build] 2023-12-19T23:04:07.119819439Z For more information on what this file should contain, see:
[step-build] 2023-12-19T23:04:07.119826013Z https://pip.pypa.io/en/stable/reference/requirements-file-format/
[step-build] 2023-12-19T23:04:07.119832378Z
[step-build] 2023-12-19T23:04:07.120630642Z ERROR: failed to build: exit status 1

Event Timeline

I tagged this as Upstream because I think it fundamentally is an upstream issue. We could try to find a different Python buildpack (or make our own) if this rises to the level of being an intractable problem. For now though I mostly wanted it documented in Phabricator in case others run into it and are confused about what to do to work around the issue.

For my use case in https://gitlab.wikimedia.org/toolforge-repos/gitlab-account-approval, it turns out that adding this requirements.txt was all that was needed:

requirements.txt
# T353762: requirements.txt for heroku/python 0.8.0 buildpack
# Install our local glaab package in the container.
# Additional dependencies will be installed by the hatchling backend when
# pip invokes it to build our package.
.

I've added the link to this task to all the bulidservice python tutorials for people to discover :)