Constrain GDAL to one minor version for wheel builds#2487
Constrain GDAL to one minor version for wheel builds#2487emlys wants to merge 15 commits intonatcap:mainfrom
Conversation
|
|
||
| # Read in requirements.txt and populate the python readme with the | ||
| # non-comment, non-environment-specifier contents. | ||
| _REQUIREMENTS = [req.split(';')[0].split('#')[0].strip() for req in |
There was a problem hiding this comment.
This is not a necessary change for this PR, but we might as well take advantage of the support for reading a requirements file directly in pyproject.toml.
There was a problem hiding this comment.
Yep, makes sense to consolidate towards pyproject.toml wherever possible!
| # the version is provided dynamically by setuptools_scm | ||
| # `dependencies` and `optional-dependencies` are provided by setuptools | ||
| # using the corresponding setup args `install_requires` and `extras_require` | ||
| dynamic = ["version", "dependencies", "optional-dependencies"] |
There was a problem hiding this comment.
We're not using optional-dependencies (though maybe we should!), so I removed it for now.
There was a problem hiding this comment.
Thanks @emlys ! I really like the solution of modifying requirements.txt, but wouldn't doing so also cause the version string to be modified since there would now be uncommitted changes? I offered a possible alternative that might be the kind of thing that would modify the library requirements before the wheel is built, which is the kind of thing we used to have to do when setuptools was in its heyday. Looking ahead, there's probably a more modern way to do this since setuptools is probably past its prime.
|
|
||
| # Read in requirements.txt and populate the python readme with the | ||
| # non-comment, non-environment-specifier contents. | ||
| _REQUIREMENTS = [req.split(';')[0].split('#')[0].strip() for req in |
There was a problem hiding this comment.
Yep, makes sense to consolidate towards pyproject.toml wherever possible!
| # The C++ extensions will be compiled and linked against the libgdal version | ||
| # that's in the build environment, and so that same libgdal version has to be | ||
| # available in the target environment. Each libgdal version corresponds to a | ||
| # minor version of GDAL itself. Adding this requirement to the package metadata | ||
| # should prevent it from being installed in an env without the necessary libgdal. | ||
| # Users who need a different GDAL version can use the conda-forge package or | ||
| # build their own wheel from source. | ||
| - name: Add gdal constraint for wheel | ||
| run: echo "gdal==${{ env.GDAL_VERSION_SPECIFIER_FOR_WHEEL }}" >> requirements.txt | ||
|
|
There was a problem hiding this comment.
Won't this direct modification of requirements.txt result in a .d<today> dirty tag in the version?
Personally, I am hopeful that we might be able to write a new custom command for setup.py since we're still using the setuptools build backend. Something like this, maybe? I think doing this should result in the version being unchanged.
diff --git a/setup.py b/setup.py
index 8dcb559d1..35bca5ca1 100644
--- a/setup.py
+++ b/setup.py
@@ -5,6 +5,7 @@ import subprocess
import numpy
from Cython.Build import cythonize
from setuptools import setup
+from setuptools.command.bdist_wheel import bdist_wheel
from setuptools.command.build_py import build_py as _build_py
from setuptools.extension import Extension
@@ -58,6 +59,12 @@ class build_py(_build_py):
# then execute the original run method
_build_py.run(self)
+class CustomWheel(bdist_wheel):
+ def run(self):
+ # Dynamically modify requirements before the wheel is packed
+ self.distribution.install_requires.append("gdal==3.10.*")
+ bdist_wheel.run(self)
+
setup(
install_requires=_REQUIREMENTS,
@@ -92,6 +99,8 @@ setup(
], compiler_directives={'language_level': '3'}),
include_dirs=[numpy.get_include()],
cmdclass={
- 'build_py': build_py
+ 'build_py': build_py,
+ 'build_wheel': CustomWheel,
+ 'bdist_wheel': CustomWheel,
}
)There was a problem hiding this comment.
And also, I'm sorry about the deep setuptools stuff! It was always arcane, and I've spent way too much time mired in setuptools subclasses over the years, so this kind of modification seems like it should work, but there is probably a way better way to to it.
phargogh
left a comment
There was a problem hiding this comment.
Huh, looks like it didn't post my response as commented, github is saying that I saw the review but didn't actually post my response? I'll try resubmitting here.
|
@phargogh that's a very good point, thanks for catching that! The custom build class you suggest does seem like a valid solution. A couple other possibilities come to mind:
I do want to prioritize moving in the direction of using |
|
Of the two options you mention, I too prefer the On the specific point about requirements.txt being a pip format and not in setuptools, that is a really good point! And I agree with you that the dependencies should be defined in pyproject.toml instead of in requirments.txt. But for the case where we are modifying the wheel build config, we can still remove the |
|
Ok, you've convinced me that the requirement belongs in the regular wheel without needing a modifier. The custom wheel class you suggest seems like a good solution! I'm just a little hesitant to add more code to A possible alternative I found in PEP 517 would be to implement an in-tree build backend that overrides However, this is at least as arcane as the the custom class approach, and requires slightly more code and an additional file. What do you think? |
|
I think this is a great solution! Definitely still a little arcane, but I have to say that it is so nice to have officially-supported build hooks like this that are well defined, well-documented and unlikely to break in a bugfix release of some distutils derivative that you didn't know your builds depended on. It's still a little obscure, but SO much better than the blog-based rumors and old stackoverflow posts that we had to rely on for setup.py modifications. So yes, I think this would be AWESOME and I totally agree that it'd be way better to move this away from setup.py. hopefully the new file won't be a big burden to write, but I don't imagine it would be for this particular case. |
Description
Fixes #2206, #2483
Added an extra GDAL constraint to the wheel build environment and package dependencies. Removed the
auditwheelstep from the wheel builds on linux.Checklist