generate_requirements.py 7.5 KB

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