Fix #198 -- Allow using Django settings for linter configuration
This commit is contained in:
1 parent
80b5c1dec8
commit
4fa6a33153
4 files changed
+37
-1
No files matched your search
@@ -7,6 +7,7 @@
|
||||
- Fix index creation detection when table is being created in the transaction (issue #178)
|
||||
- Handle unique index creation as adding a unique constraint (issue #183)
|
||||
- Allow any option to be set/unset in config file (issue #167)
|
||||
- Allow using Django settings for any option to be set/unset (issue #198)
|
||||
- Raise when unsupported database vendor, allow passing an option to select SQL analyser (issue #138 and #169)
|
||||
|
||||
## 3.0.1
|
||||
|
||||
@@ -6,6 +6,7 @@ import sys
|
||||
from importlib import import_module
|
||||
|
||||
import toml
|
||||
from django.conf import settings
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from ...constants import __version__
|
||||
@@ -151,9 +152,14 @@ class Command(BaseCommand):
|
||||
else:
|
||||
logging.basicConfig(format="%(message)s")
|
||||
|
||||
django_settings_options = self.read_django_settings(options)
|
||||
config_options = self.read_config_file(options)
|
||||
toml_options = self.read_toml_file(options)
|
||||
for k, v in itertools.chain(config_options.items(), toml_options.items()):
|
||||
for k, v in itertools.chain(
|
||||
django_settings_options.items(),
|
||||
config_options.items(),
|
||||
toml_options.items(),
|
||||
):
|
||||
if not options[k]:
|
||||
options[k] = v
|
||||
|
||||
@@ -186,6 +192,19 @@ class Command(BaseCommand):
|
||||
if linter.has_errors:
|
||||
sys.exit(1)
|
||||
|
||||
@staticmethod
|
||||
def read_django_settings(options):
|
||||
django_settings_options = dict()
|
||||
|
||||
django_migration_linter_settings = getattr(
|
||||
settings, "MIGRATION_LINTER_OPTIONS", dict()
|
||||
)
|
||||
for key in options:
|
||||
if key in django_migration_linter_settings:
|
||||
django_settings_options[key] = django_migration_linter_settings[key]
|
||||
|
||||
return django_settings_options
|
||||
|
||||
@staticmethod
|
||||
def read_config_file(options):
|
||||
config_options = dict()
|
||||
|
||||
@@ -41,6 +41,17 @@ Below the detailed command line options, which can all also be defined using a c
|
||||
| `--warnings-as-errors` | Handle warnings as errors and therefore return an error status code if we should. |
|
||||
| `--sql-analyser` | Specify the SQL analyser that should be used. Allowed values: 'sqlite', 'mysql', 'postgresql'. |
|
||||
|
||||
## Django settings configuration
|
||||
|
||||
All settings can be defined in the Django settings:
|
||||
|
||||
```
|
||||
MIGRATION_LINTER_OPTIONS = {
|
||||
"no_cache": True,
|
||||
"exclude_apps": ["users"]
|
||||
}
|
||||
```
|
||||
|
||||
## File configuration
|
||||
|
||||
Example `setup.cfg` file:
|
||||
|
||||
@@ -2,6 +2,7 @@ from unittest.mock import patch
|
||||
|
||||
from django.core.management import call_command
|
||||
from django.test import TransactionTestCase
|
||||
from django.test.utils import override_settings
|
||||
|
||||
|
||||
class LintMigrationsCommandTestCase(TransactionTestCase):
|
||||
@@ -29,3 +30,7 @@ class LintMigrationsCommandTestCase(TransactionTestCase):
|
||||
|
||||
with self.assertRaises(SystemExit):
|
||||
call_command("lintmigrations", app_label="app_drop_table")
|
||||
|
||||
@override_settings(MIGRATION_LINTER_OPTIONS={"app_label": "app_correct"})
|
||||
def test_django_settings_option(self):
|
||||
call_command("lintmigrations")
|
||||
Reference in new issue
Block a user