From ba0faeffd03b52ff2f26d5b7dcaf66a5b44d6fbe Mon Sep 17 00:00:00 2001 From: Martin Mahner Date: Mon, 23 Dec 2019 08:06:27 +0100 Subject: [PATCH] Monkeytype Django setup --- dpaste/monkeytype.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 dpaste/monkeytype.py diff --git a/dpaste/monkeytype.py b/dpaste/monkeytype.py new file mode 100644 index 0000000..9623198 --- /dev/null +++ b/dpaste/monkeytype.py @@ -0,0 +1,29 @@ +import os +from contextlib import contextmanager +from typing import Iterator + +from monkeytype.config import DefaultConfig + + +class DpasteConfig(DefaultConfig): + @contextmanager + def cli_context(self, command: str) -> Iterator[None]: + """ + Django Settings setup + """ + try: + import dpaste.settings.local # isort: skip + + settings = "dpaste.settings.local" + except ImportError: + settings = "dpaste.settings.base" + + os.environ.setdefault("DJANGO_SETTINGS_MODULE", settings) + + import django # isort: skip + + django.setup() + yield + + +CONFIG = DpasteConfig()