-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup.py
162 lines (131 loc) · 4.94 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import os
import platform
import sys
import io
import shutil
import glob
import subprocess
from pathlib import Path
from setuptools.command.install import install
from shutil import rmtree, copy
from setuptools import setup, find_packages, Command
from setuptools.command import develop
here = os.path.abspath(os.path.dirname(__file__))
NAME = 'cuvis_il'
VERSION = '3.3.0'
NUMPY_VERSION = '1.22.0'
DESCRIPTION = 'Compiled Python Bindings for the CUVIS SDK.'
if (numpy_complied := os.environ.get('CUVIS_NUMPY_COMPILED')) is not None:
NUMPY_VERSION = numpy_complied
REQUIREMENTS = {
'install': [
str(f'numpy>={NUMPY_VERSION},<2.0.0'),
],
}
def get_python_version(sep='.') -> str:
return f'{sys.version_info.major}{sep}{sys.version_info.minor}'
def get_pyil_files():
with open(Path(here) / f'binary_dir_{platform.python_version()}.stamp') as f:
path = Path(f.read().strip('\n'))
def get_platform_specifc():
if platform.system() == 'Windows':
return ['_cuvis_pyil.pyd', 'cuvis_il.py']
elif platform.system() == "Linux":
return ['_cuvis_pyil.so', 'cuvis_il.py']
else:
raise ValueError("Unsupported OS")
for file in get_platform_specifc():
full_path = path / file
copy(full_path, Path(here) / 'cuvis_il')
lib_dir = ""
if 'CUVIS' in os.environ:
lib_dir = os.getenv('CUVIS')
print('CUVIS SDK found at {}!'.format(lib_dir))
else:
Exception(
'CUVIS SDK does not seem to exist on this machine! Make sure that the environment variable CUVIS is set.')
# taken from https://github.com/navdeep-G/setup.py/blob/master/setup.py
class UploadCommand(Command):
"""Support setup.py upload."""
description = 'Build and publish the package.'
user_options = [
('username=', None, 'pip Username'),
('password=', None, 'pip Password'),
]
@staticmethod
def status(s):
"""Prints things in bold."""
print('\033[1m{0}\033[0m'.format(s))
def initialize_options(self):
# DEPRECATED - Use PYPI API for authentication instead
self.username = '__token__'
self.password = ''
pass
def finalize_options(self):
pass
def run(self):
try:
self.status('Removing previous builds…')
rmtree(os.path.join(here, 'dist'))
rmtree(os.path.join(here, 'repaired_dist'))
except OSError:
pass
self.status('Copying latest pyil files')
get_pyil_files()
# Operating system dependent
self.status('Building Source and Wheel (universal) distribution…')
if platform.system() == 'Windows':
os.system(
f'python setup.py bdist_wheel --python-tag=py{get_python_version("")} --plat-name=win_amd64')
self.status('Uploading the package to PyPI via Twine…')
os.system(
f'twine upload -p {self.password} -u {self.username} -r testpypi dist/*')
elif platform.system() == "Linux":
os.system(
f'python3 setup.py bdist_wheel --python-tag=py{get_python_version("")} --plat-name=linux_x86_64')
# Fix the package to work with manylinux
whl_file = glob.glob('./dist/*.whl')[0]
self.status('Repairing build...')
try:
os.mkdir('repaired_dist')
except:
pass
ubuntu_version = subprocess.check_output(
['lsb_release', '-rs']).decode('ascii').strip('\n')
# see https://github.com/mayeut/pep600_compliance?tab=readme-ov-file#distro-compatibility
version_lookup = {
'20.04': 'manylinux_2_31',
'22.04': 'manylinux_2_35'
}
# This creates a build compatible with Ubuntu 20.04
os.system(
f'auditwheel repair dist/* -w repaired_dist --plat {version_lookup[ubuntu_version]}_x86_64')
self.status('Uploading the package to PyPI via Twine…')
# Make sure .pypirc file is configured
os.system(
f'twine upload -p {self.password} -u {self.username} -r testpypi repaired_dist/*')
sys.exit()
try:
with io.open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
long_description = '\n' + f.read()
except FileNotFoundError:
long_description = DESCRIPTION
setup(
name=NAME,
python_requires=f'>=3.9',
version=VERSION,
packages=find_packages(),
url='https://www.cubert-hyperspectral.com/',
license='Apache License 2.0',
author='Cubert GmbH, Ulm, Germany',
author_email='[email protected]',
description=DESCRIPTION,
long_description=long_description,
long_description_content_type='text/markdown',
# setup_requires=REQUIREMENTS['setup'],
install_requires=REQUIREMENTS['install'],
include_package_data=True,
cmdclass={
'upload': UploadCommand
},
)