-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
DOC: Upgrade flake8-rst version #23847
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
Conversation
Hello @FHaase! Thanks for submitting the PR.
|
There are several issues like #23790, #23791 and ##23794 that people is working on, and will conflict with this PR I think. If you can try to coordinate, so we avoid duplicating efforts... Also, unless you expect the new Ping me when you get it sorted, and I'll review the changes. |
@datapythonista I've reverted changes in The PR's got merged a couple of hours ago so 0.6.0 is finally out. It has taken me some time but I think it's now usable and I'm going to open issues for the excluded files. |
Codecov Report
@@ Coverage Diff @@
## master #23847 +/- ##
=======================================
Coverage 42.46% 42.46%
=======================================
Files 161 161
Lines 51557 51557
=======================================
Hits 21892 21892
Misses 29665 29665
Continue to review full report at Codecov.
|
Nice. I surely reviewed the flake8 fixing in Let me review the changes, but sounds great. Thanks! |
I've seen the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great changes, thanks for taking care of this @FHaase
I added some comments, questions and ideas, if you can have a look
doc/source/10min.rst
Outdated
@@ -84,7 +80,7 @@ will be completed: | |||
.. ipython:: | |||
|
|||
@verbatim | |||
In [1]: df2.<TAB> | |||
In [1]: df2.<TAB> # noqa: E225, E999 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In some other PRs we've been adding python
to .. ipython:: python
and then we could remove the In [1]
. Also, not sure if it makes sense to move the @verbatim
to :verbatim:
under the directive, as I've seen in other places?
doc/source/10min.rst
Outdated
@@ -719,7 +719,7 @@ of the columns with labels: | |||
df = df.cumsum() | |||
|
|||
@savefig frame_plot_basic.png | |||
plt.figure(); df.plot(); plt.legend(loc='best') | |||
plt.figure(); df.plot(); plt.legend(loc='best') # noqa: E702 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have one in each line instead of the noqa
. Or does it need to be in the same line for the savefig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@datapythonista If simply moved into single lines the graph remains empty.
@savefig frame_plot_basic.png
plt.figure()
df.plot()
plt.legend(loc='best')
This can be fixed by moving @savfig
above the last statement:
plt.figure()
df.plot()
@savefig frame_plot_basic.png
plt.legend(loc='best')
However it becomes really verbose if you compare it to how it is before:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
my preferred option would be to use:
plt.figure();
df.plot();
plt.legend(loc='best');
and I'm not sure if the plt.figure()
is needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doc/source/10min.rst
Outdated
@@ -793,7 +793,7 @@ Gotchas | |||
|
|||
If you are attempting to perform an operation you might see an exception like: | |||
|
|||
.. code-block:: python | |||
.. code-block:: pycon |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what does pycon
do?
would it make sense to make it an ipython
block, for consistency with the rest?
Also, unrelated to your changes, but I'd change the print("I was true")
by a pass
, I think it add more confusion than value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
its the lexer for pygments.lexers.python.PythonConsoleLexer
.
But I've changed it to .. ipython::
anyway.
doc/source/basics.rst
Outdated
@@ -751,7 +754,7 @@ For example, we can fit a regression using statsmodels. Their API expects a form | |||
|
|||
.. ipython:: python | |||
|
|||
import statsmodels.formula.api as sm | |||
import statsmodels.formula.api as sm # noqa: E401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you checked it, but is the import needed?
doc/source/timeseries.rst
Outdated
@@ -32,7 +26,10 @@ Parsing time series information from various sources and formats | |||
|
|||
.. ipython:: python | |||
|
|||
dti = pd.to_datetime(['1/1/2018', np.datetime64('2018-01-01'), datetime(2018, 1, 1)]) | |||
from datetime import datetime, timedelta, time |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer a import datetime
doc/source/visualization.rst
Outdated
@@ -2,25 +2,31 @@ | |||
.. _visualization: | |||
|
|||
.. ipython:: python | |||
:flake8-add-ignore: E702, E703 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure why this is ignored, I'd prefer to not ignore much, but if needed please add a comment on what is being ignored
doc/source/visualization.rst
Outdated
:suppress: | ||
|
||
import numpy as np | ||
import pandas as pd | ||
|
||
import matplotlib # noqa: F401 | ||
# matplotlib.style.use('default') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove the import? and the comment?
doc/source/visualization.rst
Outdated
************* | ||
Visualization | ||
************* | ||
|
||
We use the standard convention for referencing the matplotlib API: | ||
|
||
.. ipython:: python | ||
:flake8-group: None | ||
:flake8-set-ignore: F401 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if there are unused imports please remove them, and if really needed, better a noqa
in the import
doc/source/visualization.rst
Outdated
@@ -133,6 +141,8 @@ For example, a bar plot can be created the following way: | |||
You can also create these other plots using the methods ``DataFrame.plot.<kind>`` instead of providing the ``kind`` keyword argument. This makes it easier to discover plot methods and the specific arguments they use: | |||
|
|||
.. ipython:: | |||
:flake8-group: None | |||
:flake8-add-ignore: E999, E225, F821 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same, add comments on what is being ignored
within |
Do you mind explaining again what's the reason for using different directives. Ideally for the code it'd be nice to just have Also, I'm sorry to ask this, but we need to split this PR. I understand for you it's easier to have everything in a single branch, and it's some extra work now that you already got the work done. But from a reviewers point to view, I'm sure other reviewers will have comments, and having all in the same place means that for even a single trivial change, we need to spend a lot of time reviewing the whole thing. Would be nice to have the obvious pep8 fixes in a first PR, as they will be merged fast. And adding new dependencies, non trivial changes to the the directives (skipping certain rules...), the upgrade of flake8... in another. Now that you already got all the changes do what you can, and dividing by whole files it's perfectly fine. But for the next time, please consider the reviewing process when making the changes. Thanks @FHaase |
de847b0
to
29039aa
Compare
Update flake8-rst version to version 0.6.0+. Signed-off-by: Fabian Haase <[email protected]>
29039aa
to
a2cf5ab
Compare
doc/source/conf.py
Outdated
@@ -74,6 +74,7 @@ | |||
'sphinx.ext.ifconfig', | |||
'sphinx.ext.linkcode', | |||
'nbsphinx', | |||
'flake8_rst.sphinxext.custom_roles', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does this do? I know we haven't done that before, but would be good to have a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
flake8-rst allows for customized merging code-blocks. Like
.. code-block:: python
:flake8-group: GroupForExample#1
code...
However sphinx throws an exception if a directive is decorated by an unknown role.
So all it does is telling the IPython and code-block directive that certain roles can be added.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be a problem for you postponing this to a new PR? I guess that's the best solution, but would like to give it a second thought, as I'm considering to build the docs without sphinx (#23763), and everything that requires a sphinx plugin would be extra work if we do that.
If it's not giving you more work or headaches, I'd prefer to fix everything else for now (may be we can ignore F821
which I think it's the main error avoided by this plugin), and then be back to this. Would that be ok?
F821, # undefined name | ||
W391, # blank line at end of file [Seems to be a bug (v0.4.1)] | ||
ignore = E402, # module level import not at top of file | ||
W503, # line break before binary operator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aren't we adding the semicolon at the end then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignoring W503
allows for
x = (a.....
- b....)
So there may be a \n
before a -
, +
...
ignoring W504
? would enforce
x = (a..... -
b....)
With a \n
after the -
, +
, ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the question was if you wanted to ignore the errors for the semicolon in df.plot();
in this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I'd rather have it on a per file based setting. It's only useful if there are many plots in one file that create cryptic outputs. If not it's better to have it checked.
doc/source/text.rst | ||
doc/source/timedeltas.rst | ||
doc/source/timeseries.rst | ||
doc/source/visualization.rst |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can do it later, but I think there are many of these that can now be removed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd do it later after giving it a final check.
Some of the files still have issues regarding PEP-8 but they have to be ignored by the newly introduced :flake8-group:
role.
I found out that if somewhere in the checked code-block is an E999
issue (even ignored) all issues relying on AST checks like F821
no longer are checked. It's not a problem with flake8 on python code as syntax errors are eventually fixed, but in context of documentation those issues sometimes make sense like in
.. ipython::
@verbatim
In [1]: df2.<TAB>
df2.A df2.bool
df2.abs df2.boxplot
df2.add df2.C
df2.add_prefix df2.clip
These blocks have to be manually ignored and therefore I'm including the checks after this is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I'm following, but I wouldn't overcomplicate things. I think that could be in its own block with nothing else, and have a noqa
for the syntax error, and I guess nothing else would be needed.
Or I think the directive also has a skip
or something like that, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, however when running flake8-rst
on the file, it looks for all the code-blocks (.. code-block::, .. ipython::), removes everything thats not code like (>>>
, outputs, ...), and then merges everything into one big block which gets passed over to flake8
.
If somewhere in that block is a syntax error, flake8
stops checking for AST-related issues. putting # noqa: E999
only prevents output, but AST checks are still broken.
However the new flake8
version will support to define which blocks are merged together, that way E999
issues can be seperated from the rest of the blocks, basically creating two different checks. One with broken AST, the other with working AST. That way F821
issues remain to be found in the rest of the file. Otherwise flake8-rst
wouldn't output anything even when there are issues.
It's surely more complicated than just ignoring E999
, but at least it's checking everything.
flake8-rst works on the bare *.rst files, therefore .. ipython
related skips have no effect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry didn't read it correctly:
I think that could be in its own block
Exactly, we could put one of these
:flake8-group: TABOutput
+:flake8-add-ignore: E999, E225
and later only reuse:flake8-group: TABOutput
:flake8-group: None
+# noqa: E999, E225
or:flake8-add-ignore: E999, E225
:flake8-group: Ignore
[disables checking for block]
'flake8_rst.sphinxext.custom_roles',
got added to allow these roles.
I'd prefer to use a way without # noqa
as it would get rendered in the documentation and might lead to slight confusion for readers who just use pandas and don't use flake8
or similar.
@FHaase can you check the comments from the previous review? |
Signed-off-by: Fabian Haase <[email protected]>
e9ec5ce
to
363d0df
Compare
@FHaase sorry to bother you with one more question. But regarding the blocks that break the syntax, and don't let the rest of the document be generated. Doesn't So, if you don't mind would be great to remove the inclusion of the sphinx extension for now, remove any file that can be removed from the list of ignores, merge master, and leave the CI green. So we can merge this, and continue the discussion while we work on the rest of the |
flake8-rst doesn't skip those. |
Signed-off-by: Fabian Haase <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
thanks @FHaase
thanks @FHaase as followups would be great to remove .rst that already pass (you have done some PR's on this already) |
Opened #24051 to remove the ignored files that have been fixed |
closes #23508
flake8-rst
version to >=0.6.0