generate_requirements.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. """
  2. Dynamic requirements generator for Hue multi-python build system.
  3. Generates architecture- and Python-version-specific requirement files
  4. at build time. This tool replaces static requirements.txt and supports:
  5. - Local editable paths for Hue extensions.
  6. - Binary wheels for specific platforms (e.g., ppc64le).
  7. - Architecture-aware dependency lists.
  8. """
  9. import os
  10. import sys
  11. import shutil
  12. import platform
  13. this_dir = os.path.dirname(os.path.abspath(__file__))
  14. class RequirementsGenerator:
  15. def __init__(self):
  16. self.local_requirements = [
  17. "boto-2.49.0",
  18. "django-axes-5.13.0",
  19. "django-babel",
  20. "pysaml2-7.3.1",
  21. "python-sasl-0.3.1",
  22. ]
  23. self.requirements = [
  24. "setuptools==70.0.0",
  25. "apache-ranger==0.0.3",
  26. "requests-gssapi==1.2.3",
  27. "asn1crypto==0.24.0",
  28. "avro-python3==1.8.2",
  29. "Babel==2.9.1",
  30. "celery[redis]==5.4.0",
  31. "cffi==1.15.0",
  32. "channels==4.0.0",
  33. "channels-redis==4.0.0",
  34. "configobj==5.0.9",
  35. "cx-Oracle==8.3.0",
  36. "django-auth-ldap==4.3.0",
  37. "Django==4.1.13",
  38. "daphne==3.0.2",
  39. "django-redis==5.4.0",
  40. "django-celery-beat==2.6.0",
  41. "django-celery-results==2.5.1",
  42. "django-cors-headers==3.13.0",
  43. "django-crequest==2018.5.11",
  44. "django-extensions==3.2.1",
  45. "django-ipware==3.0.2",
  46. "django_opentracing==1.1.0",
  47. "django_prometheus==2.3.1",
  48. "django-webpack-loader==1.0.0",
  49. "djangomako==1.3.2",
  50. "djangorestframework-simplejwt==5.2.1",
  51. "djangorestframework==3.14.0",
  52. "djangosaml2==1.9.3",
  53. "future==0.18.3",
  54. "gcs-oauth2-boto-plugin==3.0",
  55. "greenlet==3.1.1",
  56. "gunicorn==23.0.0",
  57. "ipython==8.12.2", # Python >= 3.8
  58. "jaeger-client==4.3.0",
  59. "jdcal==1.0.1",
  60. "kazoo==2.8.0",
  61. "kerberos==1.3.0",
  62. "kubernetes==26.1.0",
  63. "Mako==1.2.3",
  64. "openpyxl==3.0.9",
  65. "phoenixdb==1.2.1",
  66. "prompt-toolkit==3.0.39",
  67. "protobuf==3.20.3",
  68. "pyarrow==17.0.0",
  69. "pyformance==0.3.2",
  70. "python-dateutil==2.8.2",
  71. "python-daemon==2.2.4",
  72. "python-ldap==3.4.3",
  73. "python-oauth2==1.1.0",
  74. "python-pam==2.0.2",
  75. "pytidylib==0.3.2",
  76. "pytz==2021.3",
  77. "PyJWT==2.4.0",
  78. "PyYAML==6.0.1",
  79. "requests==2.32.3",
  80. "requests-kerberos==0.14.0",
  81. "krb5==0.5.1", # pinned for Sles12, dep of requests-kerberos 0.14.0
  82. "rsa==4.7.2",
  83. "ruff==0.4.2",
  84. "slack-sdk==3.31.0",
  85. "SQLAlchemy==1.3.8",
  86. "sqlparse==0.5.0",
  87. "tablib==0.13.0",
  88. "tabulate==0.8.9",
  89. "trino==0.329.0",
  90. "git+https://github.com/gethue/thrift.git",
  91. "thrift-sasl==0.4.3",
  92. "django-utils-six==2.0",
  93. "six==1.16.0",
  94. "psutil==5.8.0",
  95. "drf-spectacular[sidecar]==0.27.2",
  96. ]
  97. self.ppc64le_requirements = {
  98. "default": [],
  99. "3.8": [
  100. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/cryptography-41.0.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  101. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/numpy-1.23.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  102. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/pandas-1.4.3-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  103. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/lxml-4.6.4-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  104. "PyYAML==5.4.1",
  105. "Markdown==3.1",
  106. ],
  107. "3.9": [
  108. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/cryptography-41.0.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  109. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/numpy-1.23.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  110. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/pandas-1.4.3-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  111. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/lxml-4.6.4-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  112. "PyYAML==6.0.1",
  113. "Markdown==3.8",
  114. ]
  115. }
  116. self.x86_64_requirements = {
  117. "default": [
  118. "cryptography==42.0.8",
  119. "numpy==1.24.4",
  120. "pandas==2.0.3",
  121. "lxml==4.9.1",
  122. "sasl==0.3.1",
  123. "Markdown==3.1",
  124. ],
  125. "3.9": [
  126. "pyopenssl==22.1.0",
  127. "numpy==1.24.4",
  128. "pandas==2.0.3",
  129. "lxml==4.9.1",
  130. "sasl==0.3.1",
  131. "Markdown==3.8",
  132. "decorator==5.1.1",
  133. ],
  134. "3.11": [
  135. "cryptography==42.0.8",
  136. "numpy==1.24.4",
  137. "pandas==2.0.3",
  138. "lxml==4.9.1",
  139. "async-timeout==5.0.1",
  140. "pure-sasl==0.6.2",
  141. "Markdown==3.8",
  142. ],
  143. }
  144. self.aarch64_requirements = {
  145. "default": [
  146. "cryptography==42.0.8",
  147. "numpy==1.24.4",
  148. "pandas==2.0.3",
  149. "lxml==4.9.1",
  150. "Markdown==3.1",
  151. ],
  152. "3.9": [
  153. "pyopenssl==22.1.0",
  154. "numpy==1.24.4",
  155. "pandas==2.0.3",
  156. "lxml==4.9.1",
  157. "sasl==0.3.1",
  158. "Markdown==3.8",
  159. "decorator==5.1.1",
  160. ],
  161. "3.11": [
  162. "cryptography==42.0.8",
  163. "numpy==1.24.4",
  164. "pandas==2.0.3",
  165. "lxml==4.9.1",
  166. "async-timeout==5.0.1",
  167. "pure-sasl==0.6.2",
  168. "Markdown==3.8"
  169. ],
  170. }
  171. self.arch_requirements_map = {
  172. "ppc64le": self.ppc64le_requirements,
  173. "x86_64": self.x86_64_requirements,
  174. "aarch64": self.aarch64_requirements,
  175. }
  176. self.arch = platform.machine()
  177. self.python_version_string = f"{sys.version_info.major}.{sys.version_info.minor}"
  178. def copy_local_requirements(self, python_version_string):
  179. local_dir = f"{this_dir}/{python_version_string}"
  180. if os.path.exists(local_dir):
  181. shutil.rmtree(local_dir, ignore_errors=True)
  182. shutil.copytree(f"{this_dir}/ext-py3", local_dir)
  183. return list(map(lambda x: f"file://{local_dir}/{x}", self.local_requirements))
  184. def generate_requirements(self):
  185. if self.arch not in self.arch_requirements_map:
  186. raise ValueError(f"Unsupported architecture: {self.arch}")
  187. arch_reqs = self.arch_requirements_map[self.arch]
  188. self.requirements.extend(arch_reqs.get(self.python_version_string, arch_reqs["default"]))
  189. self.requirements.extend(self.copy_local_requirements(self.python_version_string))
  190. with open(f"{this_dir}/requirements-{self.arch}-{self.python_version_string}.txt", "w") as f:
  191. f.write("\n".join(self.requirements))
  192. def get_file_name(self):
  193. return f"{this_dir}/requirements-{self.arch}-{self.python_version_string}.txt"
  194. if __name__ == "__main__":
  195. generator = RequirementsGenerator()
  196. try:
  197. generator.generate_requirements()
  198. print(generator.get_file_name())
  199. except Exception as e:
  200. print(f"Error: {e}")
  201. sys.exit(1)