-
Notifications
You must be signed in to change notification settings - Fork 56
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
Make meson-python usage example more idiomatic #367
Make meson-python usage example more idiomatic #367
Conversation
- Use `dependency('pybind11')`, which is all that is needed since Meson 1.1.0, - Remove custom C++ compile flags that are not present in the scikit-build-core and Maturin examples (nor seem needed), - Make indentation consistent, - Use `py.install_sources` instead of a more complicated `install_subdir` call,
Thanks! The example here is synced with the cookiecutter, so it needs to be changed there. I can move your changes there. |
Ah, thank you! I was also looking for the sources to be built, but I don't think they exist, right? Rather, it's a super simple hypothetical example? If there's an actual |
Signed-off-by: Henry Schreiner <[email protected]>
bb4e957
to
af2e8fb
Compare
The source is in So those files are exactly what you get if you use cookiecutter/cruft/copier to render the template, are tested to work, and stay updated, etc. |
Hmmm,
|
Ahh, that one needs the package name, of course. The reason I went with |
Signed-off-by: Henry Schreiner <[email protected]>
Sure, it's a toss-up. I think CMake also recommends against globbing? Happy to go back to install_subdir('src/package', py.get_install_dir() / 'package') |
py.install_sources( | ||
[ | ||
'src/{{ cookiecutter.__project_slug }}/__init__.py', | ||
'src/{{ cookiecutter.__project_slug }}/_main.py', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that since I didn't find the source files, I completely made up _main.py
- it likely doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and py.typed
is missing. Let's do install_subdir. Someone can easily move to listing things if they prefer, but the template will work better this way.
CMake does discourage globbing (less-so now that CONFIGURE_DEPENDS exists), but we don't use globbing or even CMake at all for the Python files, those are picked up and installed by the scikit-build-core following the mechanism used in other Python backends, like hatchling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure how that works exactly, but in meson-python it would be a little tricky to get that right. Installing all .py
files is wrong, and the .gitattributes
method doesn't quite work either because that would also exclude .py
files from the sdist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We rip the procedure straight from hatchling. It's based on a "package" list. The default is ["<package_name>", "src/<package_name>", "python/<package_name>"]
(last of which is unique to scikit-build-core). A user can specify their own custom list, including an empty list, which disables the process. Anything in these packages is included entirely (there is a wheel.exclude
option too for filtering). Anything more exotic than packages needs to be copied around via CMake and won't work as well with editable installs (hatchling has a powerful force-include dict that we might also add a some point).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the context! I'll have to look into that, it does sound potentially useful.
Signed-off-by: Henry Schreiner <[email protected]>
Signed-off-by: Henry Schreiner <[email protected]>
That is invalid, the following produces an error saying only one argument is supported: install_subdir('src/package', py.get_install_dir() / 'package')
This doesn't install packages correctly, it adds the "src" to the package directory: install_subdir('src/package', install_dir: py.get_install_dir() / 'package')
It needs the directory strip to get rid of the leading "src". |
Signed-off-by: Henry Schreiner <[email protected]>
Ugh, you're right. I never work on packages with the |
Thanks for the quick merge! |
dependency('pybind11')
, which is all that is needed since Meson 1.1.0,py_mod
Python module,Usepy.install_sources
instead of a more complicatedinstall_subdir
call,