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

Don't ignore first argument passed to sphinx.apidoc.main #3668

Merged
merged 7 commits into from
May 13, 2017
Merged

Don't ignore first argument passed to sphinx.apidoc.main #3668

merged 7 commits into from
May 13, 2017

Conversation

adamjstewart
Copy link
Contributor

Feature or Bugfix

Bugfix? Depends on whether you consider it a bug or a feature 😉

Purpose

We use Sphinx to generate our documentation. Our API changes fairly often, so in order to make sure our API docs stay up-to-date, we always re-run sphinx-apidoc with each build. Unfortunately, Read the Docs skips our Makefile and directly calls:

$ sphinx-build -b html . _build/html

To get around this, we run sphinx-apidoc from our conf.py. Our call looks something like:

import sphinx.apidoc.main as sphinx_apidoc

sphinx_apidoc(['--force', '--no-toc', '--output-dir=.', '../spack'])

At first I was really confused why this gave different results than:

$ sphinx-apidoc --force --not-toc --output-dir=. ../spack

but after reading the source code, I quickly discovered that main ignores the first argument it is passed. This makes perfect sense when running sphinx-apidoc from the command line, as the first argument will be the name of the script. But it is much less intuitive when being called directly from main. This PR fixes that.

Detail

By default, main will still process sys.argv[1:], but if passed a list of arguments, it will now process all of them. I'm not sure if this bug (feature?) is documented already. My only concern is that this change isn't really backwards compatible. If you wanted it to be, I could theoretically check if the first argument is sphinx-apidoc and skip it if so.

Relates

First reported here:
https://github.com/LLNL/spack/pull/3982/files#r113266150

Unverified

This user has not yet uploaded their public signing key.
@tk0miya tk0miya requested a review from shimizukawa April 26, 2017 16:38
@tk0miya tk0miya added this to the 1.7 milestone Apr 26, 2017
@tk0miya
Copy link
Member

tk0miya commented Apr 26, 2017

@shimizukawa could you review this? I don't know what is the standards in python.

BTW, sphinx-build, sphinx-quickstart and sphinx-autogen are also uses parser.parse_args(argv[1:]). So we should also fix them if you'll accept this.

$ grep -r parse_args sphinx
sphinx/apidoc.py:    (opts, args) = parser.parse_args(argv[1:])
sphinx/cmdline.py:        opts, args = parser.parse_args(list(argv[1:]))
sphinx/ext/autosummary/generate.py:    options, args = p.parse_args(argv[1:])
sphinx/quickstart.py:        opts, args = parser.parse_args(argv[1:])

@adamjstewart
Copy link
Contributor Author

Let me know if this seems like the right thing to do. If so, I can modify the others as well.

@tk0miya
Copy link
Member

tk0miya commented Apr 26, 2017

either is fine to me. I don't have strong opinion.

Copy link
Member

@shimizukawa shimizukawa left a comment

Choose a reason for hiding this comment

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

Ether OK to me.

Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

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

Thank you for comment.
As I said, I'm okay to merge this after all other scripts are updated.

@adamjstewart
Copy link
Contributor Author

Sounds good, I'll try to take a stab at this sometime this week.

@adamjstewart
Copy link
Contributor Author

I think I got everything now? Hopefully you have good unit tests.

Copy link
Member

@tk0miya tk0miya left a comment

Choose a reason for hiding this comment

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

It seems test_extensions in test_quickstart.py failed.
https://travis-ci.org/sphinx-doc/sphinx/jobs/230493513#L1859

Could you check this please?

@@ -256,4 +256,4 @@ def main(argv):


if __name__ == '__main__':
sys.exit(main(sys.argv))
sys.exit(main(sys.argv[1:]))
Copy link
Member

Choose a reason for hiding this comment

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

You also need to update the main() in this file.
This causes following error:
https://travis-ci.org/sphinx-doc/sphinx/jobs/230493517#L746

@@ -114,7 +114,7 @@ def handle_exception(app, opts, exception, stderr=sys.stderr):
file=stderr)


def main(argv):
def main(argv=sys.argv[1:]):
Copy link
Member

Choose a reason for hiding this comment

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

mypy warns here: https://travis-ci.org/sphinx-doc/sphinx/jobs/231257064#L753
Please mark this line as # typing: ignore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, I've never used mypy before. Alternatively, I could remove the default argument and go back to the way things were before. I was just trying to make everything the same.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, sorry. I was wrong. # type: ignore is correct, not typing.

@tk0miya tk0miya merged commit 7cca0b4 into sphinx-doc:master May 13, 2017
@tk0miya
Copy link
Member

tk0miya commented May 13, 2017

Merged. Thank you for contribution!

@adamjstewart adamjstewart deleted the fixes/apidoc-main-argv branch May 13, 2017 16:12
tk0miya added a commit that referenced this pull request May 13, 2017
jaylett added a commit to jaylett/xapian that referenced this pull request Feb 19, 2018
Sphinx 1.7.0 changed the behaviour of the internal sphinx "main"
functions: sphinx-doc/sphinx#3668

In order to support both, we now need to manually strip argv[0]
before calling sphinx.main(), and also provide a dummy first
argument for pre-1.7 sphinx to skip automatically. We do this
by effectively duplicating our first "real" argument (-b html)
as -bhtml.
ojwb pushed a commit to xapian/xapian that referenced this pull request Feb 25, 2018
Sphinx 1.7.0 changed the behaviour of the internal sphinx "main"
functions: sphinx-doc/sphinx#3668

In order to support both, we now need to manually strip argv[0]
before calling sphinx.main(), and also provide a dummy first
argument for pre-1.7 sphinx to skip automatically. We do this
by effectively duplicating our first "real" argument (-b html)
as -bhtml.

(cherry picked from commit 13e3ccb)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants