Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Isolate strict warning counter to just the ongoing build #2607

Merged
merged 1 commit into from Oct 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 0 additions & 5 deletions mkdocs/__main__.py
Expand Up @@ -63,11 +63,6 @@ def __init__(self, log_name='mkdocs', level=logging.INFO):
self.stream.name = 'MkDocsStreamHandler'
self.logger.addHandler(self.stream)

# Add CountHandler for strict mode
self.counter = utils.log_counter
self.counter.setLevel(logging.WARNING)
self.logger.addHandler(self.counter)


pass_state = click.make_pass_decorator(State, ensure=True)

Expand Down
17 changes: 14 additions & 3 deletions mkdocs/commands/build.py
Expand Up @@ -240,8 +240,16 @@ def _build_page(page, config, doc_files, nav, env, dirty=False):

def build(config, live_server=False, dirty=False):
""" Perform a full site build. """
try:

logger = logging.getLogger('mkdocs')

# Add CountHandler for strict mode
warning_counter = utils.CountHandler()
warning_counter.setLevel(logging.WARNING)
if config['strict']:
logging.getLogger('mkdocs').addHandler(warning_counter)

try:
from time import time
start = time()

Expand Down Expand Up @@ -308,8 +316,8 @@ def build(config, live_server=False, dirty=False):
# Run `post_build` plugin events.
config['plugins'].run_event('post_build', config=config)

counts = utils.log_counter.get_counts()
if config['strict'] and len(counts):
counts = warning_counter.get_counts()
if counts:
msg = ', '.join([f'{v} {k.lower()}s' for k, v in counts])
raise Abort(f'\nAborted with {msg} in strict mode!')

Expand All @@ -323,6 +331,9 @@ def build(config, live_server=False, dirty=False):
raise Abort('\nAborted with a BuildError!')
raise

finally:
logger.removeHandler(warning_counter)


def site_directory_contains_stale_files(site_directory):
""" Check if the site directory contains stale files from a previous build. """
Expand Down
3 changes: 0 additions & 3 deletions mkdocs/utils/__init__.py
Expand Up @@ -442,9 +442,6 @@ def get_counts(self):
return [(logging.getLevelName(k), v) for k, v in sorted(self.counts.items(), reverse=True)]


# A global instance to use throughout package
log_counter = CountHandler()

# For backward compatibility as some plugins import it.
# It is no longer necessary as all messages on the
# `mkdocs` logger get counted automatically.
Expand Down