|
12 | 12 | # which require glob patterns not supported in pyproject.toml. |
13 | 13 |
|
14 | 14 | import glob |
| 15 | +import io |
| 16 | +import os |
| 17 | +import re |
| 18 | +import sys |
| 19 | +import sysconfig |
| 20 | + |
15 | 21 | from setuptools import setup |
16 | 22 |
|
17 | 23 | data_files = [ |
|
32 | 38 |
|
33 | 39 | scripts = glob.glob('bin/*') |
34 | 40 |
|
| 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 | + |
35 | 111 | setup( |
36 | 112 | data_files=data_files, |
37 | 113 | scripts=scripts, |
|
0 commit comments