generate_requirements.py 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. "apache-ranger==0.0.3",
  41. "asn1crypto==0.24.0",
  42. "avro-python3==1.8.2",
  43. "Babel==2.9.1",
  44. "celery[redis]==5.4.0",
  45. "cffi==1.15.0",
  46. "channels==4.0.0",
  47. "channels-redis==4.0.0",
  48. "configobj==5.0.9",
  49. "cx-Oracle==8.3.0",
  50. "daphne==3.0.2",
  51. "Django==4.1.13",
  52. "django-auth-ldap==4.3.0",
  53. "django-celery-beat==2.6.0",
  54. "django-celery-results==2.5.1",
  55. "django-cors-headers==3.13.0",
  56. "django-crequest==2018.5.11",
  57. "django-extensions==3.2.1",
  58. "django-ipware==3.0.2",
  59. "django_opentracing==1.1.0",
  60. "django_prometheus==2.3.1",
  61. "django-redis==5.4.0",
  62. "django-utils-six==2.0",
  63. "django-webpack-loader==1.0.0",
  64. "djangomako==1.3.2",
  65. "djangorestframework==3.14.0",
  66. "djangorestframework-simplejwt==5.2.1",
  67. "djangosaml2==1.9.3",
  68. "drf-spectacular[sidecar]==0.27.2",
  69. "future==0.18.3",
  70. "gcs-oauth2-boto-plugin==3.0",
  71. "greenlet==3.1.1",
  72. "gunicorn==23.0.0",
  73. "ipython==8.12.2", # Python >= 3.8
  74. "jaeger-client==4.3.0",
  75. "jdcal==1.0.1",
  76. "kazoo==2.8.0",
  77. "kerberos==1.3.0",
  78. "krb5==0.5.1", # pinned for Sles12, dep of requests-kerberos 0.14.0
  79. "kubernetes==26.1.0",
  80. "Mako==1.2.3",
  81. "openpyxl==3.0.9",
  82. "phoenixdb==1.2.1",
  83. "polars[calamine]==1.8.2", # Python >= 3.8
  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-magic==0.4.27",
  94. "python-oauth2==1.1.0",
  95. "python-pam==2.0.2",
  96. "pytidylib==0.3.2",
  97. "pytz==2021.3",
  98. "PyYAML==6.0.1",
  99. "requests==2.32.3",
  100. "requests-gssapi==1.2.3",
  101. "requests-kerberos==0.14.0",
  102. "rsa==4.7.2",
  103. "ruff==0.11.10",
  104. "setuptools==70.0.0",
  105. "six==1.16.0",
  106. "slack-sdk==3.31.0",
  107. "SQLAlchemy==1.3.8",
  108. "sqlparse==0.5.0",
  109. "tablib==0.13.0",
  110. "tabulate==0.8.9",
  111. "thrift-sasl==0.4.3",
  112. "trino==0.329.0",
  113. "git+https://github.com/gethue/thrift.git",
  114. ]
  115. self.ppc64le_requirements = {
  116. "default": [],
  117. "3.8": [
  118. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/cryptography-41.0.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  119. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/lxml-4.6.4-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  120. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/numpy-1.23.1-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  121. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/pandas-1.4.3-cp38-cp38-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  122. "Markdown==3.1",
  123. "PyYAML==5.4.1",
  124. ],
  125. "3.9": [
  126. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/cryptography-41.0.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  127. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/lxml-4.6.4-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  128. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/numpy-1.23.1-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  129. "http://ibm-ppc-builds.s3.amazonaws.com/silx-py-libs/pandas-1.4.3-cp39-cp39-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl",
  130. "Markdown==3.8",
  131. "PyYAML==6.0.1",
  132. ],
  133. }
  134. self.x86_64_requirements = {
  135. "default": [
  136. "cryptography==42.0.8",
  137. "lxml==4.9.1",
  138. "Markdown==3.1",
  139. "numpy==1.24.4",
  140. "pandas==2.0.3",
  141. "sasl==0.3.1",
  142. ],
  143. "3.9": [
  144. "decorator==5.1.1",
  145. "lxml==4.9.1",
  146. "Markdown==3.8",
  147. "numpy==1.24.4",
  148. "pandas==2.0.3",
  149. "pyopenssl==22.1.0",
  150. "sasl==0.3.1",
  151. ],
  152. "3.11": [
  153. "async-timeout==5.0.1",
  154. "cryptography==42.0.8",
  155. "lxml==4.9.1",
  156. "Markdown==3.8",
  157. "numpy==1.24.4",
  158. "pandas==2.0.3",
  159. "pure-sasl==0.6.2",
  160. ],
  161. }
  162. self.aarch64_requirements = {
  163. "default": [
  164. "cryptography==42.0.8",
  165. "lxml==4.9.1",
  166. "Markdown==3.1",
  167. "numpy==1.24.4",
  168. "pandas==2.0.3",
  169. ],
  170. "3.9": [
  171. "decorator==5.1.1",
  172. "lxml==4.9.1",
  173. "Markdown==3.8",
  174. "numpy==1.24.4",
  175. "pandas==2.0.3",
  176. "pyopenssl==22.1.0",
  177. "sasl==0.3.1",
  178. ],
  179. "3.11": [
  180. "async-timeout==5.0.1",
  181. "cryptography==42.0.8",
  182. "lxml==4.9.1",
  183. "Markdown==3.8",
  184. "numpy==1.24.4",
  185. "pandas==2.0.3",
  186. "pure-sasl==0.6.2",
  187. ],
  188. }
  189. self.arch_requirements_map = {
  190. "ppc64le": self.ppc64le_requirements,
  191. "x86_64": self.x86_64_requirements,
  192. "aarch64": self.aarch64_requirements,
  193. "arm64": self.aarch64_requirements, # arm64 is treated as aarch64
  194. }
  195. self.arch = platform.machine()
  196. self.python_version_string = f"{sys.version_info.major}.{sys.version_info.minor}"
  197. def copy_local_requirements(self, python_version_string):
  198. local_dir = f"{this_dir}/{python_version_string}"
  199. if os.path.exists(local_dir):
  200. shutil.rmtree(local_dir, ignore_errors=True)
  201. shutil.copytree(f"{this_dir}/ext-py3", local_dir)
  202. return list(map(lambda x: f"file://{local_dir}/{x}", self.local_requirements))
  203. def generate_requirements(self):
  204. if self.arch not in self.arch_requirements_map:
  205. raise ValueError(f"Unsupported architecture: {self.arch}")
  206. arch_reqs = self.arch_requirements_map[self.arch]
  207. self.requirements.extend(arch_reqs.get(self.python_version_string, arch_reqs["default"]))
  208. self.requirements.extend(self.copy_local_requirements(self.python_version_string))
  209. with open(f"{this_dir}/requirements-{self.arch}-{self.python_version_string}.txt", "w") as f:
  210. f.write("\n".join(self.requirements))
  211. def get_file_name(self):
  212. return f"{this_dir}/requirements-{self.arch}-{self.python_version_string}.txt"
  213. if __name__ == "__main__":
  214. generator = RequirementsGenerator()
  215. try:
  216. generator.generate_requirements()
  217. print(generator.get_file_name())
  218. except Exception as e:
  219. print(f"Error: {e}")
  220. sys.exit(1)