Fix #119 -- Handle verbosity=0 level correctly and suppress all prints/logs
This commit is contained in:
1 parent
12255d9af4
commit
419f90e728
3 files changed
+14
-4
No files matched your search
@@ -9,6 +9,7 @@ New features:
|
||||
|
||||
Miscellaneous:
|
||||
* 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
|
||||
* Renamed `master` branch to `main`
|
||||
|
||||
|
||||
@@ -138,6 +138,8 @@ class Command(BaseCommand):
|
||||
|
||||
if options["verbosity"] > 1:
|
||||
logging.basicConfig(format="%(message)s", level=logging.DEBUG)
|
||||
elif options["verbosity"] == 0:
|
||||
logger.disabled = True
|
||||
else:
|
||||
logging.basicConfig(format="%(message)s")
|
||||
|
||||
@@ -201,6 +203,7 @@ class Command(BaseCommand):
|
||||
exclude_migration_tests=config["exclude_migration_tests"],
|
||||
quiet=config["quiet"],
|
||||
warnings_as_errors=config["warnings_as_errors"],
|
||||
no_output=options["verbosity"] == 0,
|
||||
)
|
||||
linter.lint_all_migrations(
|
||||
app_label=options["app_label"],
|
||||
|
||||
@@ -57,6 +57,7 @@ class MigrationLinter(object):
|
||||
exclude_migration_tests=None,
|
||||
quiet=None,
|
||||
warnings_as_errors=False,
|
||||
no_output=False,
|
||||
):
|
||||
# Store parameters and options
|
||||
self.django_path = path
|
||||
@@ -74,6 +75,7 @@ class MigrationLinter(object):
|
||||
self.only_unapplied_migrations = only_unapplied_migrations
|
||||
self.quiet = quiet or []
|
||||
self.warnings_as_errors = warnings_as_errors
|
||||
self.no_output = no_output
|
||||
|
||||
# Initialise counters
|
||||
self.reset_counters()
|
||||
@@ -248,7 +250,8 @@ class MigrationLinter(object):
|
||||
def print_linting_msg(self, app_label, migration_name, msg, lint_result):
|
||||
if lint_result.value in self.quiet:
|
||||
return
|
||||
print("({0}, {1})... {2}".format(app_label, migration_name, msg))
|
||||
if not self.no_output:
|
||||
print("({0}, {1})... {2}".format(app_label, migration_name, msg))
|
||||
|
||||
def print_errors(self, errors):
|
||||
if MessageType.ERROR.value in self.quiet:
|
||||
@@ -260,7 +263,8 @@ class MigrationLinter(object):
|
||||
if err.get("column"):
|
||||
error_str += ", column: {0}".format(err["column"])
|
||||
error_str += ")"
|
||||
print(error_str)
|
||||
if not self.no_output:
|
||||
print(error_str)
|
||||
|
||||
def print_warnings(self, warnings):
|
||||
if MessageType.WARNING.value in self.quiet:
|
||||
@@ -268,10 +272,12 @@ class MigrationLinter(object):
|
||||
|
||||
for warning_details in warnings:
|
||||
warn_str = "\t{}".format(warning_details["msg"])
|
||||
print(warn_str)
|
||||
if not self.no_output:
|
||||
print(warn_str)
|
||||
|
||||
def print_summary(self):
|
||||
print()
|
||||
if self.no_output:
|
||||
return
|
||||
print("*** Summary ***")
|
||||
print("Valid migrations: {}/{}".format(self.nb_valid, self.nb_total))
|
||||
print("Erroneous migrations: {}/{}".format(self.nb_erroneous, self.nb_total))
|
||||
|
||||
Reference in new issue
Block a user