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
Allow gdal config via GDAL_INCLUDE/LIBRARY_PATH env variables (Simplify building on Windows with environment variables) #47
Allow gdal config via GDAL_INCLUDE/LIBRARY_PATH env variables (Simplify building on Windows with environment variables) #47
Conversation
setup.py
Outdated
@@ -89,7 +89,7 @@ def read_response(cmd): | |||
try: | |||
gdalinfo_path = None | |||
for path in os.getenv("PATH", "").split(os.pathsep): | |||
matches = list(Path(path).glob("**/gdalinfo*")) | |||
matches = list(Path(path).glob("**/gdalinfo.exe")) |
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 made this change because in my latest conda env, this was not working (while gdalinfo is available in a conda env on windows). The reason for this is that the current glob also found other gdalinfo occurences:
> c:\users\joris\scipy\pyogrio\setup.py(93)<module>()
-> matches = list(Path(path).glob("**/gdalinfo*"))
(Pdb) path
'C:\\Users\\joris\\miniconda3\\envs\\geo-dev'
(Pdb) n
> c:\users\joris\scipy\pyogrio\setup.py(94)<module>()
-> if matches:
(Pdb) matches
[WindowsPath('C:/Users/joris/miniconda3/envs/geo-dev/Lib/site-packages/osgeo_utils/samples/gdalinfo.py'), WindowsPath('C:/Users/joris/miniconda3/envs/geo-dev/Lib/site-packages/osgeo_utils/samples/__pycache__/gdalinfo.cpython-310.pyc'), WindowsPath('C:/Users/joris/miniconda3/envs/geo-dev/Library/bin/gdalinfo.exe')]
To make this more generic, we might also want to allow setting those variables on linux / mac ? (pygeos does that as well) |
Yeah, I can imagine it can be useful in some cases. |
Thanks for working on this @jorisvandenbossche ! This will be helpful.
Yes, this is a good idea, and in terms of precedence we should probably check those before and instead of using Presumably we'd want precedence in this order?
But we should also think about trying to keep those as an atomic unit, to simplify the logic. Meaning, |
That precedence order looks good. I am only not sure if we can control the precedence for the flags passed to
Yes, I think that is fine (I now already did that for the two path variables, to only use them if both are specified. And could add a warning if only some are specified) There is one issue for that, and that's the name of the GDAL library. On Linux (and Mac?), this is |
Is it actually needed to require to specify GDAL_VERSION as well if GDAL_INCLUDE_PATH/GDAL_LIBRARY_PATH are specified? Because on Windows, that could be taken from |
include_dir = os.environ.get("GDAL_INCLUDE_PATH") | ||
library_dir = os.environ.get("GDAL_LIBRARY_PATH") | ||
|
||
if include_dir and library_dir: | ||
return { | ||
"include_dirs": [include_dir], | ||
"library_dirs": [library_dir], | ||
"libraries": ["gdal_i" if platform.system() == "Windows" else "gdal"], | ||
} |
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.
So the question is whether in this case we want to require that GDAL_VERSION
env variable is set as well? (in which case we can check that to raise an error it too old)
Or do we only want to require this linux/mac? (and on windows still try gdalinfo --version
first)
I don't know how the file name for GDAL library on Windows is determined, so I'm OK with that being hard-coded here. Can always be addressed later if we discover another variant of the name. My concern with not requiring However, we're really only using We have a few options:
At this point, I'm wondering if we want to simplify and go with option 3; none of our actions (i.e., what files to include) at compile time depend on this. |
Option 2 might also still be useful? Or at least check the GDAL version if it can be obtained from the gdal-config / gdalinfo, and otherwise raise a warning if GDAL_VERSION is not specified. |
I like the idea of simplifying, esp. since we're not tightly coupled to only the latest version of GDAL. The likelihood of a user trying to install on GDAL <2.4 is hopefully low, and that's really all taht Since you are already making changes to |
Yes, I can certainly do that. |
Sure, I guess we can keep this for now; probably slightly more likely to encounter incompatible GDAL versions there without expecting it, vs the more deliberate effort required to install GDAL on Windows... |
I suppose I should actually have asked whether to keep the version check for windows in case of a |
I think we can drop this, and just let minimum version be stated in documentation. |
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.
One minor docstring comment, but otherwise looks good to me. I don't have a way of testing on Windows at the moment.
Thanks for your work on this, @jorisvandenbossche !
setup.py
Outdated
def get_gdal_paths(): | ||
"""Obtain the paths for compiling and linking with the GDAL C-API | ||
|
||
First the presence of the GDAL_INCLUDE_PATH and GDAL_LIBRARY_PATH environment |
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.
Suggestion:
GDAL_INCLUDE_PATH and GDAL_LIBRARY_PATH environment variables are used if both are present.
Related to #8
Currently, for installing on source on Windows, we indicate that you need to pass additional flags (to the include and library dirs): https://pyogrio.readthedocs.io/en/latest/install.html#windows. Passing those additional flags gets complicated if not using
python setup.py build_ext
, but eg pip, as noted in #8So this PR adds an alternative way to do this, by specifying environment variables.
This is similar to how pygeos/shapely do it (eg https://github.com/pygeos/pygeos/blob/0835379a5bc534be63037696b1b70cf4337e3841/setup.py#L66-L72)
As a result, I can build locally on Windows with
instead of
(and with pip it's even more a simplification, because of not needing the
--install-option
)Still need to update the docs if we want this.