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

Subpackage not in toc #4520

Closed
codingjoe opened this issue Jan 29, 2018 · 17 comments
Closed

Subpackage not in toc #4520

codingjoe opened this issue Jan 29, 2018 · 17 comments

Comments

@codingjoe
Copy link

Subject: Subpackage not in toc

Problem

In this commit it seems, there was a bug introduce. The bug does is the reverse of what the commit is trying to achieve.
Subpackages in version Sphinx (sphinx-apidoc) 1.6.6 are only picked up if they DO NOT contain a __init__.py file. Which doesn't make them packages but folder.

Procedure to reproduce the problem

mkdir -p parent/child
touch parent/__init__.py
touch parent/child/__init__.py

pip install sphinx==1.6.5
sphinx-apidoc -f --separate -o . .
cat parent.rst | grep Subpackages ; echo $?

pip install sphinx==1.6.6
sphinx-apidoc -f --separate -o . .
cat parent.rst | grep Subpackages ; echo $?

Environment info

  • OS: macOS & Ubuntu 16.04
  • Python version: 3.6.4
  • Sphinx version: 1.6.6
@tk0miya
Copy link
Member

tk0miya commented Jan 29, 2018

Is this related with #4449? If true, it was already fixed at HEAD of stable branch.
Could you try it please?

@tk0miya
Copy link
Member

tk0miya commented Jan 30, 2018

Ah, sorry. it is not related with this.

FROM tk0miya/sphinx-html

RUN mkdir -p parent/child
RUN touch parent/__init__.py
RUN touch parent/child/__init__.py

RUN pip3 install sphinx==1.6.5
RUN sphinx-apidoc -f --separate -o . .
RUN cat parent.rst | grep Subpackages ; echo $?

@tk0miya tk0miya modified the milestones: 1.6.7, 1.7 Feb 4, 2018
@tk0miya
Copy link
Member

tk0miya commented Feb 11, 2018

With #4334, apidoc certainly ignores parent.child module if it doesn't have any elements under its namespace.
Please let me know your opinion.
What document should we generate for parent.child?

Note: #4449 fixed the problem if parent/child/__init__.py is empty but there are more modules under parent.child namespace.

@tk0miya tk0miya modified the milestones: 1.7, 1.7.1 Feb 11, 2018
@codingjoe
Copy link
Author

@tk0miya this is still a major bug and effects all packages that implement django commands, as they are in mangement/commands/.
I still consider this wrong behavior, because a package that has a subpackage is not empty, because it has a package in it.
I think you should revert the commit. I don't see why someone would want to omit empty packages anyways. This could be an opt-in/out but no default.

@tk0miya
Copy link
Member

tk0miya commented Feb 13, 2018

The reverting causes broken toctree again (see #4334). So only my concern is what document should be generated for parent.child. empty page? only a title?
We need to discuss about it.

@codingjoe
Copy link
Author

I would simply not omit empty packages. I would add them. So yes, empty file with a title.
If you don't want a file for your empty package, remove the package, right?

@tk0miya
Copy link
Member

tk0miya commented Feb 16, 2018

I'd not made a empty package ever, so I don't have strong opinion for this.
I feel both skipping the package and creating empty page are natural. So either behavior is fine to me.

@zufallsgenerator what do you think?

@zufallsgenerator
Copy link
Contributor

zufallsgenerator commented Feb 16, 2018 via email

@codingjoe
Copy link
Author

I guess you mean we should keep the behavior. Ok, that means we omit empty packages but do not consider a package empty if it does have a sub-package underneath.

@zufallsgenerator
Copy link
Contributor

zufallsgenerator commented Feb 19, 2018

Sorry, I answered on the go (through an e-mail) and didn't get read the entire context. I now understand @codingjoe 's concern about the django commands that are in subfolders.

I think the entire reason why this is so hard to reason about, is the conditions that says that files that contain less or equal than 2 bytes should be skipped. Removing this check removes the need for a lot of special cases and fixes like mine (#4334). The need to call shall_skip in create_package_file (apidoc.py) might still need to remain though, to make TOC and modules generated consistent when using the option to exclude files.

So, just skipping the and path.getsize(module) <= 2

https://github.com/sphinx-doc/sphinx/blob/master/sphinx/ext/apidoc.py#L198

and it would solve this issue.

And an addition, the exact example put forth in this bug will render an inconsistent TOC in 1.6.5, I think @codingjoe meant to add something like this too for the django commands example:

echo "foo" > parent/child/foo.py  # The addition

@codingjoe
Copy link
Author

True, this is a more realistic example to reproduce the problem.

pip install django
django-admin startproject example .
mkdir -p example/management/commands
touch example/management/__init__.py
touch example/management/commands/__init__.py
echo '"""Docstring"""' > example/management/commands/my_customer_command.py

@codingjoe
Copy link
Author

Ok, I will open a PR about it. I don't know if I can finish it today, but I'll try to get it done EOW.

@zufallsgenerator
Copy link
Contributor

zufallsgenerator commented Feb 20, 2018

Actually, it's a bit more complicated than I thought, because of the new feature with wildcard excludes (#930) that has been added since #4334 .

@tk0miya tk0miya modified the milestones: 1.7.1, 1.7.2 Feb 23, 2018
@zufallsgenerator
Copy link
Contributor

I am working on a fix. Will push today.

zufallsgenerator added a commit to zufallsgenerator/sphinx that referenced this issue Feb 24, 2018
…kipping folders with only an empty __init__.py has been removed. The reason for this is that it was never working consistently in the first place and made the code unnecessary hard to reason about. Tests for the TOC generation have been added, as well as tests for the exclude mechanism since they are coupled. One test (test_ext_apidoc.py::test_exclude) has also been modified to reflect the new behaviour.
@zufallsgenerator
Copy link
Contributor

zufallsgenerator commented Feb 24, 2018

(Pull request)(#4670) added, should probably go to master and then 1.7.1
@codingjoe I think I've solved it already, so don't put unnecessary work in if you find my solution acceptable.

@codingjoe
Copy link
Author

@tk0miya can we move this ahead? I am starting to freeze sphinx to 1.6.5 in more and more of my packages because people complain about missing documentation.

tk0miya pushed a commit to tk0miya/sphinx that referenced this issue Mar 21, 2018
…kipping folders with only an empty __init__.py has been removed. The reason for this is that it was never working consistently in the first place and made the code unnecessary hard to reason about. Tests for the TOC generation have been added, as well as tests for the exclude mechanism since they are coupled. One test (test_ext_apidoc.py::test_exclude) has also been modified to reflect the new behaviour.
@tk0miya
Copy link
Member

tk0miya commented Mar 21, 2018

Fixed by #4670 and #4766.
Thanks,

@tk0miya tk0miya closed this as completed Mar 21, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 17, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants