-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Poetry build is naming the wheel incorrectly #3509
Comments
Follow-up: the function |
@abn We've talked previously about an issue around |
Okay, I figured out one issue. If a user has activated their own venv with a tool like pyenv, set The problem comes from this conditional: Here's what happens
Two solutions:
|
Figured out the problem: even after fixing the issue of the blocked venv in the previous comment, the name of the wheel ends up incorrect (it gets labeled 3.9 despite being built by a 3.8 venv). It comes from the function To fix this, I hacked a solution where I pass the environment to the builder classes in Then, instead of using This ends up working correctly. |
It might be worth clarifying:
|
I just replicated using Poetry's own virtual environments so it's not a pyenv thing.
ETA: It's also not a pipx thing as I can replicate it with Poetry installed through homebrew. |
I'm confused about two things here:
I'm not sure which platforms use the |
It's an unsupported feature and it's why this issue is not too big of a priority.
Basically, if you're not building anything, then the package is platform independent and you don't need a fancy wheel name. If you need to build something, say Cython, then the wheel name has to account for the Python version and the platform that did the compiling. |
Seems the same issue as #4168. |
Linking related issue. #2613 |
This assumption is fine as a default but doesn't hold for all use cases. There are cases where the build script is used to create asset files that are needed by the package but which are not platform specific (for example, building a json file for data that's going into the package). Having an option to explicitly say "this is an platform independent package" would be a lot more flexible than having the program try to guess what developers are attempting to do. |
I also have this issue and note that it worked in poetry 1.0.9 but was broken when we moved to 1.1.x |
Here's a script I run after building with poetry to fix the modules. Note that this only works properly if you are using a pure python module- if you are compiling libraries and shipping them then you should not run this script. #!/usr/bin/env bash
set -e
ORIGINAL_PACKAGE=$1
START_DIR=$(pwd)
TEMP_DIR=$(mktemp -d)
WORKING_WHEEL=$TEMP_DIR/package.whl
FINAL_PACKAGE=$(echo $ORIGINAL_PACKAGE | rev | cut -d"-" -f4- | rev)-py3-none-any.whl
if [[ ! -f "$ORIGINAL_PACKAGE" ]]; then
echo "File not found at path $1"
exit 1
fi
cp $ORIGINAL_PACKAGE $WORKING_WHEEL
cd $TEMP_DIR
mkdir unzipped
unzip $WORKING_WHEEL -d unzipped
WHEEL_FILE=$(find unzipped -name "WHEEL")
grep -v '^Root-Is-Purelib' $WHEEL_FILE > $WHEEL_FILE.tmp
grep -v '^Tag' $WHEEL_FILE.tmp > $WHEEL_FILE
rm $WHEEL_FILE.tmp
echo "Root-Is-Purelib: true" >> $WHEEL_FILE
echo "Tag: py3-none-any" >> $WHEEL_FILE
cat $WHEEL_FILE
cd unzipped
zip -r ../universal_package.whl *
cd ..
cd $START_DIR
cp $TEMP_DIR/universal_package.whl $FINAL_PACKAGE I've just started incorporating this into my own build pipelines to get around this bug. |
This should be fixed by python-poetry/poetry-core#227 (it has been working for us for months using a locally patched version). There seem to be a lot of open PRs for poetry and poetry-core, so I'm not sure how to get it reviewed. |
GitHub actions doesn't have M1 and python-poetry/poetry#3509 means that poetry names wheels incorrectly, so cibuildwheel can't be used to cross-compile.
Just reporting this issue still occurs with Poetry 1.3.1. Because our wheels package binaries compiled with Cython, we need to upload a wheel per Python version to PyPI. After running For further color, this occurs on both Linux and macOS, and pyenv exists for both environments I tested this on. It could be that Poetry uses the Python where it was installed for the file name, rather than the version of the virtualenv which is active? |
Same issue here, with poetry 1.3.1. @cjdsellers care to share how you are changing the wheel names? Thanks! |
Sure, simply just using |
So no automated script? Do you also need to change the "Root-Is-Purelib: true" line like in this comment? |
I'm only modifying the file name, its also not a pure Python module like in the example from @tedivm |
Got it! |
My example is really if you want a universal wheel- if you are okay with your wheel being locked to a specific system than renaming it should be fine, but if you want it to actually be installable across multiple platforms (which for me was a requirement, as I had to support both ARM and AMD) then you need to update the wheel's internal files to reflect that. |
To be honest though I strongly recommend just not using poetry for building your stuff. It's too buggy and opinionated around local environments so it doesn't offer what's needed to true publishing. Utilizing the build project has been a much nicer experience. |
Thanks for sharing! |
That's what I needed to hear. Thanks @tedivm ! |
After many headaches, I have determined that changing the name of the wheel as recommended by previous comments is not enough in my case. I am trying to publish these wheel files to pypi and pypi will check the md5sum of each uploaded file. After manually changing the name, the md5 is of course still the same. I am moving away from poetry for the time being. |
If the hash is the same, it sounds like you may have a universal wheel though? i.e. you could potentially get away with a single wheel for all Python versions. |
I have a shared object file that needs to be compiled on different platforms. And to clarify: the md5 mentioned above is not just the name. What I meant to say is that two files with different names have the same md5 because their contents are the same. |
Well I mean, this is definitely still a bug. |
Oh absolutely! Sorry for hijacking the thread 😅 |
You didn't really hijack the thread, just pointed out another reason why poetry should not be used to build wheels that are meant to be published. |
@tedivm: IMO your statement is to broad. If you mean "don't use Poetry to build wheels if you need a custom build script" I could agree, because |
Here's a temporary solution I also shared here: #!/bin/bash
# Rename the wheel file to match the currently active python version
wheel_file=$(find dist/ -type f -name '*.whl')
echo "Renaming ${wheel_file}"
python_ver=$(python -c 'import platform; print("".join(platform.python_version_tuple()[:2]))')
echo "Using Python version: ${python_ver}"
new_wheel_file=$(echo ${wheel_file} | sed "s/-cp[0-9]*/-cp${python_ver}/g")
echo "New wheel file name: ${new_wheel_file}"
mv ${wheel_file} ${new_wheel_file} |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
I am on the latest Poetry version.
I have searched the issues of this repo and believe that this is not a duplicate.
If an exception occurs when executing a command, I executed it again in debug mode (
-vvv
option).macOS 10.15.7
1.1.4
poetry-core 1.0.0
Issue
This is a spin off of #3508 as further investigation revealed there were two problems uncovered. This is about the naming of the wheels when using
poetry build
.Poetry is giving the wrong version tag to the built wheel. The following is the output of Poetry build:
Here is how poetry is installed:
Poetry config:
And here is the project definition that requires a build (note that the project is exclusively Python 3.8).
Project virtual environment:
pyproject.toml
:build.py
:Probable Reason
poetry-core
generates the information for the wheel tag here:https://github.com/python-poetry/poetry-core/blob/master/poetry/core/masonry/builders/wheel.py#L244
The vendored packaged
packaging
produces the tags here:https://github.com/python-poetry/poetry-core/blob/master/poetry/core/_vendor/packaging/tags.py#L744
Finally, it looks like since no kwargs are passed to
sys_tags
, then the argumentpython_version
isn't passed tocpython_tags
and it defaults to the system Python, ie whatever is running Poetry.https://github.com/python-poetry/poetry-core/blob/master/poetry/core/_vendor/packaging/tags.py#L234
The text was updated successfully, but these errors were encountered: