Skip to content

Commit 93e23d5

Browse files
authored
Merge pull request #522 from HSF/dev
fix to set customized setup
2 parents dd9c125 + 82ddc0f commit 93e23d5

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

main/setup.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
# which require glob patterns not supported in pyproject.toml.
1313

1414
import glob
15+
import io
16+
import os
17+
import re
18+
import sys
19+
import sysconfig
20+
1521
from setuptools import setup
1622

1723
data_files = [
@@ -32,6 +38,76 @@
3238

3339
scripts = glob.glob('bin/*')
3440

41+
42+
def get_python_lib():
43+
return sysconfig.get_paths()["purelib"]
44+
45+
46+
def get_python_bin_path():
47+
return sysconfig.get_paths()["scripts"]
48+
49+
50+
def get_python_home():
51+
return sys.exec_prefix
52+
53+
54+
def get_data_path():
55+
return sysconfig.get_paths()["data"]
56+
57+
58+
def replace_python_path(conf_files, python_lib_path, install_bin_path, install_home_path):
59+
"""Rewrite Apache config templates with resolved Python paths.
60+
61+
This mirrors the behavior from the legacy setup.py so that the
62+
httpd-idds-*.conf templates get concrete paths baked in at build time.
63+
"""
64+
for conf_file in conf_files:
65+
if not os.path.exists(conf_file):
66+
continue
67+
new_file = conf_file.replace('.template', '.install_template')
68+
with io.open(conf_file, 'r', encoding='utf8') as f:
69+
template = f.read()
70+
template = template.format(
71+
python_site_packages_path=python_lib_path,
72+
GLOBAL='GLOBAL',
73+
REQUEST_METHOD='REQUEST_METHOD',
74+
python_site_home_path=install_home_path,
75+
python_site_bin_path=install_bin_path,
76+
)
77+
with io.open(new_file, 'w', encoding='utf8') as f:
78+
f.write(template)
79+
80+
81+
def replace_data_path(wsgi_file, install_data_path):
82+
"""Rewrite WSGI template to point at the installed idds.cfg.
83+
84+
This mirrors the behavior from the legacy setup.py so that
85+
bin/idds.wsgi is generated from bin/idds.wsgi.template.
86+
"""
87+
if not os.path.exists(wsgi_file):
88+
return
89+
new_file = wsgi_file.replace('.template', '')
90+
with io.open(wsgi_file, 'r', encoding='utf8') as f:
91+
template = f.read()
92+
template = template.format(
93+
idds_config_path=os.path.join(install_data_path, 'etc/idds/idds.cfg')
94+
)
95+
with io.open(new_file, 'w', encoding='utf8') as f:
96+
f.write(template)
97+
98+
99+
# Perform template rewrites at build/install time, matching legacy behavior
100+
install_lib_path = get_python_lib()
101+
install_bin_path = get_python_bin_path()
102+
install_home_path = get_python_home()
103+
install_data_path = get_data_path()
104+
105+
rest_conf_files = ['etc/idds/rest/httpd-idds-443-py39-cc7.conf.template']
106+
replace_python_path(rest_conf_files, install_lib_path, install_bin_path, install_home_path)
107+
wsgi_file = 'bin/idds.wsgi.template'
108+
replace_data_path(wsgi_file, install_data_path)
109+
110+
35111
setup(
36112
data_files=data_files,
37113
scripts=scripts,

0 commit comments

Comments
 (0)