-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
224 lines (187 loc) · 9.04 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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
# **************************************************************************************************************
#
# Copyright 2020-2024 Robert Bosch GmbH
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# **************************************************************************************************************
#
# setup.py
#
# XC-HWP/ESW3-Queckenstedt
#
# Extends the standard setuptools installation by adding the documentation in PDF format
# (requires installation mode) and tidying up some folders.
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# This script deletes folders (as defined in config.CRepositoryConfig, depending on the position of this script):
# - previous builds within this repository
# - previous installations within
# * <Python installation>\Lib\site-packages (Windows)
# * <Python installation>/../lib/python3.9/site-packages (Linux)
#
# before the build and the installation start again!
#
# !!! USE WITH CAUTION !!!
#
# !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
#
# --------------------------------------------------------------------------------------------------------------
#
# * Hints:
#
# The usual
# packages = setuptools.find_packages(),
# is replaced by
# packages = [str(oRepositoryConfig.Get('PACKAGENAME')), ],
# to avoid that also config.CRepositoryConfig() and additions.CExtendedSetup() are part of the distribution.
# CRepositoryConfig and CExtendedSetup() are only repository internal helper.
#
# * Known issues:
#
# - setuptools do not properly update an existing package installation under <Python installation>\Lib\site-packages\<package name>!
# > Files modified manually within installation folder, are still modified after repeated execution of setuptools.
# > Files added manually within installation folder, are still present there after repeated execution of setuptools.
# > Only files deleted manually within installation folder, are are restored there after repeated execution of setuptools.
# - No such issues with <Python installation>\Lib\site-packages\<package name>-<versions>.egg-info.
# - Solution: explicit deletion of all previous output (all documentation-, build- and installation-folder, except the egg-info folder)
# (see 'delete_previous_build()' and 'delete_previous_installation()')
#
# --------------------------------------------------------------------------------------------------------------
#
# 30.06.2022
#
# --------------------------------------------------------------------------------------------------------------
import os, sys, platform, shlex, subprocess
import setuptools
from setuptools.command.install import install
# prefer the repository local version of all additional libraries (instead of the installed version under site-packages)
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "./additions")))
from config.CRepositoryConfig import CRepositoryConfig # providing repository and environment specific information
from additions.CExtendedSetup import CExtendedSetup # providing functions to support the extended setup process
import colorama as col
col.init(autoreset=True)
COLBR = col.Style.BRIGHT + col.Fore.RED
COLBY = col.Style.BRIGHT + col.Fore.YELLOW
COLBG = col.Style.BRIGHT + col.Fore.GREEN
SUCCESS = 0
ERROR = 1
# --------------------------------------------------------------------------------------------------------------
def printerror(sMsg):
sys.stderr.write(COLBR + f"Error: {sMsg}!\n")
def printexception(sMsg):
sys.stderr.write(COLBR + f"Exception: {sMsg}!\n")
# --------------------------------------------------------------------------------------------------------------
#TODO: check if still necessary
class ExtendedInstallCommand(install):
"""Extended setup for installation mode."""
def run(self):
listCmdArgs = sys.argv
if ( ('install' in listCmdArgs) or ('build' in listCmdArgs) or ('sdist' in listCmdArgs) or ('bdist_wheel' in listCmdArgs) ):
install.run(self)
return SUCCESS
# eof class ExtendedInstallCommand(install):
# --------------------------------------------------------------------------------------------------------------
# -- Even in case of other command line parameters than 'install' or 'build' are used we need the following objects.
# (Without repository configuration commands like '--author-email' would not be possible)
# -- setting up the repository configuration
oRepositoryConfig = None
try:
oRepositoryConfig = CRepositoryConfig(os.path.abspath(sys.argv[0]))
except Exception as ex:
print()
printexception(str(ex))
print()
sys.exit(ERROR)
# -- setting up the extended setup
oExtendedSetup = None
try:
oExtendedSetup = CExtendedSetup(oRepositoryConfig)
except Exception as ex:
print()
printexception(str(ex))
print()
sys.exit(ERROR)
# --------------------------------------------------------------------------------------------------------------
long_description = "long description" # variable is required even in case of other command line parameters than 'install' or 'build' are used
listCmdArgs = sys.argv
if ( ('install' in listCmdArgs) or ('build' in listCmdArgs) or ('sdist' in listCmdArgs) or ('bdist_wheel' in listCmdArgs) ):
print()
print(COLBY + "Entering extended installation")
print()
print(COLBY + "Extended setup step 1/5: Calling the documentation builder")
print()
nReturn = oExtendedSetup.genmaindoc()
if nReturn != SUCCESS:
sys.exit(nReturn)
print(COLBY + "Extended setup step 2/5: Converting the repository README")
print()
nReturn = oExtendedSetup.convert_repo_readme()
if nReturn != SUCCESS:
sys.exit(nReturn)
print(COLBY + "Extended setup step 3/5: Deleting previous setup outputs (build, dist, <package name>.egg-info within repository)")
print()
nReturn = oExtendedSetup.delete_previous_build()
if nReturn != SUCCESS:
sys.exit(nReturn)
if ( ('bdist_wheel' in listCmdArgs) or ('build' in listCmdArgs) ):
print()
print(COLBY + "Skipping extended setup step 4/5: Deleting previous package installation folder within site-packages")
print()
else:
print()
print(COLBY + "Extended setup step 4/5: Deleting previous package installation folder within site-packages") # (<package name> and <package name>_doc under <Python installation>\Lib\site-packages
print()
nReturn = oExtendedSetup.delete_previous_installation()
if nReturn != SUCCESS:
sys.exit(nReturn)
README_MD = str(oRepositoryConfig.Get('README_MD'))
with open(README_MD, "r", encoding="utf-8") as fh:
long_description = fh.read()
fh.close()
# --------------------------------------------------------------------------------------------------------------
# -- the 'setup' itself
print(COLBY + "Extended setup step 5/5: install.run(self)")
print()
setuptools.setup(
name = str(oRepositoryConfig.Get('REPOSITORYNAME')),
version = str(oRepositoryConfig.Get('PACKAGEVERSION')),
author = str(oRepositoryConfig.Get('AUTHOR')),
author_email = str(oRepositoryConfig.Get('AUTHOREMAIL')),
description = str(oRepositoryConfig.Get('DESCRIPTION')),
long_description = long_description,
long_description_content_type = str(oRepositoryConfig.Get('LONGDESCRIPTIONCONTENTTYPE')),
url = str(oRepositoryConfig.Get('URL')),
packages = [str(oRepositoryConfig.Get('PACKAGENAME'))],
package_dir = {str(oRepositoryConfig.Get('REPOSITORYNAME')) : str(oRepositoryConfig.Get('PACKAGENAME'))},
classifiers = [
str(oRepositoryConfig.Get('PROGRAMMINGLANGUAGE')),
str(oRepositoryConfig.Get('LICENCE')),
str(oRepositoryConfig.Get('OPERATINGSYSTEM')),
str(oRepositoryConfig.Get('DEVELOPMENTSTATUS')),
str(oRepositoryConfig.Get('INTENDEDAUDIENCE')),
str(oRepositoryConfig.Get('TOPIC')),
],
python_requires = str(oRepositoryConfig.Get('PYTHONREQUIRES')),
cmdclass={
'install': ExtendedInstallCommand,
},
install_requires = oRepositoryConfig.Get('INSTALLREQUIRES'),
package_data={f"{oRepositoryConfig.Get('PACKAGENAME')}" : oRepositoryConfig.Get('PACKAGEDATA')},
)
# --------------------------------------------------------------------------------------------------------------
print()
print(COLBG + "Extended installation done")
print()
# --------------------------------------------------------------------------------------------------------------