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

Update fiona hook for compatibility with fiona 1.9.0 #541

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/541.update.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Update ``fiona`` hook for compatibility with ``fiona`` 1.9.0.
2 changes: 2 additions & 0 deletions news/541.update.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Have ``fiona`` hook collect the package's data files (e.g., the
projections database).
2 changes: 1 addition & 1 deletion requirements-test-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dash-uploader==0.6.0
# We install it via apt-get and brew on ubuntu and macOS CI runners, respectively.
discid==1.2.0; sys_platform != 'win32'
fabric==3.0.0
fiona==1.8.22; sys_platform != 'win32'
fiona==1.9.0; sys_platform != 'win32'
folium==0.14.0
ffpyplayer==4.3.5; python_version < '3.10' # doesn't have py310 wheels
geopandas==0.12.2; python_version >= '3.8' and sys_platform != 'win32'
Expand Down
9 changes: 9 additions & 0 deletions src/_pyinstaller_hooks_contrib/hooks/stdhooks/hook-fiona.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,17 @@
# SPDX-License-Identifier: GPL-2.0-or-later
# ------------------------------------------------------------------

from PyInstaller.utils.hooks import collect_data_files, is_module_satisfies

hiddenimports = [
"fiona._shim",
"fiona.schema",
"json",
]

# As of fiona 1.9.0, `fiona.enums` is also a hidden import, made in cythonized `fiona.crs`.
if is_module_satisfies("fiona >= 1.9.0"):
hiddenimports.append("fiona.enums")

# Collect data files that are part of the package (e.g., projections database)
datas = collect_data_files("fiona")
32 changes: 32 additions & 0 deletions src/_pyinstaller_hooks_contrib/tests/test_libraries.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ def test_fiona(pyi_builder):
'''
)


@importorskip('fiona')
def test_fiona_transform(pyi_builder):
# Test that fiona in frozen application has access to its projections database. If projection data is unavailable,
# the transform becomes an identity transform.
pyi_builder.test_source(
"""
from fiona.transform import transform_geom
from fiona.crs import from_epsg

eiffel_tower = {
'type': 'Point',
'coordinates': (2.294694, 48.858093),
}

crs_source = from_epsg(4326) # WGS84
crs_target = from_epsg(25831) # ETRS89 / UTM zone 31N

transformed = transform_geom(crs_source, crs_target, eiffel_tower)
print(f"Transformed point: {transformed}")

# Expected coordinates: obtained by manually running this program unfrozen
EXPECTED_COORDINATES = (448265.9146792292, 5411920.651338793)
EPS = 1e-6

delta = [abs(value - expected) for value, expected in zip(transformed["coordinates"], EXPECTED_COORDINATES)]
print(f"Delta: {delta}")
assert all([value < EPS for value in delta]), f"Delta {delta} exceeds threshold!"
"""
)


@importorskip('jinxed')
def test_jinxed(pyi_builder):
pyi_builder.test_source(
Expand Down