setup.py 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #!/usr/bin/env python
  2. import os
  3. import sys
  4. python_version = sys.version_info[:2]
  5. if python_version < (3, 8):
  6. sys.exit(f"Error: Sentry requires at least Python 3.8 ({python_version})")
  7. if python_version != (3, 8):
  8. import logging
  9. logger = logging.getLogger()
  10. logger.warning(f"A Python version different than 3.8 is being used ({python_version})")
  11. from distutils.command.build import build as BuildCommand
  12. from setuptools import setup
  13. from setuptools.command.develop import develop as DevelopCommand
  14. from setuptools.command.sdist import sdist as SDistCommand
  15. ROOT = os.path.dirname(os.path.abspath(__file__))
  16. # add sentry to path so we can import sentry.utils.distutils
  17. sys.path.insert(0, os.path.join(ROOT, "src"))
  18. from sentry.utils.distutils.commands.build_assets import BuildAssetsCommand
  19. from sentry.utils.distutils.commands.build_integration_docs import BuildIntegrationDocsCommand
  20. from sentry.utils.distutils.commands.build_js_sdk_registry import BuildJsSdkRegistryCommand
  21. IS_LIGHT_BUILD = os.environ.get("SENTRY_LIGHT_BUILD") == "1"
  22. class SentrySDistCommand(SDistCommand):
  23. # If we are not a light build we want to also execute build_assets as
  24. # part of our source build pipeline.
  25. if not IS_LIGHT_BUILD:
  26. sub_commands = SDistCommand.sub_commands + [
  27. ("build_integration_docs", None),
  28. ("build_assets", None),
  29. ("build_js_sdk_registry", None),
  30. ]
  31. class SentryBuildCommand(BuildCommand):
  32. def run(self):
  33. from distutils import log as distutils_log
  34. distutils_log.set_threshold(distutils_log.WARN)
  35. if not IS_LIGHT_BUILD:
  36. self.run_command("build_integration_docs")
  37. self.run_command("build_assets")
  38. self.run_command("build_js_sdk_registry")
  39. BuildCommand.run(self)
  40. class SentryDevelopCommand(DevelopCommand):
  41. def run(self):
  42. DevelopCommand.run(self)
  43. if not IS_LIGHT_BUILD:
  44. self.run_command("build_integration_docs")
  45. self.run_command("build_assets")
  46. self.run_command("build_js_sdk_registry")
  47. cmdclass = {
  48. "sdist": SentrySDistCommand,
  49. "develop": SentryDevelopCommand,
  50. "build": SentryBuildCommand,
  51. "build_assets": BuildAssetsCommand,
  52. "build_integration_docs": BuildIntegrationDocsCommand,
  53. "build_js_sdk_registry": BuildJsSdkRegistryCommand,
  54. }
  55. def get_requirements(env):
  56. with open(f"requirements-{env}.txt") as fp:
  57. return [x.strip() for x in fp.read().split("\n") if not x.startswith(("#", "--"))]
  58. # Only include dev requirements in non-binary distributions as we don't want these
  59. # to be listed in the wheels. Main reason for this is being able to use git/URL dependencies
  60. # for development, which will be rejected by PyPI when trying to upload the wheel.
  61. extras_require = {"rabbitmq": ["amqp==2.6.1"]}
  62. if not sys.argv[1:][0].startswith("bdist"):
  63. extras_require["dev"] = get_requirements("dev-frozen")
  64. setup(
  65. install_requires=get_requirements("frozen"),
  66. extras_require=extras_require,
  67. cmdclass=cmdclass,
  68. )