Skip to content

poetry-core does not execute build function in build.py #7470

@cdgriffith

Description

@cdgriffith
  • Poetry version: 1.3.2
  • Python version: 3.10.9
  • OS version and name: Windows 11
  • pyproject.toml:
  • I am on the latest stable Poetry version, installed using a recommended method.
  • I have searched the issues of this repo and believe that this is not a duplicate.
  • I have consulted the FAQ and blog for any relevant entries or release notes.
  • If an exception occurs when executing a command, I executed it again in debug mode (-vvv option) and have included the output below.

Issue

Trying to switch to the lighter poetry-core for building wheels, but the build function is not executed inside the build.py file.

Using poetry.core as the build backend, I will only see Build File Imported (custom print statements in build.py) and neither build function is called.

However if I switch the build system back to the old method of just poetry:

[build-system]
requires = ["poetry", "Cython", "setuptools", "wheel"]
build-backend = "poetry.masonry.api"

Everything will work fine when I run pip wheel . -v and show both:

Build File Imported
Build with Cython

build.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
from setuptools.command.build_ext import build_ext

from pathlib import Path
import shutil

root = Path(__file__).parent

print("Build File Imported")

def copy_files():
    # Why does poetry put include files at the root of site-packages? So bad! Copy them inside the package
    shutil.copy(root / "AUTHORS.rst", root / "box" / "AUTHORS.rst")
    shutil.copy(root / "CHANGES.rst", root / "box" / "CHANGES.rst")
    shutil.copy(root / "LICENSE", root / "box" / "LICENSE")
    shutil.copy(root / "box_logo.png", root / "box" / "box_logo.png")


try:
    from Cython.Build import cythonize
except ImportError:
    # Got to provide this function. Otherwise, poetry will fail
    def build(setup_kwargs):
        print("Build without Cython")
        copy_files()


# Cython is installed. Compile
else:
    # This function will be executed in setup.py:
    def build(setup_kwargs):
        print("Build with Cython")
        copy_files()
        # Build
        setup_kwargs.update(
            {
                "ext_modules": cythonize(
                    [
                        str(file.relative_to(root))
                        for file in Path(root, "box").glob("*.py")
                        if file.name != "__init__.py"
                    ],
                    compiler_directives={"language_level": 3},
                ),
            }
        )

Package itself is https://github.com/cdgriffith/Box/blob/master/pyproject.toml and issue brought up by cdgriffith/Box#244

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/bugSomething isn't working as expectedstatus/triageThis issue needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions