Improve explanation of how to ignore per file if the file name contains spaces
1kastner opened this issue · comments
This discussion started at PyCQA/flake8#1519.
I have a file called 01 Einfuehrung in Python.ipynb
and I would like to ignore specific issues here. In the file, I harm some design principles purposefully and show the user how this creates an issue lateron. However, my per-file-ignores are not considered. I am not sure how exactly the glob pattern is working. There are a few examples, e.g. at https://flake8.pycqa.org/en/latest/user/options.html?highlight=glob%20#cmdoption-flake8-filename but they are not exhausting enough for me.
Extract of my config:
per-file-ignores =
"01 Einfuehrung in Python.ipynb": F403, F405, E116, E731
With or without hyphens around the file name, in both cases the extract of the console output looks like this:
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[14]:1:19: E226 missing whitespace around arithmetic operator
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[14]:3:1: E731 do not assign a lambda expression, use a def
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[23]:2:23: E226 missing whitespace around arithmetic operator
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[23]:4:1: F403 'from math import *' used; unable to detect undefined names
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[23]:8:7: F405 'sin' may be undefined, or defined from star imports: math
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[23]:8:11: F405 'pi' may be undefined, or defined from star imports: math
01-einfuehrung-in-toolbox\01 einfuehrung in python.ipynb#In[23]:8:13: E226 missing whitespace around arithmetic operator
So I would wish to be able how exactly the glob patterns work but in the documentation I could not find sufficient information how to deal with spaces in file names. Thanks a lot for your assistance!
Sorry to "send you back" (I will file the issue for that) but this is an upstream issue with flake8😅
Cause
I did a quick test and the problem is with the spaces in the path, since flake8
allows you to define a list of files as well as a list of errors codes for per-file-ignores
which might be separated with commas or white spaces or a mix of them.
[flake8_nb]
per-file-ignores =
; Single file and single error code
file1.py:E231
; Single file and multiple error codes
file1.py:E231,F401
; Multiple files and single error code
file1.py file2.py:E231
; The following are all equivalent, for multiple files and multiple error code
file1.py file2.py:E231,E401
file1.py file2.py:E231 E401
file1.py,file2.py:E231,E401
This is why 01 Einfuehrung in Python.ipynb
gets split up and interpreted as 4 files (01
, Einfuehrung
, in
and Python.ipynb
) and the pattern doesn't match.
Since adding support for file paths with white spaces in it would most likely be a breaking change (e.g. file1.py file2.py
would be a interpreted as a single file) and files with spaces would only be usable as a script, I'm not sure if flake8
will add support for it.
Workarounds
- Just replace the
-
! Having spaces in your file path leads to problems all over the place (one prime example is LaTeX), - (Only if you really insist on the spaces, since it can lead to miss matches) Replace
*
in the pattern.
[flake8_nb]
per-file-ignores =
01*Einfuehrung*in*Python.ipynb: F403, F405, E116, E731
Thank you very much @s-weigand for your comment and support!