Skip to content

Commit

Permalink
Context: Filter MarkupResemblesLocatorWarning from BeautifulSoup
Browse files Browse the repository at this point in the history
BeautifulSoup will raise a `MarkupResemblesLocatorWarning` every time it
is asked to parse a string that looks like a path or url.

This warning is intended to aid novice users. But in the context of
flamingo it leads to warning every time a content consists of something
that looks like a path or url to bs4.

With this change we globally disable this specific warning from bs4.
Disabling warning this early in the startup process makes this effective
for flamingo itself and all plugins. (Settings are loaded earlier - but
I hope nobody needs to run bs4 in their settings modules...)

Signed-off-by: Chris Fiege <cfi@pengutronix.de>
  • Loading branch information
SmithChart committed Apr 5, 2024
1 parent 1c6edfc commit ea5e010
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions flamingo/core/context.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
import shutil
import os
import warnings

Check warning on line 4 in flamingo/core/context.py

View check run for this annotation

Codecov / codecov/patch

flamingo/core/context.py#L4

Added line #L4 was not covered by tests

import bs4

Check warning on line 6 in flamingo/core/context.py

View check run for this annotation

Codecov / codecov/patch

flamingo/core/context.py#L6

Added line #L6 was not covered by tests

from flamingo.core.data_model import ContentSet, AND, NOT, OR, Q, F
from flamingo.core.plugins.plugin_manager import PluginManager
Expand Down Expand Up @@ -34,6 +37,12 @@ def setup(self):
self.logger = logging.getLogger('flamingo')
self.logger.debug('setting up context')

# BS4: Filter MarkupResemblesLocatorWarning
# BS4 emits warnings when we try to parse strings that look like a path or url.
# So if we parse some content that may only contain something that looks like a path or url,
# but is a valid content, we would be greeted with a MarkupResemblesLocatorWarning.
warnings.filterwarnings("ignore", category=bs4.MarkupResemblesLocatorWarning)

# setup plugins
self.plugins = PluginManager(self)
self.plugins.run_plugin_hook('setup')
Expand Down

0 comments on commit ea5e010

Please sign in to comment.