From 089a039efa17143e6d75e524bd6249dafba4f597 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 15 Jan 2021 11:11:46 +0000 Subject: [PATCH] Added "python -m configurations" entry point. inspired by https://github.com/django/django/blob/e0a46367df8b17905f1c78f5c86f88d21c0f2b4d/django/__main__.py#L1-L9 see also https://code.djangoproject.com/ticket/24857 --- configurations/__main__.py | 10 ++++++++++ tests/test_main.py | 16 ++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 configurations/__main__.py diff --git a/configurations/__main__.py b/configurations/__main__.py new file mode 100644 index 0000000..871ecc2 --- /dev/null +++ b/configurations/__main__.py @@ -0,0 +1,10 @@ +""" +invokes django-cadmin when the configurations module is run as a script. + +Example: python -m configurations check +""" + +from .management import execute_from_command_line + +if __name__ == "__main__": + execute_from_command_line() diff --git a/tests/test_main.py b/tests/test_main.py index 7cbedbe..7f0a786 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -106,6 +106,22 @@ class MainTests(TestCase): stdout=subprocess.PIPE) self.assertIn('--configuration', proc.communicate()[0].decode('utf-8')) + def test_configuration_argument_in_runypy_cli(self): + """ + Verify that's configuration option has been added to managements + commands when using the -m entry point + """ + proc = subprocess.Popen( + [sys.executable, '-m', 'configurations', 'test', '--help'], + stdout=subprocess.PIPE, + ) + self.assertIn('--configuration', proc.communicate()[0].decode('utf-8')) + proc = subprocess.Popen( + [sys.executable, '-m', 'configurations', 'runserver', '--help'], + stdout=subprocess.PIPE, + ) + self.assertIn('--configuration', proc.communicate()[0].decode('utf-8')) + def test_django_setup_only_called_once(self): proc = subprocess.Popen( [sys.executable, os.path.join(os.path.dirname(__file__),