Project-level configuration files not found when run inside a Jupyer notebook
Please describe how you installed Flake8
I installed flake8 on Ubuntu 18.04 with pip inside a virtualenv
$ pip install flake8
Please provide the exact, unmodified output of flake8 --bug-report
{
"dependencies": [
{
"dependency": "entrypoints",
"version": "0.3"
}
],
"platform": {
"python_implementation": "CPython",
"python_version": "3.6.7",
"system": "Linux"
},
"plugins": [
{
"is_local": false,
"plugin": "mccabe",
"version": "0.6.1"
},
{
"is_local": false,
"plugin": "pycodestyle",
"version": "2.5.0"
},
{
"is_local": false,
"plugin": "pyflakes",
"version": "2.1.1"
}
],
"version": "3.7.7"
}
Please describe the problem or feature
While using a downstream repository to perform linting on the cells of Jupyter notebooks, I noticed that my configuration files were not being respected, even though they were respected when invoking flake8
from the command line.
If this is a bug report, please explain with examples (and example code) what you expected to happen and what actually happened.
If I execute the following
from flake8.api import legacy
style_guide = legacy.get_style_guide()
style_guide.options
inside a Python terminal, the ignore
attribute contains the ignore
s from my project-level specification, as desired.
If I run the same lines in a Jupyter notebook in the same directory, only the default ignore
s are included. ignore
s specified in a .flake8
file in that directory do not appear.
I did a little bit of digging to try and determine where the problem is occurring, and it seems to be somewhere between the ConfigFileFinder
and the Application
.
The code below is collected in a GitHub gist here.
If I execute the internals of get_style_guide
up to 37 in api.legacy
in order to gain direct access to the application
, like so:
import flake8
from flake8.formatting import base as formatter
from flake8.main import application as app
application = app.Application()
application.parse_preliminary_options_and_args([])
flake8.configure_logging(
application.prelim_opts.verbose, application.prelim_opts.output_file
)
application.make_config_finder()
application.find_plugins()
application.register_plugin_options()
application.parse_configuration_and_cli([])
then, in a Jupyter notebook, application.config_finder.local_config_files
returns an empty list, indicating that the local config files were not found, but the same procedure returns a non-empty list in a Python terminal.
But if, inside the Jupyter notebook, I then run the following:
import flake8.options.config as config
cff = config.ConfigFileFinder(application.program_name, [], [])
cff.local_config_files()
the local config file is present. I was unable to dig any further to find out where the divergence in behavior is occurring.
Many thanks for providing an awesome tool! Your work is very much appreciated.