Skip to content

Explicit WheelBuilder Platlib Path from Poetry Python Version #9344

@grabpot

Description

@grabpot

Description

I'm trying to build a pybind11 package with several shared libraries using Poetry and setuptools.

The explicit build-platlib definition introduced in PR 634 in poetry-core's WheelBuilder appears to get the plat_specifier from the Poetry Python version, and not the build environment, as _get_sys_tags() does in the same class.

If the Python version used by Poetry, e.g. 3.9, differs to the target build version, e.g. 3.11, this results in the shared lib being copied to the wrong directory, /build/lib.linux-x86_64-cpython-39 instead of /build/lib.linux-x86_64-cpython-311, and the linking failing due to "missing" libraries.

I'm running Poetry 1.7.1, but also tested that it fails to build on latest version. Builds successfully on 1.5.1 prior to explicit definition of build-platlib.

Workarounds

The library_dirs parameter is passed to setuptools when defining the Pybind11Extension ext_modules. My build.py script populates this path, but as it is run in the build environment, it has the correct target Python version. This can be manually changed to match the Poetry Python version.

Poetry Installation Method

install.python-poetry.org

Operating System

Rocky 8.6

Poetry Version

Poetry (version 1.7.1)

Poetry Configuration

cache-dir = "/home/grabpot/.cache/pypoetry"
experimental.new-installer = false
experimental.system-git-client = false
installer.max-workers = null
installer.modern-installation = true
installer.no-binary = null
installer.parallel = true
virtualenvs.create = true
virtualenvs.in-project = true
virtualenvs.options.always-copy = false
virtualenvs.options.no-pip = false
virtualenvs.options.no-setuptools = false
virtualenvs.options.system-site-packages = false
virtualenvs.path = "{cache-dir}/virtualenvs"
virtualenvs.prefer-active-python = true
virtualenvs.prompt = "{project_name}-py{python_version}"
warnings.export = true

Python Sysconfig

No response

Example pyproject.toml

[tool.poetry]
...

[tool.poetry.build]
script = "build.py"
generate-setup-file = true

[build-system]
requires = ["pybind11","setuptools","poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"

Poetry Runtime Logs

/usr/bin/ld: cannot find -lshared_lib1
/usr/bin/ld: cannot find -lshared_lib2
collect2: error: ld returned 1 exit status
error: command '/usr/bin/g++' failed with exit code 1

  CalledProcessError

  Command '['/tmp/tmpduga50vk/.venv/bin/python', '/home/grabpot/code/tmp/project/setup.py', 'build', '-b', '/home/grabpot/code/tmp/project/build', '--build-purelib', '/home/grabpot/code/tmp/project/build/lib', '--build-platlib', '/home/grabpot/code/tmp/project/build/lib.linux-x86_64-cpython-39']' returned non-zero exit status 1.

  at /usr/lib64/python3.9/subprocess.py:373 in check_call
       369│     if retcode:
       370│         cmd = kwargs.get("args")
       371│         if cmd is None:
       372│             cmd = popenargs[0]
    →  373│         raise CalledProcessError(retcode, cmd)
       374│     return 0
       375│ 
       376│ 
       377│ def check_output(*popenargs, timeout=None, **kwargs):

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/build-systemRelated to PEP 517 packaging (see poetry-core)area/coreRelated to the poetry-core librarykind/bugSomething isn't working as expected

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions