Skip to content
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

Integrate flake8_rst into ./ci/code_check.sh #23381

Merged
merged 16 commits into from Nov 9, 2018

Conversation

FHaase
Copy link
Contributor

@FHaase FHaase commented Oct 27, 2018

  • tests added / passed
  • passes git diff upstream/master -u -- "*.py" | flake8 --diff

Integrated flake8-rst into code_check.sh in order to check code in .. code-blocks:: python directives

  • fixed all issues found with version v0.4.1
    • F821 undefined name ignored -- too many occurences for now
    • W391 blank line at end of file -- 4 occurences where I had no idea how to fix
doc/source/contributing_docstring.rst:629:9: W391 blank line at end of file
doc/source/contributing_docstring.rst:725:9: W391 blank line at end of file
doc/source/contributing_docstring.rst:815:9: W391 blank line at end of file
doc/source/contributing_docstring.rst:911:9: W391 blank line at end of file

Added flake8-rst as development dependency
Added flake8-rst configuration
Added checks to code_checks.sh

Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
cookbook.rst:971 -> python of .. code-block:: deleted to disable
                    flake8-rst checks. %timeit is invalid Syntax,
                    # noqa: E999 does not have an effect.

Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
readding F401 detection

Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
# Conflicts:
#	ci/code_checks.sh
@pep8speaks
Copy link

Hello @FHaase! Thanks for submitting the PR.

adding flake8-rst to travis-36.yaml

reverting changes to requirements-optional-pip.txt
     pytables seems to be tables on PyPI
     [running ./scripts/convert_deps.py previously changed it]

Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
@codecov
Copy link

codecov bot commented Oct 27, 2018

Codecov Report

Merging #23381 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master   #23381   +/-   ##
=======================================
  Coverage   92.25%   92.25%           
=======================================
  Files         161      161           
  Lines       51262    51262           
=======================================
  Hits        47292    47292           
  Misses       3970     3970
Flag Coverage Δ
#multiple 90.64% <ø> (ø) ⬆️
#single 42.33% <ø> (ø) ⬆️
Impacted Files Coverage Δ
pandas/core/missing.py 91.7% <ø> (ø) ⬆️
pandas/core/accessor.py 98.79% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f691711...ed17b45. Read the comment docs.

@jschendel jschendel added Docs CI Continuous Integration Code Style Code style, linting, code_checks labels Oct 27, 2018
@gfyoung
Copy link
Member

gfyoung commented Oct 27, 2018

F821 undefined name ignored -- too many occurences for now

If this gets merged, an issue should be created for this.

@gfyoung gfyoung requested review from datapythonista and jreback and removed request for datapythonista October 27, 2018 22:07
@datapythonista
Copy link
Member

Really nice work, thank you for it.

But I don't think this is really validating the docstrings, just the rst files. We surely have plenty of pep8 errors in docstrings that are not detected here.

Besides that, in #23154, the goal was to validate pep8 of docstrings from validate_docstrings.py, so people working on docstrings can see of there is any pep8 issue at the same time of validating the rest of formats.

Happy to merge this, but let's remove the "Closes #23154" from the description, and let's create the issues for the pep8 errors being ignored as @gfyoung says.

Also, can't check well from my phone, but when adding flake8-rst to the dependencies, there are some files that are automatically generated. Did you edit them manually, or did you run convert_deps.py?

@jorisvandenbossche, @WillAyd, if you can also take a look here.

@FHaase
Copy link
Contributor Author

FHaase commented Oct 28, 2018

Okay let me summarize what I did:

  • added flake8-rst to ./ci/environment-dev.yaml then executed `./scripts/convert_deps.py
    • it changed requirement tables within ./ci/requirements-optional-pip.txt to something with pytables.
      manually reverted back to tables as pytables does not seem to be within pypi.org
  • added flake8-rst commands to ./ci/code_checks.sh
    • flake8-rst pandas # searching within *.py files in pandas subfolder.
    • flake8-rst doc --filename=*.rst # searching within *.rst files in doc subfolder
  • fixed all issues flake8-rst in version v0.4.1 finds executing both commands.
  • added flake8-rst as dependency in ./ci/travis-36.yaml to make travis pass.

What does flake8-rst do?

  • looks for .. code-blocks:: python directives
  • cuts the code-block out and passes it into flake8
  • reports the flake8 issues

Does it find everything?

  • No
    • :: or .. code-blocks:: # No specification of language python
    • .. ipython:: python # ipython currently not in RegEx
    • flake8-rst pandas --benchmark # reveals number of checked files is 3
  • The intention of the plugin however is to find all these things.

Regarding integration in validate_docstrings.py:
I didn't get it was specificly required to have it integrated there and thought having it in ./ci/code_checks.sh would already be enough. I'm going to take a look into that.

Why do I think it closes #23154 ?
The PR introduces a mechanic that [if bugless] checks code in docstrings and rst files. Currently it isn't bugfree but that is not an issue with this project, but rather with flake8-rst itself and should be fixed over there.

@FHaase
Copy link
Contributor Author

FHaase commented Oct 28, 2018

@datapythonista
calling ./ci/validate_docstrings.py now calls and outputs results of:

  • flake8 --doctest <doc.source_file_name>?
  • flake8-rst <doc.source_file_name>?
    <doc.source_file_name> only if a function name was passed.

./ci/validate_docstrings.py pandas.read_excel

Flake8 reported issues:
Invoking command "flake8 --doctest pandas/util/_decorators.py" returned:
pandas/util/_decorators.py:320:26: F721 syntax error in doctest
pandas/util/_decorators.py:321:13: F721 syntax error in doctest
pandas/util/_decorators.py:322:15: F821 undefined name '_make_signature'
pandas/util/_decorators.py:322:31: F821 undefined name 'f'

Is that what you had in mind?

@datapythonista
Copy link
Member

As I said, I was happy to merge the PR as it was. Just, we can't close the issue you referenced yet, as there is more to do.

If you can add those new changes in a separate PR I can give you more precise feedback. But summarizing, validate_doctrings.py is reporting a set of errors of different types, and PEP8 issues are just another kind of error. I don't like how flake8 is called as a new type of checked, and not as the rest of the checks. This makes things much more complicated, and doesn't consider the pep8 errors when the script is called without parameters to get the json report of all pending errors in the docstrings.

Besides that, I don't like using subprocess. I guess flake8-rst is a Python program, so we should be able to import it and call the appropriate functions.

In any case, validating the docstrings is for another PR, as it's independent of checking the code blocks.

@@ -302,23 +302,17 @@ To evaluate single-element pandas objects in a boolean context, use the method

.. warning::

You might be tempted to do the following:
Using a DataFrame as a condition will raise errors,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What was the point of changing this? We always ask changes to have one focus to keep diff minimal. Would prefer if you could back out anything unrelated to the flake8 and do in a separate PR

@@ -744,15 +744,15 @@ Transitioning to ``pytest``
.. code-block:: python

class TestReallyCoolFeature(object):
....
.... # noqa: E999
Copy link
Contributor Author

@FHaase FHaase Oct 31, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@WillAyd Would you prefer a pass instead of the noqa?

Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
Copy link
Member

@datapythonista datapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really nice work. I'd possibly use pass instead of the ... everywhere, but just a preference.

Looking forward to have all these fixes merged, and to start validating pep8 in docstrings.

Btw, if you have rendered the output of the pep directive and you can add a screenshot of it, would be nice, I don't know how that is being rendered.

@FHaase
Copy link
Contributor Author

FHaase commented Nov 3, 2018

pep257
pep8

Found another one when looking for the occurence.

@datapythonista
Copy link
Member

doesn't seem like the rendering is correct, is it? I guess what's expected is that the text shown is PEP 8 and that is a link to the pep8 page. Can't check the links, but looks like there are two different links there?

Sorry if I'm misunderstanding.

@FHaase
Copy link
Contributor Author

FHaase commented Nov 3, 2018

<a class="pep reference external" href="https://www.python.org/dev/peps/pep-0008#imports"><strong>PEP 8#imports</strong></a>
That's the generated html. It looks a little strange because of the linebreak. The link works and points to the import section of the pep page.

I'd rather use the :pep: role than having a hardcoded link everywhere.

:pep:
A reference to a Python Enhancement Proposal. This generates appropriate index entries. The text “PEP number” is generated; in the HTML output, this text is a hyperlink to an online copy of the specified PEP. You can link to a specific section by saying :pep:`number#anchor`.

@datapythonista
Copy link
Member

thanks for the clarification, if that's the case all good.

@WillAyd can you take a look and merge if you're happy?

@FHaase
Copy link
Contributor Author

FHaase commented Nov 4, 2018

Before merging I'd like to change two more things:

  • remove flake8_rst coverage from .py files as there won't be any .. code-blocks:: within NumpyDocstrings. And flake8 with --docstrings options will cover it once ENH: Use flake8 to check for PEP8 violations in doctests #23399 is merged and integrated in ci.
  • temporarily fix version to 0.4.2 as newer version will cover more types ( especially .. ipython::), thus suddenly letting travis fail.

I'm just waiting for any more suggestions to not trigger ci-builds. [skip ci] seems to not work with circle ci and azure pipeline.

@datapythonista
Copy link
Member

I wouldn't worry that much about the CI, and I'd leave the PR in a state that you're happy and it can be merged.

@FHaase
Copy link
Contributor Author

FHaase commented Nov 4, 2018

Okay can merge if wanted

@datapythonista
Copy link
Member

@WillAyd can you take another look, and merge on green if you're happy.

Thanks @FHaase for the work on this, really nice PR. If you want to create two issues for the errors you're ignoring, that would be nice. I'm sure you'll be better than me at explaining what are the problems. You can mention this PR, and mention me too if you want.

Signed-off-by: Fabian Haase <haase.fabian@gmail.com>
@jreback
Copy link
Contributor

jreback commented Nov 6, 2018

@datapythonista note this will slightly conflict with your revision of ci deps (need to add the new package)

@datapythonista
Copy link
Member

no problem, I can update the other two PRs, their CI is still waiting, so it's a good time

@datapythonista
Copy link
Member

@FHaase can you fix the conflicts please? Sorry this wasn't merged before.

@FHaase
Copy link
Contributor Author

FHaase commented Nov 9, 2018

@datapythonista No Problem. Currently fixing issues within the docs getting covered by an updated flake8-rst. Is it possible to add a PR that builds on an unmerged PR?

@datapythonista
Copy link
Member

It's possible, but makes things a bit tricky, so I'd better wait.

@jreback @WillAyd can you take a look at this again? Would be nice to get it merged once it's green.

Copy link
Member

@jorisvandenbossche jorisvandenbossche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

@datapythonista datapythonista merged commit efd1844 into pandas-dev:master Nov 9, 2018
@datapythonista
Copy link
Member

Thanks @FHaase, nice work. It's great to have all those issues fixed, and validation in the rst files.

thoo added a commit to thoo/pandas that referenced this pull request Nov 10, 2018
…fixed

* upstream/master: (47 commits)
  CLN: remove values attribute from datetimelike EAs (pandas-dev#23603)
  DOC/CI: Add linting to rst files, and fix issues (pandas-dev#23381)
  PERF: Speeds up creation of Period, PeriodArray, with Offset freq (pandas-dev#23589)
  PERF: define is_all_dates to shortcut inadvertent copy when slicing an IntervalIndex (pandas-dev#23591)
  TST: Tests and Helpers for Datetime/Period Arrays (pandas-dev#23502)
  Update description of Index._values/values/ndarray_values (pandas-dev#23507)
  Fixes to make validate_docstrings.py not generate warnings or unwanted output (pandas-dev#23552)
  DOC: Added note about groupby excluding Decimal columns by default (pandas-dev#18953)
  ENH: Support writing timestamps with timezones with to_sql (pandas-dev#22654)
  CI: Auto-cancel redundant builds (pandas-dev#23523)
  Preserve EA dtype in DataFrame.stack (pandas-dev#23285)
  TST: Fix dtype mismatch on 32bit in IntervalTree get_indexer test (pandas-dev#23468)
  BUG: raise if invalid freq is passed (pandas-dev#23546)
  remove uses of (ts)?lib.(NaT|iNaT|Timestamp) (pandas-dev#23562)
  BUG: Fix error message for invalid HTML flavor (pandas-dev#23550)
  ENH: Support EAs in Series.unstack (pandas-dev#23284)
  DOC: Updating DataFrame.join docstring (pandas-dev#23471)
  TST: coverage for skipped tests in io/formats/test_to_html.py (pandas-dev#22888)
  BUG: Return KeyError for invalid string key (pandas-dev#23540)
  BUG: DatetimeIndex slicing with boolean Index raises TypeError (pandas-dev#22852)
  ...
JustinZhengBC pushed a commit to JustinZhengBC/pandas that referenced this pull request Nov 14, 2018
tm9k1 pushed a commit to tm9k1/pandas that referenced this pull request Nov 19, 2018
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Pingviinituutti pushed a commit to Pingviinituutti/pandas that referenced this pull request Feb 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI Continuous Integration Code Style Code style, linting, code_checks Docs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants