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

Use node.findall if available (docutils 18.x) #403

Merged
merged 7 commits into from
Jun 2, 2022

Conversation

drammock
Copy link
Contributor

@drammock drammock commented May 28, 2022

closes #399

@drammock drammock mentioned this pull request May 28, 2022
@jarrodmillman
Copy link
Member

You can fix the linter warnings via:

pip install pre-commit
pre-commit run --all-files --show-diff-on-failure --color always

Or do

 pip install pre-commit
 pre-commit install

and it will automatically run when you try to commit.

@jarrodmillman
Copy link
Member

We will want to make sure we still support docutils < 0.18 and sphinx==4, I think.

@drammock
Copy link
Contributor Author

drammock commented May 28, 2022

pre-commit is failing, looks like it mistakes python 3.10 for python 3.1 (!!) here's the log

version information

pre-commit version: 2.19.0
git --version: git version 2.25.1
sys.version:
    3.10.4 | packaged by conda-forge | (main, Mar 24 2022, 17:39:04) [GCC 10.3.0]
sys.executable: /opt/miniforge3/envs/numpydoc-dev/bin/python3.1
os.name: posix
sys.platform: linux

error information

An unexpected error has occurred: CalledProcessError: command: ('/opt/miniforge3/envs/numpydoc-dev/bin/python3.1', '-mvirtualenv', '/home/drmccloy/.cache/pre-commit/repowbc6hl47/py_env-python3.1', '-p', 'python3.1')
return code: 1
expected return code: 0
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.1'
    
stderr: (none)
Traceback (most recent call last):
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/error_handler.py", line 73, in error_handler
    yield
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/main.py", line 361, in main
    return hook_impl(
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/commands/hook_impl.py", line 238, in hook_impl
    return retv | run(config, store, ns)
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/commands/run.py", line 414, in run
    install_hook_envs(to_install, store)
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/repository.py", line 223, in install_hook_envs
    _hook_install(hook)
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/repository.py", line 79, in _hook_install
    lang.install_environment(
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/languages/python.py", line 219, in install_environment
    cmd_output_b(*venv_cmd, cwd='/')
  File "/opt/miniforge3/envs/numpydoc-dev/lib/python3.10/site-packages/pre_commit/util.py", line 146, in cmd_output_b
    raise CalledProcessError(returncode, cmd, retcode, stdout_b, stderr_b)
pre_commit.util.CalledProcessError: command: ('/opt/miniforge3/envs/numpydoc-dev/bin/python3.1', '-mvirtualenv', '/home/drmccloy/.cache/pre-commit/repowbc6hl47/py_env-python3.1', '-p', 'python3.1')
return code: 1
expected return code: 0
stdout:
    RuntimeError: failed to find interpreter for Builtin discover of python_spec='python3.1'
    
stderr: (none)

EDIT fixed by manually typing the zero into .git/hooks/pre-commit 🤦🏻

@drammock
Copy link
Contributor Author

We will want to make sure we still support docutils < 0.18 and sphinx==4, I think.

my change to test_reference will break that, I think. Stand by.

@jarrodmillman jarrodmillman changed the title use node.findall if available (docutils 18.x) Use node.findall if available (docutils 18.x) May 31, 2022
@jarrodmillman jarrodmillman added this to the 1.4.0 milestone May 31, 2022
numpydoc/numpydoc.py Outdated Show resolved Hide resolved
numpydoc/tests/test_full.py Show resolved Hide resolved
@jarrodmillman jarrodmillman marked this pull request as ready for review May 31, 2022 17:47
"""Triage node.traverse (docutils <0.18) vs node.findall.

TODO: This check can be removed when the minimum supported docutils version
for numpydoc is docutils>=0.18
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to be clear, the findall method was only added in docutils 0.18, correct?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I double-checked, and in fact it wasn't introduced until 0.18.1:

Release 0.18.1
==============

* docutils/nodes.py

  - `Node.traverse()` returns a list again to restore backwards
    compatibility. Fixes bug #431.

  - New method `Node.findall()`: like `Node.traverse()` but returns an
    iterator. Obsoletes `Node.traverse()`.

(from https://sourceforge.net/p/docutils/code/HEAD/tree/trunk/docutils/HISTORY.txt)

I'll push a commit to be more specific about the version.

@drammock
Copy link
Contributor Author

drammock commented Jun 1, 2022

Just a note that although the CIs were coming back green before the last commit, I don't think they're actually testing against sphinx 5.0beta / docutils 0.18 ? Locally I still see this:

=================================== short test summary info ===================================
XFAIL numpydoc/tests/test_validate.py::TestValidator::test_bad_docstrings[BadParameters-blank_lines-msgs30]
XFAIL numpydoc/tests/test_validate.py::TestValidator::test_bad_docstrings[BadReturns-no_type-msgs33]
=============================== 237 passed, 2 xfailed in 1.73s ================================

and I'm not sure how to fix it... that pytest.parametrize is over 200 lines long and I haven't had the time to wrap my head around it. Maybe @datapythonista or @larsoner have time to look?

@drammock
Copy link
Contributor Author

drammock commented Jun 1, 2022

Just a note that although the CIs were coming back green before the last commit, I don't think they're actually testing against sphinx 5.0beta / docutils 0.18 ?

Never mind, I'm wrong, I just spotted the prerelease jobs. And I also just realized that I was mis-reading the pytest output. Those are successfully failing XFAILs not unexpectedly passing XFAILs. So I think this is ready for review/merge @jarrodmillman

Copy link
Collaborator

@larsoner larsoner left a comment

Choose a reason for hiding this comment

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

Code changes LGTM, +1 for merge. Feel free to merge if you're happy @jarrodmillman !

I can also confirm that on docutils 0.18.1 I have failures building MNE-Python's doc, and with this PR things build fine.

@jarrodmillman
Copy link
Member

See #404. That should fix the test failures.

@drammock
Copy link
Contributor Author

drammock commented Jun 2, 2022

See #404. That should fix the test failures.

Ok great! Can you manually re-trigger the failing runs? I can't just push an empty commit; as a first time contrib here, the CIs will wait for maintainer approval anyway.

@larsoner
Copy link
Collaborator

larsoner commented Jun 2, 2022

Since it's a change to the CI yaml you'll need to merge or rebase I think

@drammock
Copy link
Contributor Author

drammock commented Jun 2, 2022

Since it's a change to the CI yaml you'll need to merge or rebase I think

Ah right, of course. Will do when I'm not on a phone

@larsoner
Copy link
Collaborator

larsoner commented Jun 2, 2022

All green!

@jarrodmillman
Copy link
Member

Thanks!!

@jarrodmillman jarrodmillman merged commit 601642b into numpy:main Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

sphinx 5 compatibility
4 participants