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

Fix #5104: apidoc: Interface of sphinx.apidoc:main() has changed #5106

Merged
merged 2 commits into from
Jun 20, 2018

Conversation

tk0miya
Copy link
Member

@tk0miya tk0miya commented Jun 18, 2018

@adamjstewart
Copy link
Contributor

Doesn't this suffer from the same problem that was fixed in #3668? Shouldn't it be argv=sys.argv[1:] and _main(argv)?

@tk0miya
Copy link
Member Author

tk0miya commented Jun 18, 2018

sphinx.apidoc:main() is only provided to keep compatibility with 1.6 or older. So it should not omit the first item of sys.argv. On the other hand, sphinx.ext.apidoc:main() takes sys.argv[1:].
I think this is correct.

@adamjstewart
Copy link
Contributor

@tk0miya Shouldn't both sphinx.ext.apidoc.main() and sphinx.apidoc.main() behave identically? Currently, both default to sys.argv[1:], the only difference is that sphinx.apidoc.main() throws away the first argument it is given, while sphinx.ext.apidoc.main() does not. This seems like it is reverting the behavior introduced in #3668.

@tk0miya
Copy link
Member Author

tk0miya commented Jun 18, 2018

Yes, #3668 is incompatible change to past release. So this revert the change. The most important feature of sphinx.apidoc:main() is taking full sys.argv as Sphinx-1.6 doing.

@adamjstewart
Copy link
Contributor

Why revert #3668? It fixed an important bug where the first argument passed to sphinx.apidoc.main is completely ignored with no warning. Reintroducing bugs to preserver compatibility with old releases doesn't make sense to me.

@tk0miya
Copy link
Member Author

tk0miya commented Jun 18, 2018

sphinx.apidoc:main() is only used to keep compatibility with past release. It should be same as 1.6's one doing. That means it should take whole of sys.argv, not sys.argv[1:].

The change of #3668 is merged into sphinx.ext.apidoc:main(). It is successor of sphinx.apidoc module. I think its interface is same as what you want.

It fixed an important bug where the first argument passed to sphinx.apidoc.main is completely ignored with no warning.

I don't think this is not a bug. The main function is not public API. So there are no specification.

@adamjstewart
Copy link
Contributor

Ah, I see. I guess I assumed that #3668 had been merged and released before 1.7.

I don't think this is not a bug. The main function is not public API. So there are no specification.

Fair enough. Is sphinx.ext.apidoc.main() a public API?

@tk0miya
Copy link
Member Author

tk0miya commented Jun 18, 2018

Fair enough. Is sphinx.ext.apidoc.main() a public API?

It's not. The public APIs are listed in document:
http://www.sphinx-doc.org/en/master/extdev/index.html

But it does not mean other functions are fragile. We'll work to keep all of functions stable. So please let me know if something goes wrong.

@adamjstewart
Copy link
Contributor

If sphinx.ext.apidoc.main isn't public, is there a recommended way to automatically generate API docs? Is it preferable to call sphinx-apidoc in a subprocess?

@tk0miya
Copy link
Member Author

tk0miya commented Jun 19, 2018

AFAIK, apidoc is useful to create skelton of API document project. So it is not needed to invoke it through APIs. For that purpose, we provides sphinx.ext.autosummary module. How about this?
Please let me know your goal.

Anyway, your request is not related with this bug. So I'd like to merge this if this works fine. Could you move to new issue please?

@stephenfin
Copy link
Contributor

stephenfin commented Jun 19, 2018

If sphinx.ext.apidoc.main isn't public, is there a recommended way to automatically generate API docs? Is it preferable to call sphinx-apidoc in a subprocess?

@adamjstewart try sphinx-contrib/apidoc. We're using this extensively in OpenStack until I can talk @tk0miya around into accepting #4101 😉

AFAIK, apidoc is useful to create skelton of API document project. So it is not needed to invoke it through APIs. For that purpose, we provides sphinx.ext.autosummary module. How about this?
Please let me know your goal.

@tk0miya I'm afraid it's more complicated than that. There are big differences between sphinx.ext.autosummary and sphinx-apidoc. I described these in #4101 (comment). Until we resolve those differences, sphinx-apidoc remains the only option for OpenStack at least.

@stephenfin
Copy link
Contributor

Why revert #3668? It fixed an important bug where the first argument passed to sphinx.apidoc.main is completely ignored with no warning. Reintroducing bugs to preserver compatibility with old releases doesn't make sense to me.

FWIW, #3668 was necessary due to a change in how argparse and optparse work. That defaults to using sys.argv[1:] unless you tell it otherwise, which we needed to do so we could call it programatically for unit tests and the likes. As you've noted though, neither original nor updated version are correct in that there's a disconnect between what we expected in the past (a list of arguments referenced by argv) and what we expect today (an option list of args and kwargs, referenced via arg and kwarg respectively). As a result, this fix seems correct.

Copy link
Contributor

@stephenfin stephenfin 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.

@jakirkham
Copy link

...try sphinx-contrib/apidoc.

Thanks for sharing @stephenfin. Glad to hear there are proper tools out there. Have been resorting to hacks like calling sphinx.ext.apidoc.main from conf.py for some time.

If it helps, @tk0miya, lots of people try to do something similar. ( readthedocs/readthedocs.org#1139 ) Am sure they would also appreciate proper support in Sphinx for this use case. :)

@jakirkham
Copy link

In any event, would still be great to have this PR land.

@codecov
Copy link

codecov bot commented Jun 20, 2018

Codecov Report

Merging #5106 into 1.7 will increase coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff             @@
##              1.7    #5106      +/-   ##
==========================================
+ Coverage   82.04%   82.05%   +<.01%     
==========================================
  Files         283      288       +5     
  Lines       37825    38144     +319     
  Branches     5860     5914      +54     
==========================================
+ Hits        31035    31298     +263     
- Misses       5481     5528      +47     
- Partials     1309     1318       +9
Impacted Files Coverage Δ
sphinx/apidoc.py 0% <0%> (ø)
sphinx/errors.py 68.42% <0%> (ø)
sphinx/search/__init__.py 95.11% <0%> (ø)
sphinx/quickstart.py 0% <0%> (ø)
sphinx/__init__.py 57.5% <0%> (ø)

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 6e27f6c...f54d886. Read the comment docs.

@tk0miya
Copy link
Member Author

tk0miya commented Jun 20, 2018

@stephenfin Thank you for your help. it was very helpful to me (because I'm very poor at English...)

@tk0miya tk0miya merged commit e78133a into sphinx-doc:1.7 Jun 20, 2018
@tk0miya tk0miya deleted the 5104_broken_apidoc_main branch June 20, 2018 13:14
@tk0miya
Copy link
Member Author

tk0miya commented Jun 20, 2018

Merged. Thank you for your comment. Let's talk about the API or modules in another issue.

I'll take a look #4101 later. Please wait a moment.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 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.

4 participants