generate_requirements.py 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. "pydantic==2.10.6",
  89. "pyformance==0.3.2",
  90. "PyJWT==2.4.0",
  91. "python-daemon==2.2.4",
  92. "python-dateutil==2.8.2",
  93. "python-ldap==3.4.3",
  94. "python-magic==0.4.27",
  95. "python-oauth2==1.1.0",
  96. "python-pam==2.0.2",
  97. "pytidylib==0.3.2",
  98. "pytz==2021.3",
  99. "PyYAML==6.0.1",
  100. "requests==2.32.3",
  101. "requests-gssapi==1.2.3",
  102. "requests-kerberos==0.14.0",
  103. "rsa==4.7.2",
  104. "ruff==0.11.10",
  105. "setuptools==70.0.0",
  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. ],
  125. "3.9": [
  126. "decorator==5.1.1",
  127. "lxml==4.9.1",
  128. "Markdown==3.8",
  129. "numpy==1.24.4",
  130. "pandas==2.0.3",
  131. "pyopenssl==22.1.0",
  132. "sasl==0.3.1",
  133. ],
  134. "3.11": [
  135. "async-timeout==5.0.1",
  136. "cryptography==42.0.8",
  137. "lxml==4.9.1",
  138. "Markdown==3.8",
  139. "numpy==1.24.4",
  140. "pandas==2.0.3",
  141. "pure-sasl==0.6.2",
  142. ],
  143. }
  144. self.aarch64_requirements = {
  145. "default": [
  146. "cryptography==42.0.8",
  147. "lxml==4.9.1",
  148. "Markdown==3.1",
  149. "numpy==1.24.4",
  150. "pandas==2.0.3",
  151. ],
  152. "3.9": [
  153. "decorator==5.1.1",
  154. "lxml==4.9.1",
  155. "Markdown==3.8",
  156. "numpy==1.24.4",
  157. "pandas==2.0.3",
  158. "pyopenssl==22.1.0",
  159. "sasl==0.3.1",
  160. ],
  161. "3.11": [
  162. "async-timeout==5.0.1",
  163. "cryptography==42.0.8",
  164. "lxml==4.9.1",
  165. "Markdown==3.8",
  166. "numpy==1.24.4",
  167. "pandas==2.0.3",
  168. "pure-sasl==0.6.2",
  169. ],
  170. }
  171. self.arch_requirements_map = {
  172. "x86_64": self.x86_64_requirements,
  173. "aarch64": self.aarch64_requirements,
  174. "arm64": self.aarch64_requirements, # arm64 is treated as aarch64
  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)