forked from ec-jrc/pyg2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
136 lines (112 loc) · 5.27 KB
/
setup.py
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
132
133
134
135
136
import os
import subprocess
import sys
import glob
from shutil import rmtree
from setuptools import setup, find_packages, Command
current_dir = os.path.dirname(os.path.abspath(__file__))
sys.path.append(os.path.join(current_dir, './src/'))
import pyg2p.util.files as fm
from pyg2p import __version__
readme_file = os.path.join(current_dir, 'README.md')
with open(readme_file, 'r') as f:
long_description = f.read()
class UploadCommand(Command):
"""Support setup.py upload."""
description = 'Publish pyg2p package.'
user_options = []
@staticmethod
def print_console(s):
print(f'\033[1m{s}\033[0m')
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
try:
self.print_console('Removing previous builds...')
rmtree(os.path.join(current_dir, 'dist'))
except OSError:
pass
self.print_console('Building Source and Wheel (universal) distribution...')
os.system(f'{sys.executable} setup.py sdist')
self.print_console('Uploading the package to PyPI via Twine...')
os.system('twine upload dist/*')
self.print_console('Pushing git tags...')
os.system(f'git tag {__version__}')
os.system('git push --tags')
sys.exit()
def setup_data_files(setup_args_):
user_conf_dir = f'{os.path.expanduser("~")}/.pyg2p/'
fm.create_dir(user_conf_dir)
list_files = {t: [os.path.join(t, f) for f in os.listdir(t) if f.endswith('.json')]
for t in ('./templates',
'./configuration',
'./configuration/global')}
for_user_to_copy = [f for f in list_files['./configuration'] if
not fm.exists(os.path.join(user_conf_dir, fm.filename(f)))]
templates_to_copy = [f for f in list_files['./templates'] if
not fm.exists(os.path.join(user_conf_dir, 'templates_samples', fm.filename(f)))]
data_files = [('pyg2p/configuration/', list_files['./configuration/global'])]
if for_user_to_copy:
data_files.append((user_conf_dir, for_user_to_copy))
if templates_to_copy:
data_files.append((os.path.join(user_conf_dir, 'templates_samples'), templates_to_copy))
if not fm.exists(os.path.join(user_conf_dir, 'tests/commands.txt')):
data_files.append((os.path.join(user_conf_dir, 'tests'), ['configuration/tests/commands.txt']))
setup_args_.update({'data_files': data_files})
def _get_gdal_version():
try:
p = subprocess.Popen(['gdal-config', '--version'], stdout=subprocess.PIPE)
except FileNotFoundError:
raise SystemError('gdal-config not found.'
'GDAL seems not installed. '
'Please, install GDAL binaries and libraries for your system '
'and then install the relative pip package.')
else:
return p.communicate()[0].splitlines()[0].decode()
gdal_version = _get_gdal_version()
req_file = 'requirements.txt'
requirements = [l for l in open(req_file).readlines() if l and not l.startswith('#')]
requirements += [f'GDAL=={gdal_version}']
setup_args = dict(name='pyg2p',
version=__version__,
description="Convert GRIB files to netCDF or PCRaster",
long_description=long_description,
long_description_content_type='text/markdown',
license="EUPL 1.2",
install_requires=requirements,
author="Domenico Nappo",
author_email="[email protected]",
package_dir={'': 'src/'},
py_modules=[os.path.splitext(os.path.basename(path))[0] for path in glob.glob('src/*.py*')],
include_package_data=True,
package_data={'pyg2p': ['*.json']},
packages=find_packages('src'),
keywords="NetCDF GRIB PCRaster Lisflood EFAS GLOFAS",
scripts=['bin/pyg2p'],
zip_safe=True,
# setup.py publish to pypi.
cmdclass={
'upload': UploadCommand,
'publish': UploadCommand,
},
classifiers=[
# complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers
'Development Status :: 4 - Beta',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Financial and Insurance Industry',
'Intended Audience :: Other Audience',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)',
'Operating System :: Unix',
'Operating System :: POSIX',
'Operating System :: Microsoft :: Windows',
'Operating System :: MacOS :: MacOS X',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Topic :: Scientific/Engineering :: Physics',
])
setup_data_files(setup_args)
setup(**setup_args)