juledwar / soufi

Source finder CLI and API
Apache License 2.0
0 stars 0 forks source link

Yum and Alpine finders clobber warning messages #56

Closed 0xDEC0DE closed 8 months ago

0xDEC0DE commented 8 months ago

The Yum and Alpine finders both do this in order to "pretty up" their warning messages:

warnings.formatwarning = lambda msg, *x, **y: f'WARNING: {msg}\n'

Unfortunately, this setting is global, and affects whatever application soufi is imported into.

Libraries should not be fidgeting with such things, they should just raise the warning and let the parent application worry about the formatting.

0xDEC0DE commented 8 months ago

Test case

It's easiest to reproduce with Flask:

Setup

echo 'THIS_IS_PROBLEMATIC = "^.*reg\.ex$"' > test.conf

Definitions

"expected" = prints filename, line number, and offending bit of code on warnings.

Behaves as expected

import flask
app = flask.Flask(__name__)
app.config.from_pyfile("test.conf")

Does not behave as expected

import flask
import soufi
app = flask.Flask(__name__)
app.config.from_pyfile("test.conf")