setup.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 import (
  19. BuildAssetsCommand,
  20. BuildIntegrationDocsCommand,
  21. BuildJsSdkRegistryCommand,
  22. )
  23. IS_LIGHT_BUILD = os.environ.get("SENTRY_LIGHT_BUILD") == "1"
  24. class SentrySDistCommand(SDistCommand):
  25. # If we are not a light build we want to also execute build_assets as
  26. # part of our source build pipeline.
  27. if not IS_LIGHT_BUILD:
  28. sub_commands = SDistCommand.sub_commands + [
  29. ("build_integration_docs", None),
  30. ("build_assets", None),
  31. ("build_js_sdk_registry", None),
  32. ]
  33. class SentryBuildCommand(BuildCommand):
  34. def run(self):
  35. from distutils import log as distutils_log
  36. distutils_log.set_threshold(distutils_log.WARN)
  37. if not IS_LIGHT_BUILD:
  38. self.run_command("build_integration_docs")
  39. self.run_command("build_assets")
  40. self.run_command("build_js_sdk_registry")
  41. BuildCommand.run(self)
  42. class SentryDevelopCommand(DevelopCommand):
  43. def run(self):
  44. DevelopCommand.run(self)
  45. if not IS_LIGHT_BUILD:
  46. self.run_command("build_integration_docs")
  47. self.run_command("build_assets")
  48. self.run_command("build_js_sdk_registry")
  49. cmdclass = {
  50. "sdist": SentrySDistCommand,
  51. "develop": SentryDevelopCommand,
  52. "build": SentryBuildCommand,
  53. "build_assets": BuildAssetsCommand,
  54. "build_integration_docs": BuildIntegrationDocsCommand,
  55. "build_js_sdk_registry": BuildJsSdkRegistryCommand,
  56. }
  57. def get_requirements(env):
  58. with open(f"requirements-{env}.txt") as fp:
  59. return [x.strip() for x in fp.read().split("\n") if not x.startswith(("#", "--"))]
  60. # Only include dev requirements in non-binary distributions as we don't want these
  61. # to be listed in the wheels. Main reason for this is being able to use git/URL dependencies
  62. # for development, which will be rejected by PyPI when trying to upload the wheel.
  63. extras_require = {"rabbitmq": ["amqp==2.6.1"]}
  64. if not sys.argv[1:][0].startswith("bdist"):
  65. extras_require["dev"] = get_requirements("dev-frozen")
  66. setup(
  67. install_requires=get_requirements("frozen"),
  68. extras_require=extras_require,
  69. cmdclass=cmdclass,
  70. )