python-poetry-buildpack icon indicating copy to clipboard operation
python-poetry-buildpack copied to clipboard

Python version extraction breaks if a trailing space exists

Open ferndot opened this issue 2 years ago • 4 comments

Hello! It appears that Python version extraction is currently breaking if the python-versions = "x.x.x" line in poetry.lock includes a trailing space. This trailing space will be added if the Python version specification in pyproject.toml also includes a trailing space. I found this because the VSCode TOML plugin I am using adds these spaces: https://github.com/oovm/vscode-toml/issues/7.

When that happens, the Heroku build fails with the following message:

-----> 3.9.11  is not valid, please specify an exact Python version (e.g. 3.8.1) in your pyproject.toml (and thus poetry.lock)

To make this more robust, I propose that we strip out spaces in this command: https://github.com/moneymeets/python-poetry-buildpack/blob/868d88bd7a4b11e62d57dbf673394ebf38962857/bin/compile#L85

ferndot avatar Jul 18 '22 20:07 ferndot

I may have a chance to contribute a patch, but wanted to put this up in case someone else gets to it first!

ferndot avatar Jul 18 '22 20:07 ferndot

Oh, that's a good catch. I wonder if adjusting tr set would be enough:

-PYTHON_RUNTIME_VERSION="$(sed -n -e '/^\[metadata\]/,/^\[/p' poetry.lock | sed -n -e 's/^python-versions\s*=\s*//p' | tr -d \"\')" 
+PYTHON_RUNTIME_VERSION="$(sed -n -e '/^\[metadata\]/,/^\[/p' poetry.lock | sed -n -e 's/^python-versions\s*=\s*//p' | tr -d \" \')" 

A PR with a test would be appreciated.

zyv avatar Jul 19 '22 06:07 zyv

Since we are at it, maybe you could have a look @felix11h ?

zyv avatar Sep 02 '22 13:09 zyv

Since we are at it, maybe you could have a look @felix11h ?

Sure thing, I will have a look! I'm hoping to get to it next week.

felix11h avatar Sep 07 '22 10:09 felix11h