Fix #119 -- Handle verbosity=0 level correctly and suppress all prints/logs

This commit is contained in:
David Wobrock committed 2021-06-26 13:29:01 +02:00
1 parent 12255d9af4
commit 419f90e728
3 files changed
+11 -1

No files matched your search

+1
View File
@@ -9,6 +9,7 @@ New features:
Miscellaneous: Miscellaneous:
* Add complete and working support for `toml` configuration files * Add complete and working support for `toml` configuration files
* Handle `--verbosity 0` or `-v 0` correctly to not print anything from the linter
* Add code coverage to the linter * Add code coverage to the linter
* Renamed `master` branch to `main` * Renamed `master` branch to `main`
@@ -138,6 +138,8 @@ class Command(BaseCommand):
if options["verbosity"] > 1: if options["verbosity"] > 1:
logging.basicConfig(format="%(message)s", level=logging.DEBUG) logging.basicConfig(format="%(message)s", level=logging.DEBUG)
elif options["verbosity"] == 0:
logger.disabled = True
else: else:
logging.basicConfig(format="%(message)s") logging.basicConfig(format="%(message)s")
@@ -201,6 +203,7 @@ class Command(BaseCommand):
exclude_migration_tests=config["exclude_migration_tests"], exclude_migration_tests=config["exclude_migration_tests"],
quiet=config["quiet"], quiet=config["quiet"],
warnings_as_errors=config["warnings_as_errors"], warnings_as_errors=config["warnings_as_errors"],
no_output=options["verbosity"] == 0,
) )
linter.lint_all_migrations( linter.lint_all_migrations(
app_label=options["app_label"], app_label=options["app_label"],
+7 -1
View File
@@ -57,6 +57,7 @@ class MigrationLinter(object):
exclude_migration_tests=None, exclude_migration_tests=None,
quiet=None, quiet=None,
warnings_as_errors=False, warnings_as_errors=False,
no_output=False,
): ):
# Store parameters and options # Store parameters and options
self.django_path = path self.django_path = path
@@ -74,6 +75,7 @@ class MigrationLinter(object):
self.only_unapplied_migrations = only_unapplied_migrations self.only_unapplied_migrations = only_unapplied_migrations
self.quiet = quiet or [] self.quiet = quiet or []
self.warnings_as_errors = warnings_as_errors self.warnings_as_errors = warnings_as_errors
self.no_output = no_output
# Initialise counters # Initialise counters
self.reset_counters() self.reset_counters()
@@ -248,6 +250,7 @@ class MigrationLinter(object):
def print_linting_msg(self, app_label, migration_name, msg, lint_result): def print_linting_msg(self, app_label, migration_name, msg, lint_result):
if lint_result.value in self.quiet: if lint_result.value in self.quiet:
return return
if not self.no_output:
print("({0}, {1})... {2}".format(app_label, migration_name, msg)) print("({0}, {1})... {2}".format(app_label, migration_name, msg))
def print_errors(self, errors): def print_errors(self, errors):
@@ -260,6 +263,7 @@ class MigrationLinter(object):
if err.get("column"): if err.get("column"):
error_str += ", column: {0}".format(err["column"]) error_str += ", column: {0}".format(err["column"])
error_str += ")" error_str += ")"
if not self.no_output:
print(error_str) print(error_str)
def print_warnings(self, warnings): def print_warnings(self, warnings):
@@ -268,10 +272,12 @@ class MigrationLinter(object):
for warning_details in warnings: for warning_details in warnings:
warn_str = "\t{}".format(warning_details["msg"]) warn_str = "\t{}".format(warning_details["msg"])
if not self.no_output:
print(warn_str) print(warn_str)
def print_summary(self): def print_summary(self):
print() if self.no_output:
return
print("*** Summary ***") print("*** Summary ***")
print("Valid migrations: {}/{}".format(self.nb_valid, self.nb_total)) print("Valid migrations: {}/{}".format(self.nb_valid, self.nb_total))
print("Erroneous migrations: {}/{}".format(self.nb_erroneous, self.nb_total)) print("Erroneous migrations: {}/{}".format(self.nb_erroneous, self.nb_total))