generate_requirements.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. "boto3==1.37.38",
  45. "celery[redis]==5.4.0",
  46. "cffi==1.15.0",
  47. "channels==4.2.2",
  48. "channels-redis==4.2.1",
  49. "configobj==5.0.9",
  50. "cx-Oracle==8.3.0",
  51. "daphne==3.0.2",
  52. "Django==4.2.23",
  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==4.4.0",
  57. "django-crequest==2018.5.11",
  58. "django-extensions==3.2.3",
  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.15.2",
  67. "djangorestframework-simplejwt==5.3.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. "polars[calamine]==1.8.2", # Python >= 3.8
  85. "prompt-toolkit==3.0.39",
  86. "protobuf==3.20.3",
  87. "psutil==5.8.0",
  88. "pyarrow==17.0.0",
  89. "pydantic==2.10.6",
  90. "pyformance==0.3.2",
  91. "PyJWT==2.4.0",
  92. "python-daemon==2.2.4",
  93. "python-dateutil==2.8.2",
  94. "python-ldap==3.4.3",
  95. "python-magic==0.4.27",
  96. "python-oauth2==1.1.0",
  97. "python-pam==2.0.2",
  98. "pytidylib==0.3.2",
  99. "pytz==2021.3",
  100. "PyYAML==6.0.1",
  101. "requests==2.32.3",
  102. "requests-gssapi==1.2.3",
  103. "requests-kerberos==0.14.0",
  104. "rsa==4.7.2",
  105. "ruff==0.11.10",
  106. "six==1.16.0",
  107. "slack-sdk==3.31.0",
  108. "SQLAlchemy==1.3.8",
  109. "sqlparse==0.5.0",
  110. "tablib==0.13.0",
  111. "tabulate==0.8.9",
  112. "thrift-sasl==0.4.3",
  113. "trino==0.329.0",
  114. "git+https://github.com/gethue/thrift.git",
  115. ]
  116. self.x86_64_requirements = {
  117. "default": [
  118. "cryptography==42.0.8",
  119. "lxml==4.9.1",
  120. "Markdown==3.1",
  121. "numpy==1.24.4",
  122. "pandas==2.0.3",
  123. "sasl==0.3.1",
  124. "setuptools==70.0.0",
  125. ],
  126. "3.9": [
  127. "decorator==5.1.1",
  128. "lxml==4.9.1",
  129. "Markdown==3.8",
  130. "numpy==1.24.4",
  131. "pandas==2.0.3",
  132. "pyopenssl==22.1.0",
  133. "sasl==0.3.1",
  134. "setuptools==80.9.0",
  135. ],
  136. "3.11": [
  137. "async-timeout==5.0.1",
  138. "cryptography==42.0.8",
  139. "lxml==4.9.1",
  140. "Markdown==3.8",
  141. "numpy==1.24.4",
  142. "pandas==2.0.3",
  143. "pure-sasl==0.6.2",
  144. "setuptools==80.9.0",
  145. ],
  146. }
  147. self.aarch64_requirements = {
  148. "default": [
  149. "cryptography==42.0.8",
  150. "lxml==4.9.1",
  151. "Markdown==3.1",
  152. "numpy==1.24.4",
  153. "pandas==2.0.3",
  154. "setuptools==70.0.0",
  155. ],
  156. "3.9": [
  157. "decorator==5.1.1",
  158. "lxml==4.9.1",
  159. "Markdown==3.8",
  160. "numpy==1.24.4",
  161. "pandas==2.0.3",
  162. "pyopenssl==22.1.0",
  163. "sasl==0.3.1",
  164. "setuptools==80.9.0",
  165. ],
  166. "3.11": [
  167. "async-timeout==5.0.1",
  168. "cryptography==42.0.8",
  169. "lxml==4.9.1",
  170. "Markdown==3.8",
  171. "numpy==1.24.4",
  172. "pandas==2.0.3",
  173. "pure-sasl==0.6.2",
  174. "setuptools==80.9.0",
  175. ],
  176. }
  177. self.arch_requirements_map = {
  178. "x86_64": self.x86_64_requirements,
  179. "aarch64": self.aarch64_requirements,
  180. "arm64": self.aarch64_requirements, # arm64 is treated as aarch64
  181. }
  182. self.arch = platform.machine()
  183. self.python_version_string = f"{sys.version_info.major}.{sys.version_info.minor}"
  184. def copy_local_requirements(self, python_version_string):
  185. local_dir = f"{this_dir}/{python_version_string}"
  186. if os.path.exists(local_dir):
  187. shutil.rmtree(local_dir, ignore_errors=True)
  188. shutil.copytree(f"{this_dir}/ext-py3", local_dir)
  189. return list(map(lambda x: f"file://{local_dir}/{x}", self.local_requirements))
  190. def generate_requirements(self):
  191. if self.arch not in self.arch_requirements_map:
  192. raise ValueError(f"Unsupported architecture: {self.arch}")
  193. arch_reqs = self.arch_requirements_map[self.arch]
  194. self.requirements.extend(arch_reqs.get(self.python_version_string, arch_reqs["default"]))
  195. self.requirements.extend(self.copy_local_requirements(self.python_version_string))
  196. with open(f"{this_dir}/requirements-{self.arch}-{self.python_version_string}.txt", "w") as f:
  197. f.write("\n".join(self.requirements))
  198. def get_file_name(self):
  199. return f"{this_dir}/requirements-{self.arch}-{self.python_version_string}.txt"
  200. if __name__ == "__main__":
  201. generator = RequirementsGenerator()
  202. try:
  203. generator.generate_requirements()
  204. print(generator.get_file_name())
  205. except Exception as e:
  206. print(f"Error: {e}")
  207. sys.exit(1)