Skip to content

Commit cadc2a7

Browse files
committed
Fix for pyinstaller build bug at github
1 parent 0ad2be4 commit cadc2a7

2 files changed

Lines changed: 116 additions & 71 deletions

File tree

setup.py

Lines changed: 85 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -15,122 +15,149 @@
1515
see <http://www.gnu.org/licenses/>.
1616
"""
1717

18-
__author__ = 'J Sundar (wrf.guy@gmail.com)'
18+
__author__ = "J Sundar (wrf.guy@gmail.com)"
1919

2020
import io
2121
import os
2222
import glob
2323
from setuptools import find_packages, setup
2424

2525
# Package meta-data.
26-
NAME = 'wrfplot'
27-
DESCRIPTION = 'Command line application to plot WRF model output data...'
28-
URL = 'https://github.com/wxguy/wrfplot'
29-
EMAIL = 'wrf.guy@gmail.com'
30-
AUTHOR = 'J Sundar'
31-
REQUIRES_PYTHON = '>=3.7.0'
26+
NAME = "wrfplot"
27+
DESCRIPTION = "Command line application to plot WRF model output data..."
28+
URL = "https://github.com/wxguy/wrfplot"
29+
EMAIL = "wrf.guy@gmail.com"
30+
AUTHOR = "J Sundar"
31+
REQUIRES_PYTHON = ">=3.7.0"
3232
VERSION = None
33-
LICENSE = 'GNU General Public License v3 (GPLv3)'
33+
LICENSE = "GNU General Public License v3 (GPLv3)"
3434

3535
# What packages are required for this module to be executed?
36-
REQUIRED = ['cartopy', 'xarray', 'matplotlib', 'wrf-python>=1.3', 'tqdm', 'netcdf4']
36+
REQUIRED = ["cartopy", "xarray", "matplotlib", "wrf-python>=1.3", "tqdm", "netcdf4"]
3737

3838
here = os.path.abspath(os.path.dirname(__file__))
3939

40-
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
41-
long_description = '\n' + f.read()
40+
with io.open(os.path.join(here, "README.md"), encoding="utf-8") as f:
41+
long_description = "\n" + f.read()
4242

4343
about = {}
4444
if not VERSION:
45-
with open(os.path.join(here, NAME, '_version.py')) as f:
45+
with open(os.path.join(here, NAME, "_version.py")) as f:
4646
exec(f.read(), about)
4747
else:
48-
about['__version__'] = VERSION
48+
about["__version__"] = VERSION
4949

5050

5151
def list_files(directory):
5252
files = []
53-
all_files = glob.glob(directory + '/**/*', recursive=True)
53+
all_files = glob.glob(directory + "/**/*", recursive=True)
5454
for _file in all_files:
55-
if os.path.isfile(_file) and '.py' not in _file:
55+
if os.path.isfile(_file) and ".py" not in _file:
5656
files.append(_file)
5757
return files
5858

5959

6060
def _version():
61-
from setuptools_scm.version import SEMVER_MINOR, guess_next_simple_semver, release_branch_semver_version, simplified_semver_version
61+
from setuptools_scm.version import (
62+
SEMVER_MINOR,
63+
guess_next_simple_semver,
64+
release_branch_semver_version,
65+
simplified_semver_version,
66+
)
6267

6368
def my_release_branch_semver_version(version):
6469
v = release_branch_semver_version(version)
65-
if v == version.format_next_version(guess_next_simple_semver, retain=SEMVER_MINOR):
66-
return version.format_next_version(guess_next_simple_semver, fmt="{guessed}", retain=SEMVER_MINOR)
70+
if v == version.format_next_version(
71+
guess_next_simple_semver, retain=SEMVER_MINOR
72+
):
73+
return version.format_next_version(
74+
guess_next_simple_semver, fmt="{guessed}", retain=SEMVER_MINOR
75+
)
6776
return v
6877

6978
return {
70-
'version_scheme': my_release_branch_semver_version,
71-
'local_scheme': 'no-local-version',
79+
"version_scheme": my_release_branch_semver_version,
80+
"local_scheme": "no-local-version",
7281
}
7382

7483

7584
setup(
7685
name=NAME,
77-
use_scm_version=True, # _version
78-
setup_requires=['setuptools_scm'],
86+
use_scm_version=True, # _version
87+
setup_requires=["setuptools_scm"],
7988
description=DESCRIPTION,
8089
long_description=long_description,
8190
author=AUTHOR,
8291
author_email=EMAIL,
8392
python_requires=REQUIRES_PYTHON,
8493
url=URL,
85-
keywords=["Scientific", "Engineering", "Atmospheric Science", "Weather Model", "Plotting", "Software Development",
86-
"Numerical Weather Prediction", "NWP", "Weather Research and Forecast", "WRF"],
87-
py_modules=['wrfplot'],
88-
94+
keywords=[
95+
"Scientific",
96+
"Engineering",
97+
"Atmospheric Science",
98+
"Weather Model",
99+
"Plotting",
100+
"Software Development",
101+
"Numerical Weather Prediction",
102+
"NWP",
103+
"Weather Research and Forecast",
104+
"WRF",
105+
],
106+
py_modules=["wrfplot"],
89107
entry_points={
90-
'console_scripts': ['wrfplot=wrfplot.wrfplot:main'],
108+
"console_scripts": ["wrfplot=wrfplot.wrfplot:main"],
91109
},
92110
install_requires=REQUIRED,
93111
license=LICENSE,
94112
classifiers=[
95113
# Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers
96-
'License :: OSI Approved :: GNU General Public License v3 (GPLv3)'
97-
'Programming Language :: Python',
98-
'Programming Language :: Python :: 3.7',
99-
'Programming Language :: Python :: 3.8',
100-
'Programming Language :: Python :: 3.9',
101-
'Programming Language :: Python :: 3.10',
102-
'Programming Language :: Python :: 3.11',
103-
'Operating System :: Unix',
104-
'Operating System :: MacOS',
105-
'Operating System :: POSIX :: Linux',
106-
'Operating System :: Microsoft :: Windows',
107-
'Programming Language :: Python :: Implementation :: CPython',
108-
'Topic :: Scientific/Engineering :: Atmospheric Science',
109-
'Topic :: Scientific/Engineering :: Numerical Weather Model',
110-
'Topic :: Scientific/Engineering :: WRF',
111-
'Topic :: Scientific/Engineering :: Visualization',
114+
"License :: OSI Approved :: GNU General Public License v3 (GPLv3)"
115+
"Programming Language :: Python",
116+
"Programming Language :: Python :: 3.7",
117+
"Programming Language :: Python :: 3.8",
118+
"Programming Language :: Python :: 3.9",
119+
"Programming Language :: Python :: 3.10",
120+
"Programming Language :: Python :: 3.11",
121+
"Operating System :: Unix",
122+
"Operating System :: MacOS",
123+
"Operating System :: POSIX :: Linux",
124+
"Operating System :: Microsoft :: Windows",
125+
"Programming Language :: Python :: Implementation :: CPython",
126+
"Topic :: Scientific/Engineering :: Atmospheric Science",
127+
"Topic :: Scientific/Engineering :: Numerical Weather Model",
128+
"Topic :: Scientific/Engineering :: WRF",
129+
"Topic :: Scientific/Engineering :: Visualization",
112130
],
113-
packages=find_packages("wrfplot", exclude=['test', 'test.*'],),
131+
packages=find_packages(
132+
"wrfplot",
133+
exclude=["test", "test.*"],
134+
),
114135
include_package_data=True,
115-
exclude_package_data={'': ['test']},
116-
package_dir={'wrfplot': 'wrfplot'},
117-
package_data={'wrfplot': ['colormaps/colormaps/cartocolors/*',
118-
'colormaps/colormaps/cmocean/*',
119-
'colormaps/colormaps/colorbrewer/*',
120-
'colormaps/colormaps/colorcet/*',
121-
'colormaps/colormaps/cubehelix/*',
122-
'colormaps/colormaps/ncar_ncl/*',
123-
'colormaps/colormaps/scientific/*',
124-
'colormaps/colormaps/sciviz/*',
125-
'colormaps/colormaps/tableau/*',
126-
'data/*', 'data/shapefiles/natural_earth/cultural/*',
127-
'data/shapefiles/natural_earth/physical/*', 'data/shape/*']},
136+
exclude_package_data={"": ["test"]},
137+
package_dir={"wrfplot": "wrfplot"},
138+
package_data={
139+
"wrfplot": [
140+
"colormaps/colormaps/cartocolors/*",
141+
"colormaps/colormaps/cmocean/*",
142+
"colormaps/colormaps/colorbrewer/*",
143+
"colormaps/colormaps/colorcet/*",
144+
"colormaps/colormaps/cubehelix/*",
145+
"colormaps/colormaps/ncar_ncl/*",
146+
"colormaps/colormaps/scientific/*",
147+
"colormaps/colormaps/sciviz/*",
148+
"colormaps/colormaps/tableau/*",
149+
"data/*",
150+
"data/shapefiles/natural_earth/cultural/*",
151+
"data/shapefiles/natural_earth/physical/*",
152+
"data/shape/*",
153+
]
154+
},
128155
# package_data={'wrfplot': list_files('wrfplot')},
129156
# $ setup.py publish support.
130157
# cmdclass={ 'upload': UploadCommand,},
131158
project_urls={
132159
"Bug Reports": "https://github.com/wxguy/wrfplot/issues",
133160
"Source": "https://github.com/wxguy/wrfplot",
134-
"Documentation": "https://wxguy.in/wrfplot"
161+
"Documentation": "https://wxguy.in/wrfplot",
135162
},
136163
)

wrfplot.spec

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# -*- mode: python ; coding: utf-8 -*-
2-
import sys ; sys.setrecursionlimit(sys.getrecursionlimit() * 5)
2+
import sys
3+
4+
sys.setrecursionlimit(sys.getrecursionlimit() * 5)
35

46
import os
57
import importlib
8+
69
block_cipher = None
710

811

912
def include_files(src_dir, dest_dir, startswith=None, endswith=None):
10-
""" Copy files from source to Pyinstaller packed destination """
13+
"""Copy files from source to Pyinstaller packed destination"""
1114
path_list = []
1215
if os.path.isdir(src_dir):
1316
for file in os.listdir(src_dir):
@@ -25,20 +28,35 @@ def include_files(src_dir, dest_dir, startswith=None, endswith=None):
2528

2629

2730
conda_prefix = os.getenv("CONDA_PREFIX")
28-
libos_files = include_files(os.path.join(conda_prefix, "lib"), os.path.join("shapely", ".libs"), startswith='libgeos')
29-
py_files = include_files('wrfplot', '.', endswith='.py')
31+
libos_files = include_files(
32+
os.path.join(conda_prefix, "lib"),
33+
os.path.join("shapely", ".libs"),
34+
startswith="libgeos",
35+
)
36+
py_files = include_files("wrfplot", ".", endswith=".py")
3037
# Convert name list path to list to string
31-
mpl_toolkits_dir = list(importlib.import_module('mpl_toolkits').__path__)[0]
32-
mpl_toolkits_module = include_files(mpl_toolkits_dir, 'mpl_toolkits')
33-
colormaps_module = os.path.dirname(importlib.machinery.PathFinder().find_module("colormaps").get_filename())
34-
38+
mpl_toolkits_dir = list(importlib.import_module("mpl_toolkits").__path__)[0]
39+
mpl_toolkits_module = include_files(mpl_toolkits_dir, "mpl_toolkits")
40+
try:
41+
colormaps_module = os.path.dirname(
42+
importlib.machinery.PathFinder().find_module("colormaps").get_filename()
43+
)
44+
except Exception as err:
45+
colormaps_module = (
46+
importlib.machinery.PathFinder()
47+
.find_spec("colormaps")
48+
.submodule_search_locations[0]
49+
)
3550

3651
a = Analysis(
37-
['wrfplot/wrfplot.py'],
52+
["wrfplot/wrfplot.py"],
3853
pathex=[],
3954
binaries=[],
40-
datas=[('./wrfplot/data', 'data'), (colormaps_module, 'colormaps')] + libos_files + py_files + mpl_toolkits_module,
41-
hiddenimports=['colormaps', 'tqdm'],
55+
datas=[("./wrfplot/data", "data"), (colormaps_module, "colormaps")]
56+
+ libos_files
57+
+ py_files
58+
+ mpl_toolkits_module,
59+
hiddenimports=["colormaps", "tqdm"],
4260
hookspath=[],
4361
hooksconfig={},
4462
runtime_hooks=[],
@@ -56,7 +74,7 @@ exe = EXE(
5674
a.scripts,
5775
[],
5876
exclude_binaries=True,
59-
name='wrfplot',
77+
name="wrfplot",
6078
debug=False,
6179
bootloader_ignore_signals=False,
6280
strip=False,
@@ -77,5 +95,5 @@ coll = COLLECT(
7795
strip=False,
7896
upx=True,
7997
upx_exclude=[],
80-
name='wrfplot',
98+
name="wrfplot",
8199
)

0 commit comments

Comments
 (0)