Allow overriding any option through config file, and not only a subset
This commit is contained in:
1 parent
3219f9cf8a
commit
5a6ddd0d63
2 files changed
+22
-46
No files matched your search
@@ -6,6 +6,7 @@
|
|||||||
- Add support for Django 4.0
|
- Add support for Django 4.0
|
||||||
- Fix index creation detection when table is being created in the transaction (issue #178)
|
- 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)
|
- Handle unique index creation as adding a unique constraint (issue #183)
|
||||||
|
- Allow any option to be set/unset in config file (issue #167)
|
||||||
|
|
||||||
## 3.0.1
|
## 3.0.1
|
||||||
|
|
||||||
|
|||||||
@@ -143,66 +143,41 @@ class Command(BaseCommand):
|
|||||||
else:
|
else:
|
||||||
logging.basicConfig(format="%(message)s")
|
logging.basicConfig(format="%(message)s")
|
||||||
|
|
||||||
keys = (
|
|
||||||
"ignore_name_contains",
|
|
||||||
"ignore_name",
|
|
||||||
"include_name_contains",
|
|
||||||
"include_name",
|
|
||||||
"include_apps",
|
|
||||||
"exclude_apps",
|
|
||||||
"database",
|
|
||||||
"cache_path",
|
|
||||||
"no_cache",
|
|
||||||
"applied_migrations",
|
|
||||||
"unapplied_migrations",
|
|
||||||
"exclude_migration_tests",
|
|
||||||
"quiet",
|
|
||||||
"warnings_as_errors",
|
|
||||||
)
|
|
||||||
boolean_keys = (
|
|
||||||
"no_cache",
|
|
||||||
"applied_migrations",
|
|
||||||
"unapplied_migrations",
|
|
||||||
"warnings_as_errors",
|
|
||||||
)
|
|
||||||
|
|
||||||
config = {key: options[key] for key in keys}
|
|
||||||
|
|
||||||
config_parser = configparser.ConfigParser()
|
config_parser = configparser.ConfigParser()
|
||||||
config_parser.read(DEFAULT_CONFIG_FILES, encoding="utf-8")
|
config_parser.read(DEFAULT_CONFIG_FILES, encoding="utf-8")
|
||||||
for key in keys:
|
for key, value in options.items():
|
||||||
if key in boolean_keys:
|
if isinstance(value, bool):
|
||||||
config_get_fn = config_parser.getboolean
|
config_get_fn = config_parser.getboolean
|
||||||
else:
|
else:
|
||||||
config_get_fn = config_parser.get
|
config_get_fn = config_parser.get
|
||||||
|
|
||||||
config_value = config_get_fn(CONFIG_NAME, key, fallback=None)
|
config_value = config_get_fn(CONFIG_NAME, key, fallback=None)
|
||||||
if config_value and not config[key]:
|
if config_value and not options[key]:
|
||||||
config[key] = config_value
|
options[key] = config_value
|
||||||
|
|
||||||
if os.path.exists(PYPROJECT_TOML):
|
if os.path.exists(PYPROJECT_TOML):
|
||||||
pyproject_toml = toml.load(PYPROJECT_TOML)
|
pyproject_toml = toml.load(PYPROJECT_TOML)
|
||||||
section = pyproject_toml.get("tool", {}).get(CONFIG_NAME, {})
|
section = pyproject_toml.get("tool", {}).get(CONFIG_NAME, {})
|
||||||
for key in keys:
|
for key in options:
|
||||||
if key in section and not config[key]:
|
if key in section and not options[key]:
|
||||||
config[key] = section[key]
|
options[key] = section[key]
|
||||||
|
|
||||||
linter = MigrationLinter(
|
linter = MigrationLinter(
|
||||||
settings_path,
|
settings_path,
|
||||||
ignore_name_contains=config["ignore_name_contains"],
|
ignore_name_contains=options["ignore_name_contains"],
|
||||||
ignore_name=config["ignore_name"],
|
ignore_name=options["ignore_name"],
|
||||||
include_name_contains=config["include_name_contains"],
|
include_name_contains=options["include_name_contains"],
|
||||||
include_name=config["include_name"],
|
include_name=options["include_name"],
|
||||||
include_apps=config["include_apps"],
|
include_apps=options["include_apps"],
|
||||||
exclude_apps=config["exclude_apps"],
|
exclude_apps=options["exclude_apps"],
|
||||||
database=config["database"],
|
database=options["database"],
|
||||||
cache_path=config["cache_path"],
|
cache_path=options["cache_path"],
|
||||||
no_cache=config["no_cache"],
|
no_cache=options["no_cache"],
|
||||||
only_applied_migrations=config["applied_migrations"],
|
only_applied_migrations=options["applied_migrations"],
|
||||||
only_unapplied_migrations=config["unapplied_migrations"],
|
only_unapplied_migrations=options["unapplied_migrations"],
|
||||||
exclude_migration_tests=config["exclude_migration_tests"],
|
exclude_migration_tests=options["exclude_migration_tests"],
|
||||||
quiet=config["quiet"],
|
quiet=options["quiet"],
|
||||||
warnings_as_errors=config["warnings_as_errors"],
|
warnings_as_errors=options["warnings_as_errors"],
|
||||||
no_output=options["verbosity"] == 0,
|
no_output=options["verbosity"] == 0,
|
||||||
)
|
)
|
||||||
linter.lint_all_migrations(
|
linter.lint_all_migrations(
|
||||||
|
|||||||
Reference in new issue
Block a user