isciences / exactextract

Fast and accurate raster zonal statistics
Apache License 2.0
246 stars 32 forks source link

Python: Declare `project.ini` to be included as part of sdist #70

Closed kylebarron closed 7 months ago

kylebarron commented 7 months ago
git clone https://github.com/isciences/exactextract
cd exactextract/python/
python -m build .

should work, but doesn't. The issue is that python -m build creates an isolated venv that is not in-tree for building.

You can also see this issue if you run

python -m build . --sdist
tar -ztvf dist/exactextract-0.2.0.dev0.tar.gz | grep project.ini
# no files found

which creates an sdist that does not include project.ini, and so you can't build from that sdist because setup.py expects to find that config file.

kylebarron commented 7 months ago

It looks like even when you include extra files (by creating a MANIFEST.in file with

include project.ini

and including VersionSource.cmake), it still doesn't work because it isn't able to find all the cmake conf files.

As more context, I generally prefer python -m build to pip install because the latter installs all build dependencies in your current environment.

Possibly the more important part is that no one can build from your sdist because it doesn't include the cmake files. E.g.

python -m build . --sdist
pip install ./dist/exactextract-0.2.0.dev0.tar.gz

gives

      CMake Warning:
        Ignoring extra path from command line:

         "/private/var/folders/42/5jr6891d4ds4xysz7q0rsghw0000gn/T"

      CMake Error: The source directory "/private/var/folders/42/5jr6891d4ds4xysz7q0rsghw0000gn/T" does not appear to contain CMakeLists.txt.
      Specify --help for usage, or press the help button on the CMake GUI.
dbaston commented 7 months ago

Yes, I think I'm causing all manner of problems by having setup.py and friends in the python dir, rather than at the root of the repo. I've been intending to check out solutions like https://github.com/maximiliank/cmake_python_r_example. Alternatively I could put the Python bindings in a separate repo, but that'll be easier once it settles down a bit more.

kylebarron commented 7 months ago

I don't much C++ work at all myself, but I would point you to https://learn.scientific-python.org/development/guides/packaging-compiled/#packaging-compiled-projects and https://github.com/pybind/cmake_example

dbaston commented 7 months ago

Thank you @kylebarron for the analysis and the suggestion to revisit scikit-build-core.