Skip to content
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

Add shim module and support for GDAL 3 #804

Merged
merged 17 commits into from Oct 21, 2019
Merged

Add shim module and support for GDAL 3 #804

merged 17 commits into from Oct 21, 2019

Conversation

sgillies
Copy link
Member

@sgillies sgillies commented Oct 17, 2019

I propose to merge this and make a 1.8.9 release without fixing the Appveyor build so that we can ease the PROJ 4/6 pain of users. Let's tackle the Appveyor updates in the master branch.

Summary of the PR:

  • Adds a shim module for GDAL 3, introduces two new functions (osr_get_name and osr_set_traditional_axis_mapping_strategy), and adds no-op versions of the functions to the older shims.
  • Everywhere we initialize an OGRSpatialReferenceH object using OSRImportFrom*, we set its axis order to the "traditional" one to preserve the existing axis order.
  • We disable two tests for GDAL 3 because towgs84 and wktext don't surface in GDAL's WKT output anymore.

@hobu you're interested in this, I know. Want to give it a quick scan? I realize that some of the Cython files are archaic and a bit opaque.

@snorfalorpagus any objections?

@rbuffat
Copy link
Contributor

rbuffat commented Oct 17, 2019

Regarding the "TypeError: attrib() got an unexpected keyword argument 'convert'" on travis this might be the reason: https://stackoverflow.com/questions/58189683/typeerror-attrib-got-an-unexpected-keyword-argument-convert

fiona/_shim3.pyx Outdated
@@ -0,0 +1,149 @@
"""Shims on top of ogrext for GDAL versions >= 2.2"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

>= 3.0

- pip install -e .[test]
- "python -m pip wheel -r requirements-dev.txt"
- "python -m pip install -r requirements-dev.txt"
- "GDAL_CONFIG=$GDALINST/gdal-$GDALVERSION/bin/gdal-config python -m pip install --upgrade --force-reinstall --no-use-pep517 -e .[test]"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose you didn't want to include the --upgrade again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to leave it for now. This is copied from rasterio and we haven't had a problem there yet.

@coveralls
Copy link

coveralls commented Oct 17, 2019

Coverage Status

Coverage increased (+0.03%) to 82.903% when pulling 7371b7d on gdal3 into da226d9 on maint-1.8.

@sgillies sgillies self-assigned this Oct 18, 2019
@sgillies sgillies added this to the 1.8.9 milestone Oct 18, 2019
@@ -19,6 +19,8 @@ cdef OGRFieldSubType get_field_subtype(void *fielddefn)
cdef void set_field_subtype(void *fielddefn, OGRFieldSubType subtype)
cdef bint check_capability_create_layer(void *cogr_ds)
cdef void *get_linear_geometry(void *geom)
cdef const char* osr_get_name(OGRSpatialReferenceH hSrs)
Copy link
Member Author

@sgillies sgillies Oct 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is copied from rasterio. It isn't called in fiona yet, but it will be in a future version as we change our modules to be more like those in rasterio. Therefore, I'm going to leave it in.

else:
raise ValueError("Invalid CRS")

# Fixup, export to WKT, and set the GDAL dataset's projection.
OSRFixup(cogr_srs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this OSRFixup call should be still used in GDAL < 3.0. Supporting both version scenarios is probably complicated, however.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you see any harm in having osr_set_traditional_axis_mapping_strategy call OSRFixup for GDAL versions 1 and 2 @hobu ? That's one way to bring it back in.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No harm, but that's not quite where you want it. You want it right after any ImportFromWkt-type calls happen where the input might be ESRI content.

@hobu
Copy link
Member

hobu commented Oct 18, 2019

Some test failures in path finding stuff using @conda-forge:

(fiona) [hobu@kasai fiona (gdal3)]$ cs2cs
Rel. 6.2.0, September 1st, 2019
usage: cs2cs [-dDeEfIlrstvwW [args]] [+opt[=arg] ...]
                   [+to +opt[=arg] ...] [file ...]
(fiona) [hobu@kasai fiona (gdal3)]$ gdalinfo --version
GDAL 3.0.1, released 2019/06/28
_______________________ test_gdal_data_wheel ________________________

    @pytest.mark.wheel
    def test_gdal_data_wheel():
        """Get GDAL data path from a wheel"""
>       assert GDALDataFinder().search() == os.path.join(os.path.dirname(fiona.__file__), 'gdal_data')
E       AssertionError: assert None == '/Users/hobu/dev/git/fiona/fiona/gdal_data'
E        +  where None = <bound method GDALDataFinder.search of <fiona._env.GDALDataFinder object at 0x116194588>>()
E        +    where <bound method GDALDataFinder.search of <fiona._env.GDALDataFinder object at 0x116194588>> = <fiona._env.GDALDataFinder object at 0x116194588>.search
E        +      where <fiona._env.GDALDataFinder object at 0x116194588> = GDALDataFinder()
E        +  and   '/Users/hobu/dev/git/fiona/fiona/gdal_data' = <function join at 0x10f6cfe18>('/Users/hobu/dev/git/fiona/fiona', 'gdal_data')
E        +    where <function join at 0x10f6cfe18> = <module 'posixpath' from '/Users/hobu/miniconda3/envs/fiona/lib/python3.7/posixpath.py'>.join
E        +      where <module 'posixpath' from '/Users/hobu/miniconda3/envs/fiona/lib/python3.7/posixpath.py'> = os.path
E        +    and   '/Users/hobu/dev/git/fiona/fiona' = <function dirname at 0x10f6e7158>('/Users/hobu/dev/git/fiona/fiona/__init__.py')
E        +      where <function dirname at 0x10f6e7158> = <module 'posixpath' from '/Users/hobu/miniconda3/envs/fiona/lib/python3.7/posixpath.py'>.dirname
E        +        where <module 'posixpath' from '/Users/hobu/miniconda3/envs/fiona/lib/python3.7/posixpath.py'> = os.path
E        +      and   '/Users/hobu/dev/git/fiona/fiona/__init__.py' = fiona.__file__

tests/test_data_paths.py:16: AssertionError
_______________________ test_proj_data_wheel ________________________

    @pytest.mark.wheel
    def test_proj_data_wheel():
        """Get GDAL data path from a wheel"""
>       assert PROJDataFinder().search() == os.path.join(os.path.dirname(fiona.__file__), 'proj_data')
E       AssertionError: assert '/Users/hobu/...na/share/proj' == '/Users/hobu/d...ona/proj_data'
E         - /Users/hobu/miniconda3/envs/fiona/share/proj
E         + /Users/hobu/dev/git/fiona/fiona/proj_data

tests/test_data_paths.py:22: AssertionError
_____________________ test_env_gdal_data_wheel ______________________

    @pytest.mark.wheel
    def test_env_gdal_data_wheel():
        runner = CliRunner()
        result = runner.invoke(main_group, ['env', '--gdal-data'])
        assert result.exit_code == 0
>       assert result.output.strip() == os.path.join(os.path.dirname(fiona.__file__), 'gdal_data')
E       AssertionError: assert '/Users/hobu/...na/share/gdal' == '/Users/hobu/d...ona/gdal_data'
E         - /Users/hobu/miniconda3/envs/fiona/share/gdal
E         + /Users/hobu/dev/git/fiona/fiona/gdal_data

tests/test_data_paths.py:30: AssertionError
_____________________ test_env_proj_data_wheel ______________________

    @pytest.mark.wheel
    def test_env_proj_data_wheel():
        runner = CliRunner()
        result = runner.invoke(main_group, ['env', '--proj-data'])
        assert result.exit_code == 0
>       assert result.output.strip() == os.path.join(os.path.dirname(fiona.__file__), 'proj_data')
E       AssertionError: assert '/Users/hobu/...na/share/proj' == '/Users/hobu/d...ona/proj_data'
E         - /Users/hobu/miniconda3/envs/fiona/share/proj
E         + /Users/hobu/dev/git/fiona/fiona/proj_data

tests/test_data_paths.py:38: AssertionError
= 4 failed, 875 passed, 6 skipped, 1 xfailed, 6 xpassed in 11.08 seconds =

@hobu
Copy link
Member

hobu commented Oct 18, 2019

Small cast nit 1b5081a

@hobu
Copy link
Member

hobu commented Oct 18, 2019

Bumping up the requirements got me over the attrib issue on windows. The important one is coverage, but maybe it is time to bump the rest.

diff --git a/requirements-dev.txt b/requirements-dev.txt
index 975aeb3..7df9078 100644
--- a/requirements-dev.txt
+++ b/requirements-dev.txt
@@ -1,8 +1,8 @@
 -r requirements.txt
-coverage==4.5.1
-cython==0.28.3
-pytest==3.4.2
+coverage==4.5.4
+cython==0.29.13
+pytest==5.2.1
 pytest-cov==2.5.1
 setuptools==39.0.1
 boto3==1.9.19
-wheel==0.31.1
+wheel==0.31.1
\ No newline at end of file

@sgillies
Copy link
Member Author

@hobu skip those tests with pytest -m "not wheel". I haven't yet figured out how to make these tests not run by default using a marker.

@hobu
Copy link
Member

hobu commented Oct 18, 2019

pytest -m "not wheel

ok, with that and the requirements bump, my windows tests are clean.

@snowman2
Copy link
Contributor

Everywhere we initialize an OGRSpatialReferenceH object using OSRImportFrom*, we set its axis order to the "traditional" one to preserve the existing axis order.

I would recommend against this approach as it will change the CRS and it will be different on export. I would recommend only doing so when doing a transformation operation where it is needed.

@sgillies
Copy link
Member Author

@snowman2 I believe the code here is consistent with GDAL and OGR. See in https://gdal.org/development/rfc/rfc73_proj6_wkt2_srsbarn.html:

Vector layers mostly all call SetAxisMappingStrategy(OAMS_TRADITIONAL_GIS_ORDER) on the OGRSpatialReference* returned by GetSpatialRef().

@sgillies sgillies merged commit e0d015b into maint-1.8 Oct 21, 2019
@jorisvandenbossche
Copy link
Member

On the conda-forge builds that use GDAL 3, it is complaining about "undefined symbol: OSRFixup" (conda-forge/fiona-feedstock#143), but that symbol should only be used when built against GDAL 1/2 ?

@rbuffat
Copy link
Contributor

rbuffat commented Oct 22, 2019

@jorisvandenbossche it is important that setup.py needs to know about the correct gdal version. I don't fully understand your build system. Maybe the problem is that you pin gdal to 2.4 in https://github.com/conda-forge/fiona-feedstock/blob/8a8798d39c129ebfc1817808ef7298aaf0f4e0ef/recipe/bld.bat#L2 ?

@jorisvandenbossche
Copy link
Member

That's for windows, which does not yet have GDAL 3 builds I think (and the windows builds are also passing). For linux (https://github.com/conda-forge/fiona-feedstock/blob/master/recipe/build.sh) it does not seem to be pinned like that.
Fiona does not detect the available GDAL version automatically (if it can find it) when running setup.py ?

@rbuffat
Copy link
Contributor

rbuffat commented Oct 22, 2019

@jorisvandenbossche Maybe I found the issue: setup.py chooses _shim2.c instead of _shim3.c for gdal3. I created a PR to fix this: #807

@sgillies As a side note, we log information in setup.py. Do you know how to display these logs?

@sgillies
Copy link
Member Author

@rbuffat thank you, that PR does the trick. I've made this mistake before and it comes from not building the wheels from a source distribution, but from a repo checkout. I need to change that.

Fiona 1.8.9.post1 is being built now.

@jorisvandenbossche
Copy link
Member

@rbuffat thanks a lot for fixing that!

@sgillies
Copy link
Member Author

See https://stackoverflow.com/a/8710759 for a pointer on setup.py logging.

@jorisvandenbossche
Copy link
Member

The builds for GDAL 3 are passing, but now the builds for GDAL 2.4 are failing. Importing the build package gives:

  File "fiona/ogrext.pyx", line 1, in init fiona.ogrext
ImportError: No module named _shim

@jorisvandenbossche
Copy link
Member

A typo in the merged PR (minor -> major) is the reason for that, I assume, see https://github.com/Toblerity/Fiona/pull/807/files#r337729479

@jorisvandenbossche
Copy link
Member

With fiona 1.8.9.post2, all builds are passing now for conda-forge: conda-forge/fiona-feedstock#145

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants