Coverage for waveqc/__init__.py: 48%

25 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-15 08:47 +0000

1import re 

2from re import Match 

3 

4import sentry_sdk 

5from pyramid.config import Configurator 

6from sentry_sdk.integrations.celery import CeleryIntegration 

7from sentry_sdk.integrations.pyramid import PyramidIntegration 

8from sentry_sdk.integrations.redis import RedisIntegration 

9from whitenoise import WhiteNoise 

10 

11from .config import settings as waveqc_settings 

12 

13sentry_sdk.init( 

14 dsn=waveqc_settings.SENTRY_DSN, 

15 environment=waveqc_settings.ENV, 

16 traces_sample_rate=1.0, 

17 profiles_sample_rate=1.0, 

18 integrations=[ 

19 PyramidIntegration(transaction_style="route_pattern"), 

20 CeleryIntegration(monitor_beat_tasks=True), 

21 RedisIntegration(), 

22 ], 

23) 

24 

25 

26def immutable_file_test(_: str, url: str) -> Match[str] | None: 

27 # Match filename with 8 hex digits before the extension 

28 # e.g. app.db8f2edc.js 

29 return re.match(r"^.+\.[0-9a-f]{8}\..+$", url) 

30 

31 

32def main(_: dict[str, str], **settings: bool) -> WhiteNoise: 

33 settings["pyramid.reload_templates"] = waveqc_settings.PYRAMID_RELOAD_TEMPLATES 

34 config = Configurator(settings=settings) 

35 config.include("pyramid_jinja2") 

36 config.include(".filters") 

37 config.include(".models") 

38 config.include(".routes") 

39 config.scan(".views") 

40 config.add_jinja2_renderer(".html") 

41 if waveqc_settings.DEBUG: 

42 config.include("pyramid_debugtoolbar") 

43 

44 app = config.make_wsgi_app() 

45 return WhiteNoise( 

46 app, 

47 root="waveqc/static/", 

48 prefix="static/", 

49 autorefresh=waveqc_settings.DEBUG, 

50 max_age=None, 

51 immutable_file_test=immutable_file_test, 

52 )