buildpacks-python icon indicating copy to clipboard operation
buildpacks-python copied to clipboard

Support the Poetry package manager

Open edmorley opened this issue 2 years ago • 2 comments

We should support the Poetry package manager: https://python-poetry.org/

See also:

edmorley avatar Feb 28 '23 18:02 edmorley

Hi @edmorley, are there any updates on the availability of this feature—or how to use it, if it is available?

larsakerson avatar Mar 31 '23 18:03 larsakerson

@larsakerson Hi! This GitHub issue is still open, so the feature hasn't been added. Subscribe to this issue to get notified when it's added. (Which will be sometime later this year, but I don't have a timeline more specific than that.)

edmorley avatar Apr 03 '23 11:04 edmorley

Quick status update - preparation for this has been happening in:

  • https://github.com/heroku/buildpacks-python/pull/229
  • https://github.com/heroku/buildpacks-python/pull/233
  • https://github.com/heroku/buildpacks-python/pull/241
  • https://github.com/heroku/buildpacks-python/pull/243
  • https://github.com/heroku/buildpacks-python/pull/256
  • https://github.com/heroku/buildpacks-python/pull/257
  • https://github.com/heroku/buildpacks-python/pull/258

...and I have the actual Poetry support implementation itself working locally. It just needs some final tests and polish and then I should have a PR open for it at some point next week :-)

edmorley avatar Aug 30 '24 16:08 edmorley

Poetry support PR now open: #261.

edmorley avatar Sep 03 '24 16:09 edmorley

Poetry support has now been released in v0.17.0 of this buildpack, and the Heroku CNB builder image updated with the new buildpack version, so Poetry builds now work with the latest version of the builder :-)

  1. git clone https://github.com/heroku/python-getting-started && cd python-getting-started
  2.  cat > pyproject.toml<<'EOF'
     [tool.poetry]
     package-mode = false
    
     [tool.poetry.dependencies]
     python = "3.12.*"
     django = "^5.1"
     gunicorn = "^23"
     dj-database-url = "^2"
     whitenoise = "^6"
     EOF
    
  3. poetry lock
  4. rm requirements.txt
  5. pack build --builder heroku/builder:24 poetry-test
$ pack build --builder heroku/builder:24 poetry-test
24: Pulling from heroku/builder
Digest: sha256:8a5252099ee2717fb69769909f1fca61ee9b4460faf564fab2c937a9f989253d
Status: Image is up to date for heroku/builder:24
24: Pulling from heroku/heroku
Digest: sha256:2363090f27c848b67a06a3a269dac13f042ffeed61af27432bd3bad360ed1d0e
Status: Image is up to date for heroku/heroku:24
===> ANALYZING
Image with name "poetry-test" not found
===> DETECTING
heroku/python   0.17.0
heroku/procfile 3.1.2
===> RESTORING
===> BUILDING

[Determining Python version]
Using Python version 3.12.5 specified in runtime.txt

[Installing Python]
Installing Python 3.12.5

[Installing Poetry]
Installing Poetry 1.8.3

[Installing dependencies using Poetry]
Creating virtual environment
Running 'poetry install --sync --only main'
Installing dependencies from lock file

Package operations: 8 installs, 0 updates, 0 removals

  - Installing asgiref (3.8.1)
  - Installing sqlparse (0.5.1)
  - Installing django (5.1.1)
  - Installing packaging (24.1)
  - Installing typing-extensions (4.12.2)
  - Installing dj-database-url (2.2.0)
  - Installing gunicorn (23.0.0)
  - Installing whitenoise (6.7.0)

[Generating Django static files]
Running 'manage.py collectstatic'

1 static file symlinked to '/workspace/staticfiles', 1 post-processed.

[Discovering process types]
Procfile declares types -> web
===> EXPORTING
Adding layer 'heroku/python:python'
Adding layer 'heroku/python:venv'
Adding layer 'buildpacksio/lifecycle:launch.sbom'
Adding 1/1 app layer(s)
Adding layer 'buildpacksio/lifecycle:launcher'
Adding layer 'buildpacksio/lifecycle:config'
Adding layer 'buildpacksio/lifecycle:process-types'
Adding label 'io.buildpacks.lifecycle.metadata'
Adding label 'io.buildpacks.build.metadata'
Adding label 'io.buildpacks.project.metadata'
Setting default process type 'web'
Saving poetry-test...
*** Images (a4be12101625):
      poetry-test
Adding cache layer 'heroku/python:poetry'
Adding cache layer 'heroku/python:python'
Adding cache layer 'heroku/python:venv'
Successfully built image poetry-test

edmorley avatar Sep 04 '24 09:09 edmorley

Oh and support for selecting the Python version using tool.poetry.dependencies.python is being tracked in: https://github.com/heroku/buildpacks-python/issues/260

In the meantime, use runtime.txt to control the Python version (or omit runtime.txt to use the default Python version).

Note that once support for tool.poetry.dependencies.python lands, it's likely that some builds will error due to use of "unsafe" version ranges in tool.poetry.dependencies.python (see the linked issue for more details). As such, if you are switching to Poetry now and want to prevent potential build errors in the future, I'd recommend using a tool.poetry.dependencies.python value like 3.12.* instead of ^3.12.

edmorley avatar Sep 04 '24 09:09 edmorley