forked from sentinel-hub/sentinelhub-py
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.py
124 lines (100 loc) · 4.22 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
import io
import os
from setuptools import setup, find_packages
def parse_requirements(file):
required_packages = []
with open(os.path.join(os.path.dirname(__file__), file)) as req_file:
for line in req_file:
if '/' not in line:
required_packages.append(line.strip())
return required_packages
def get_version():
for line in open(os.path.join(os.path.dirname(__file__), 'sentinelhub', '_version.py')):
if line.find("__version__") >= 0:
version = line.split("=")[1].strip()
version = version.strip('"').strip("'")
return version
def get_long_description():
return io.open('README.md', encoding="utf-8").read()
def update_package_config():
""" Every time sentinelhub package is installed entire config.json is overwritten. However this function
will check if sentinelhub is already installed and try to copy those parameters from old config.json that are by
default set to an empty value (i.e. instance_id, aws_access_key_id and aws_secret_access_key) into new config.json
file.
"""
try:
import importlib
import sys
import json
path = importlib.machinery.PathFinder().find_spec('sentinelhub', sys.path[1:]).submodule_search_locations[0]
old_config_filename = os.path.join(path, 'config.json')
with open(old_config_filename, 'r') as file:
old_config = json.load(file)
from sentinelhub.config import SHConfig
config = SHConfig()
for attr, value in old_config.items():
if hasattr(config, attr) and not getattr(config, attr):
setattr(config, attr, value)
config.save()
except BaseException:
pass
def install_additional_requirements(file):
""" Because setuptools do not support installing from GitHub if the same version of the package is available at PyPI
"""
try:
try:
from pip import _internal as pip
except ImportError: # in case pip version is <10.0
import pip
from sys import version_info
if version_info[:2] >= (3, 7):
pip.main(['install', 'cython'])
with open(os.path.join(os.path.dirname(__file__), file)) as req_file:
for line in req_file:
if '/' in line:
pip.main(['install', line])
except BaseException:
pass
update_package_config()
REQUIREMENTS_FILE = "requirements.txt"
setup(
name='sentinelhub',
python_requires='>=3.5',
version=get_version(),
description='Sentinel Hub Utilities',
long_description=get_long_description(),
long_description_content_type="text/markdown",
url='https://github.com/sentinel-hub/sentinelhub-py',
author='Sinergise ltd.',
author_email='[email protected]',
license='MIT',
packages=find_packages(),
package_data={'sentinelhub': ['sentinelhub/config.json']},
include_package_data=True,
install_requires=parse_requirements(REQUIREMENTS_FILE),
extras_require={'DEV': parse_requirements("requirements-dev.txt")},
zip_safe=False,
entry_points={'console_scripts': ['sentinelhub=sentinelhub.commands:main_help',
'sentinelhub.aws=sentinelhub.commands:aws',
'sentinelhub.config=sentinelhub.commands:config',
'sentinelhub.download=sentinelhub.commands:download']},
classifiers=[
'Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Operating System :: MacOS',
'Operating System :: Microsoft :: Windows',
'Operating System :: Unix',
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: Implementation :: PyPy',
'Topic :: Scientific/Engineering',
'Topic :: Software Development'
]
)
install_additional_requirements(REQUIREMENTS_FILE)