You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The above subpackages toctree is clearly missingpkgA.pkgC as a subpackage of pkgA.
Likely Reason
When attempting to generate the file pkgA.rst, a call is made to create_package_file() for pkgA, which calls shall_skip() for each subfolder in pkgA\ to check if it is a subpackage.
The [shall_skip(module, opts, excludes)] (
) takes 3 arguments - the first one module being the absolute path to the __init__.py file. For pkgC, this would mean module = <path-to-repo_root/pkgA/pkgC/__init__.py. The function has three checks, if either fails then the folder is not included as a subpackage.
The third check basically tests if the filename part of os.path.basename(module) == '__init__.py', if not then it should not start with an underscore. However the value of module gets altered during the 2nd check. See for module in glob.glob(path.join(basemodule, '*.py')). Since [glob.glob()] (https://docs.python.org/3/library/glob.html) returns list of files in arbitrary order*, it is possible that the value of module at the end of the 2nd check (and entering into the 3rd check) is the path to a filename starting with an underscore (and indeed this is what happened for me!). In the presented example, module = <path-to-repo_root/pkgA/pkgC/_fileC2.py after the 2nd check and before starting the 3rd check; thus, failing the 3rd check and pkgC is not included as a subpackage of pkgA.
* This is because glob.glob() gets the file list using a call to os.scandir() that returns files listed in arbitrary order.
The problem persists if the package itself contains an underscore in its name. I know that, PEP8 discourages the presence of underscores in package names:
Modules should have short, all-lowercase names. Underscores can be used in the module name if it improves readability. Python packages should also have short, all-lowercase names, although the use of underscores is discouraged.
The Problem
Assume the following folder structure:
When I run
sphinx-apidoc -o source .. --force
fromrepo_root/docs/
, theSubpackages
section ofrepo_root/docs/source/pkA.rst
is generated as follows:The above subpackages
toctree
is clearly missingpkgA.pkgC
as a subpackage ofpkgA
.Likely Reason
When attempting to generate the file
pkgA.rst
, a call is made tocreate_package_file()
forpkgA
, which callsshall_skip()
for each subfolder inpkgA\
to check if it is a subpackage.The [
shall_skip(module, opts, excludes)
] (sphinx/sphinx/ext/apidoc.py
Line 193 in b90c257
module
being the absolute path to the__init__.py
file. ForpkgC
, this would meanmodule = <path-to-repo_root/pkgA/pkgC/__init__.py
. The function has three checks, if either fails then the folder is not included as a subpackage.The third check basically tests if the filename part of
os.path.basename(module) == '__init__.py'
, if not then it should not start with an underscore. However the value ofmodule
gets altered during the 2nd check. Seefor module in glob.glob(path.join(basemodule, '*.py'))
. Since [glob.glob()
] (https://docs.python.org/3/library/glob.html) returns list of files in arbitrary order*, it is possible that the value ofmodule
at the end of the 2nd check (and entering into the 3rd check) is the path to a filename starting with an underscore (and indeed this is what happened for me!). In the presented example,module = <path-to-repo_root/pkgA/pkgC/_fileC2.py
after the 2nd check and before starting the 3rd check; thus, failing the 3rd check andpkgC
is not included as a subpackage ofpkgA
.* This is because
glob.glob()
gets the file list using a call toos.scandir()
that returns files listed in arbitrary order.Suggested Solution
In lines
sphinx/sphinx/ext/apidoc.py
Line 205 in b90c257
sphinx/sphinx/ext/apidoc.py
Line 205 in b90c257
shall_skip()
, change name of variablemodule
to a different name, say,module_
.The text was updated successfully, but these errors were encountered: