-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathsetup.py
208 lines (195 loc) · 8.26 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
# set PYTHONPATH to use the current directory first
import sys
import os
import re
import site
from io import open
sys.path.insert(0,'.')
# get release version
from pandaclient import PandaToolsPkgInfo
release_version = PandaToolsPkgInfo.release_version
from setuptools import setup
from setuptools.command.install import install as install_org
# import distutils after setuptools to tweak sys.modules so that the distutils module in setuptools is used
import distutils
from distutils.command.install_data import install_data as install_data_org
# custom install to disable egg
class install_panda (install_org):
def finalize_options (self):
install_org.finalize_options(self)
self.single_version_externally_managed = True
# generates files using templates and install them
class install_data_panda (install_data_org):
def initialize_options (self):
install_data_org.initialize_options (self)
self.prefix = None
self.root = None
self.install_purelib = None
self.install_scripts = None
def finalize_options (self):
# set install_purelib
self.set_undefined_options('install',
('prefix','prefix'))
self.set_undefined_options('install',
('root','root'))
self.set_undefined_options('install',
('install_purelib','install_purelib'))
self.set_undefined_options('install',
('install_scripts','install_scripts'))
def run (self):
rpmInstall = False
# set install_dir
if not self.install_dir:
if self.root:
# rpm or wheel
self.install_dir = self.prefix
self.install_purelib = distutils.sysconfig.get_python_lib()
self.install_scripts = os.path.join(self.prefix, 'bin')
rpmInstall = True
else:
# sdist
if not self.prefix:
if '--user' in self.distribution.script_args:
self.install_dir = site.USER_BASE
else:
self.install_dir = site.PREFIXES[0]
else:
self.install_dir = self.prefix
#raise Exception, (self.install_dir, self.prefix, self.install_purelib)
self.install_dir = os.path.expanduser(self.install_dir)
self.install_dir = os.path.abspath(self.install_dir)
# remove /usr for bdist/bdist_rpm
match = re.search('(build/[^/]+/dumb)/usr',self.install_dir)
if match is not None:
self.install_dir = re.sub(match.group(0),match.group(1),self.install_dir)
# remove /var/tmp/*-buildroot for bdist_rpm
match = re.search('(/var/tmp/.*-buildroot)/usr',self.install_dir)
if match is not None:
self.install_dir = re.sub(match.group(0),match.group(1),self.install_dir)
# create tmp area
tmpDir = 'build/tmp'
self.mkpath(tmpDir)
new_data_files = []
autoGenFiles = []
for destDir,dataFiles in self.data_files:
newFilesList = []
for srcFile in dataFiles:
# dest filename
destFile = re.sub('\.template$','',srcFile)
# append
newFilesList.append(destFile)
if destFile == srcFile:
continue
autoGenFiles.append(destFile)
# open src
inFile = open(srcFile)
# read
filedata=inFile.read()
# close
inFile.close()
# replace patterns
for item in re.findall('@@([^@]+)@@',filedata):
if not hasattr(self,item):
raise RuntimeError('unknown pattern %s in %s' % (item,srcFile))
# get pattern
patt = getattr(self,item)
# convert to absolute path
if item.startswith('install'):
patt = os.path.abspath(patt)
# remove build/*/dump for bdist
patt = re.sub('build/[^/]+/dumb','',patt)
# remove /var/tmp/*-buildroot for bdist_rpm
patt = re.sub('/var/tmp/.*-buildroot','',patt)
# replace
filedata = filedata.replace('@@%s@@' % item, patt)
# write to dest
oFile = open(destFile,'w')
oFile.write(filedata)
oFile.close()
# replace dataFiles to install generated file
new_data_files.append((destDir,newFilesList))
# install
self.data_files = new_data_files
install_data_org.run(self)
# post install only for client installation
if not os.path.exists(os.path.join(self.install_purelib, 'pandacommon')):
target = os.path.join(self.install_purelib, 'pandatools')
if not os.path.exists(target):
os.symlink('pandaclient', target)
# delete
for autoGenFile in autoGenFiles:
try:
os.remove(autoGenFile)
except Exception:
pass
with open('README.md', 'r', encoding='utf-8') as description_file:
long_description = description_file.read()
setup(
name="panda-client",
version=release_version,
description='PanDA Client Package',
long_description=long_description,
long_description_content_type='text/markdown',
license='GPL',
author='PanDA Team',
author_email='[email protected]',
url='https://panda-wms.readthedocs.io/en/latest/',
python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
],
# optional pip dependencies
extras_require={
'jupyter': ['pandas', 'jupyter-dash'],
},
packages = [ 'pandaclient',
],
scripts = [ 'scripts/prun',
'scripts/pcontainer',
'scripts/pbook',
'scripts/pathena',
'scripts/phpo',
'scripts/pchain',
],
data_files = [ ('etc/panda', ['templates/panda_setup.sh.template',
'templates/panda_setup.csh.template',
'templates/panda_setup.example.cfg.template',
'templates/site_path.sh.template',
'glade/pbook.glade',
]
),
('etc/panda/icons', ['icons/retry.png',
'icons/update.png',
'icons/kill.png',
'icons/pandamon.png',
'icons/savannah.png',
'icons/config.png',
'icons/back.png',
'icons/sync.png',
'icons/forward.png',
'icons/red.png',
'icons/green.png',
'icons/yellow.png',
'icons/orange.png',
]
),
('etc/panda/share', ['share/FakeAppMgr.py',
'share/ConfigExtractor.py',
'share/functions.sh'
]
),
],
cmdclass={
'install': install_panda,
'install_data': install_data_panda
}
)