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

src vs src-python #19

Closed dpdani closed 9 months ago

dpdani commented 9 months ago

Hello 👋

Just a question, more than an issue.

In the minimal example (as well as the others, but this is the one I read through), the src folder containing source files to be compiled is separated from a src-python folder containing the python package itself.

Intuitively, I was going to put extension files together with python files. Would this be a bad idea?

Also, assuming separation is nice, would there be a counter-point to having a structure like this?

+ package
  + src
    + py_package
        - __init__.py
        - ...
    + extension  # no CMakeLists.txt here
        - spam.c
    + include
       - spam.h
  - pyproject.toml
  - CMakeLists.txt
  - ...
tttapa commented 9 months ago

I don't think there's a right or wrong answer, it just comes down to preference.
(As long as you don't put the .c files in the src/py_package folder, because that would cause them to be included when installing the Python package, which is probably not what you want.)

The structure you propose looks good to me.

The reasons why I use a separate src-python folder in the example are 1. to show that you can select a custom folder if you want to, and 2. because in my personal projects, the interesting code is usually in the C++ source files, so I like to keep it separate from the (less interesting) Python wrapping scripts.

dpdani commented 9 months ago

Thank you for the clarification 🙏

What happens when one puts C files in e.g. the src/py_package folder above? Included = shipped with the sdist?

tttapa commented 9 months ago

Not just in the sdist (you want them to be in the sdist), but also in the compiled wheels, meaning that they will be installed to the user's site-packages folder alongside the .py files of your project.

dpdani commented 9 months ago

But only implies that the user will receive the source alongside the compiled .so in the wheel file. As far as I understand, it wouldn't break anything. Right?

tttapa commented 9 months ago

Exactly.

dpdani commented 9 months ago

Thanks!