forked from openstreams/wflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wflow_all.spec
131 lines (109 loc) · 3.6 KB
/
wflow_all.spec
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# -*- mode: python -*-
import os
import shutil
import subprocess
import sys
from distutils.dir_util import copy_tree, remove_tree
from pathlib import Path
import pyproj
import xarray
from osgeo import gdal
# got a RecursionError: maximum recursion depth exceeded
sys.setrecursionlimit(10_000)
gdal.UseExceptions()
datas = [
(gdal.GetConfigOption("GDAL_DATA"), "gdal-data"),
(Path(xarray.__path__[0]) / "static", "xarray/static"),
]
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
scriptpaths = [
"openda_bmi/opendapy.py",
"Scripts/bmi2runner.py",
"Scripts/pcr2netcdf.py",
"Scripts/wflow_flood.py",
"Scripts/wflow_prepare_step1.py",
"Scripts/wflow_prepare_step2.py",
"wflow/wflow_adapt.py",
"wflow/wflow_delwaq.py",
"wflow/wflow_emwaq.py",
"wflow/wflow_sediment.py",
"wflow/wflow_floodmap.py",
"wflow/wflow_gr4.py",
"wflow/wflow_hbv.py",
"wflow/wflow_lintul.py",
"wflow/wflow_pcrglobwb.py",
"wflow/wflow_routing.py",
"wflow/wflow_sbm.py",
"wflow/wflow_sphy.py",
"wflow/wflow_topoflex.py",
"wflow/wflow_w3ra.py",
"wflow/wflow_w3.py",
"wflow/wflow_stream.py",
"wflow/wflow_wave.py",
]
def scriptname(scriptpath):
"""Get 'wflow_hbv' from 'wflow/wflow_hbv.py'"""
return os.path.splitext(os.path.basename(scriptpath))[0]
def do_analysis(scriptpath):
"""Run PyInstaller Analysis"""
# note that the datas locations have to be set again in __init__.py
# if they are to work in a bundled folder
return Analysis(
[scriptpath],
# TODO check if still necessary in PyInstaller 3.3 after
# https://github.com/pyinstaller/pyinstaller/pull/2401
# Though this seems more solid, submit as hook patch?
datas=datas,
hiddenimports=[ # in opendapy.py: importlib.import_module(sys.argv[3])
# for wflow this would always be wflow.wflow_bmi
"wflow.wflow_bmi",
"wflow.wflow_bmi_combined",
"pkg_resources.py2_warn",
],
)
def do_pyz(a):
return PYZ(a.pure, a.zipped_data)
def do_exe(apyz):
# unpack tuple created by zip
a, pyz = apyz
return EXE(
pyz,
a.scripts,
exclude_binaries=True,
name=scriptname(a.inputs[0]),
upx=False,
icon="logo.ico",
)
def do_collect(aexe):
# unpack tuple created by zip
a, exe = aexe
return COLLECT(
exe, a.binaries, a.zipfiles, a.datas, name=scriptname(a.inputs[0]), upx=False
)
analist = list(map(do_analysis, scriptpaths))
pyzlist = list(map(do_pyz, analist))
exelist = list(map(do_exe, zip(analist, pyzlist)))
collist = list(map(do_collect, zip(analist, exelist)))
filename = "version.txt"
versionfile = open(os.path.join("dist", filename), "w")
version = subprocess.check_output(["git", "describe", "--tags"]).strip().decode()
versionfile.write(version)
versionfile.close()
# merge all individual folders in the parent 'dist' folder
# Replace with MERGE when this issue is fixed
# https://github.com/pyinstaller/pyinstaller/issues/1527
for scriptpath in scriptpaths:
srcdir = os.path.join("dist", scriptname(scriptpath))
# only copy if new or newer
copy_tree(srcdir, "dist", update=1)
remove_tree(srcdir)
# getting an error if this folder does not exist
libbin_dir = Path("dist") / "Library" / "bin"
libbin_dir.mkdir(exist_ok=True, parents=True)