Skip to content

Commit

Permalink
better frozen init, bump gdal and proj
Browse files Browse the repository at this point in the history
  • Loading branch information
visr committed Nov 6, 2019
1 parent 863f54c commit 67370be
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
4 changes: 2 additions & 2 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ dependencies:
- python=3.6
- numpy>=1.12
- scipy>=1.0
- gdal>=2.2.4
- gdal>=3
- netcdf4>=1.4.1
- cftime>=1.0.1
- xarray>=0.11
- pyproj=1.9
- pyproj=2.4
- thrift>=0.11
- numba>=0.42
- pyinstaller>=3.3
Expand Down
18 changes: 14 additions & 4 deletions wflow/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,15 @@
import sys
import pkg_resources

# import pyproj and gdal, to be able to set paths to shared resources
# in case we are using a frozen bundle created with pyinstaller
import pyproj
import pyproj.datadir
import osgeo.gdal as gdal

gdal.UseExceptions()

if getattr(sys, "frozen", False):
import osgeo.gdal as gdal
# running in a bundle
# sys._MEIPASS is set by PyInstaller
basedir = getattr(sys, "_MEIPASS", None)
Expand All @@ -23,13 +29,17 @@
# use the included gdal-data
gdal_data_path = os.path.join(basedir, "gdal-data")
gdal.SetConfigOption("GDAL_DATA", gdal_data_path)
os.environ["GDAL_DATA"] = gdal_data_path

# set environment variable instead of pyproj_datadir such
# set environment variable next to pyproj_datadir such
# that child processes will inherit it
os.environ["PROJ_DIR"] = os.path.join(basedir, "proj-data")
proj_data_dir = os.path.join(basedir, "proj-data")
pyproj.datadir.set_data_dir(proj_data_dir)
os.environ["PROJ_LIB"] = proj_data_dir

try:
from wflow.version import version

__version__ = version
except:
pass
pass
5 changes: 4 additions & 1 deletion wflow_all.spec
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,18 @@ from distutils.dir_util import copy_tree, remove_tree

from osgeo import gdal
import pyproj
pyproj_datadir = pyproj.datadir.pyproj_datadir
import pcraster

gdal.UseExceptions()
pcrasterlib = pathlib.Path(pcraster.__file__).parents[2] / "lib"
datas = [(gdal.GetConfigOption("GDAL_DATA"), "gdal-data")]
pyproj_datadir = pyproj.datadir.get_data_dir()
# prevent unintentionally adding the entire workdir
if pyproj_datadir != "":
datas.append((pyproj_datadir, "proj-data"))

print("data included in pyinstaller distribution:")
print(datas)

# list identical make_wflow_exe script with --normal
# except for the wtools scripts
Expand Down

0 comments on commit 67370be

Please sign in to comment.