Don't ignore first argument passed to sphinx.apidoc.main#3668
Don't ignore first argument passed to sphinx.apidoc.main#3668tk0miya merged 7 commits intosphinx-doc:masterfrom adamjstewart:fixes/apidoc-main-argv
Conversation
|
@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 |
|
Let me know if this seems like the right thing to do. If so, I can modify the others as well. |
|
either is fine to me. I don't have strong opinion. |
tk0miya
left a comment
There was a problem hiding this comment.
Thank you for comment.
As I said, I'm okay to merge this after all other scripts are updated.
|
Sounds good, I'll try to take a stab at this sometime this week. |
|
I think I got everything now? Hopefully you have good unit tests. |
tk0miya
left a comment
There was a problem hiding this comment.
It seems test_extensions in test_quickstart.py failed.
https://travis-ci.org/sphinx-doc/sphinx/jobs/230493513#L1859
Could you check this please?
|
|
||
| if __name__ == '__main__': | ||
| sys.exit(main(sys.argv)) | ||
| sys.exit(main(sys.argv[1:])) |
There was a problem hiding this comment.
You also need to update the main() in this file.
This causes following error:
https://travis-ci.org/sphinx-doc/sphinx/jobs/230493517#L746
sphinx/cmdline.py
Outdated
|
|
||
|
|
||
| def main(argv): | ||
| def main(argv=sys.argv[1:]): |
There was a problem hiding this comment.
mypy warns here: https://travis-ci.org/sphinx-doc/sphinx/jobs/231257064#L753
Please mark this line as # typing: ignore.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Oh, sorry. I was wrong. # type: ignore is correct, not typing.
|
Merged. Thank you for contribution! |
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.
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)
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-apidocwith each build. Unfortunately, Read the Docs skips our Makefile and directly calls:To get around this, we run
sphinx-apidocfrom ourconf.py. Our call looks something like:At first I was really confused why this gave different results than:
but after reading the source code, I quickly discovered that
mainignores the first argument it is passed. This makes perfect sense when runningsphinx-apidocfrom the command line, as the first argument will be the name of the script. But it is much less intuitive when being called directly frommain. This PR fixes that.Detail
By default,
mainwill still processsys.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 issphinx-apidocand skip it if so.Relates
First reported here:
https://github.com/LLNL/spack/pull/3982/files#r113266150