tttapa / py-build-cmake

Modern, PEP 517 compliant build backend for creating Python packages with extensions built using CMake.
https://pypi.org/project/py-build-cmake
MIT License
38 stars 6 forks source link

Namespace packages support 420 #20

Open clamydo opened 8 months ago

clamydo commented 8 months ago

According to the README, this feature is planned. Can you say something about the status please?

What is necessary to implement this feature?

Thank you for this very useful package!

tttapa commented 8 months ago

Version 0.2.0a8 adds experimental namespace package support.

clamydo commented 8 months ago

Awesome and thank you! My first experiments with it were successful. I'm still playing around with the setup though. I'll get back to you if I'm stumbling with it.

clamydo commented 8 months ago

I have a project structure like:

CMakeLists.txt
pyproject.toml
cpp/
  ...
python/
  foobar/
    blu/
       bla/
         __init__.py

and a pyproject.toml like:

[project] # Project metadata
name = "blu.bla"
requires-python = ">=3.8"
license = { "file" = "LICENSE" }
authors = [{ "name" = "bla", "email" = "bla@example.com" }]
dependencies = [
  "pyarrow~=13.0",
]
# dynamic = ["version", "description"]
version = "0.0.dev"

[build-system] # How pip and other frontends should build this project
requires = [
  "py-build-cmake~=0.2.0a8",
  "pybind11~=2.11",
  "pyarrow~=13.0",
]
build-backend = "py_build_cmake.build"

[tool.py-build-cmake.module] # Where to find the Python module to package
directory = "python/foobar"
name = "blu/bla"
namespace = true

[[tool.py-build-cmake.cmake]] # How to build the CMake project
minimum_version = "3.16"
build_type = "Debug"
source_path = "."
build_args = ["--target", "python_extension_target"]
install_args = ["--strip"]
install_components = ["python_modules"]

[tool.py-build-cmake.stubgen] # Whether and how to generate typed stub files

[tool.py-build-cmake.editable]
mode = "symlink"

and I get

  ❌ Error in user configuration:

                Namespace packages should not contain __init__.py (in /home/user/project/python/foobar/blu/bla)

But according to https://packaging.python.org/en/latest/guides/packaging-namespace-packages/ an __init__.py in this position should be legal. Just at the namespace level python/foobar no __init__.py is allowed.

Am I doing something wrong?

tttapa commented 7 months ago

I initially intended directory and name to point to the parent namespace package only. But py-build-cmake should support your use case as well. I'll see if I can implement something next week.