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

Never skip modules and packages #453

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions autoapi/_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -408,12 +408,26 @@ class PythonModule(TopLevelPythonPythonMapper):

type = "module"

def _should_skip(self) -> bool:
skip_private_member = (
self.is_private_member and "private-members" not in self.options
)

return self.obj.get("hide", False) or skip_private_member


class PythonPackage(TopLevelPythonPythonMapper):
"""The representation of a package."""

type = "package"

def _should_skip(self) -> bool:
skip_private_member = (
self.is_private_member and "private-members" not in self.options
)

return self.obj.get("hide", False) or skip_private_member


class PythonClass(PythonObject):
"""The representation of a class."""
Expand Down
23 changes: 23 additions & 0 deletions tests/python/py3moduleexample/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-

templates_path = ["_templates"]
source_suffix = ".rst"
master_doc = "index"
project = "pyexample"
copyright = "2015, readthedocs"
author = "readthedocs"
version = "0.1"
release = "0.1"
language = "en"
exclude_patterns = ["_build"]
pygments_style = "sphinx"
todo_include_todos = False
html_theme = "alabaster"
htmlhelp_basename = "pyexampledoc"
extensions = ["sphinx.ext.autodoc", "autoapi.extension"]
autoapi_dirs = ["example"]
autoapi_python_class_content = "both"
autoapi_keep_files = True
autoapi_options = [
"members",
]
3 changes: 3 additions & 0 deletions tests/python/py3moduleexample/example/_hidden.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def hidden_function() -> int:
"""A hidden function"""
return 1
167 changes: 167 additions & 0 deletions tests/python/py3moduleexample/example/example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
# -*- coding: utf-8 -*-
import asyncio
import typing
from typing import ClassVar, Dict, Iterable, Generic, List, TypeVar, Union, overload

from example2 import B

T = TypeVar("T")
U = TypeVar("U")

software = "sphin'x"
more_software = 'sphinx"autoapi'
interesting_string = "interesting\"fun'\\'string"

code_snippet = """The following is some code:

# -*- coding: utf-8 -*-
from __future__ import absolute_import, division, print_function, unicode_literals
# from future.builtins.disabled import *
# from builtins import *

print("chunky o'block")
"""

max_rating: int = 10

is_valid: bool
if max_rating > 100:
is_valid = False
else:
is_valid = True

ratings: List[int] = [0, 1, 2, 3, 4, 5]

rating_names: Dict[int, str] = {0: "zero", 1: "one"}


def f(start: int, end: int) -> Iterable[int]:
"This is f"
i = start
while i < end:
yield i
i += 1


mixed_list: List[Union[str, int]] = [1, "two", 3]
"This is mixed"


def f2(not_yet_a: "A") -> int: ...


def f3(imported: B) -> B: ...


class MyGeneric(Generic[T, U]): ...


@overload
def overloaded_func(a: float) -> float: ...


@typing.overload
def overloaded_func(a: str) -> str: ...


def overloaded_func(a: Union[float, str]) -> Union[float, str]:
"""Overloaded function"""
return a * 2


@overload
def undoc_overloaded_func(a: str) -> str: ...


def undoc_overloaded_func(a: str) -> str:
return a * 2


class A:
"""class A"""

is_an_a: ClassVar[bool] = True
not_assigned_to: ClassVar[str]

def __init__(self):
self.instance_var: bool = True
"""This is an instance_var."""

async def async_method(self, wait: bool) -> int:
if wait:
await asyncio.sleep(1)
return 5

@property
def my_prop(self) -> str:
"""My property."""
return "prop"

def my_method(self) -> str:
"""My method."""
return "method"

@overload
def overloaded_method(self, a: float) -> float: ...

@typing.overload
def overloaded_method(self, a: str) -> str: ...

def overloaded_method(self, a: Union[float, str]) -> Union[float, str]:
"""Overloaded method"""
return a * 2

@overload
def undoc_overloaded_method(self, a: float) -> float: ...

def undoc_overloaded_method(self, a: float) -> float:
return a * 2

@typing.overload
@classmethod
def overloaded_class_method(cls, a: float) -> float: ...

@overload
@classmethod
def overloaded_class_method(cls, a: str) -> str: ...

@classmethod
def overloaded_class_method(cls, a: Union[float, str]) -> Union[float, str]:
"""Overloaded class method"""
return a * 2


class C:
@overload
def __init__(self, a: int) -> None: ...

@typing.overload
def __init__(self, a: float) -> None: ...

def __init__(self, a: str): ...


class D(C):
class Da: ...

class DB(Da): ...

...


async def async_function(wait: bool) -> int:
"""Blah.

Args:
wait: Blah
"""
if wait:
await asyncio.sleep(1)

return 5


global_a: A = A()


class SomeMetaclass(type): ...
2 changes: 2 additions & 0 deletions tests/python/py3moduleexample/example/example2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class B:
pass
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def hidden_function() -> int:
"""A hidden function"""
return 1
3 changes: 3 additions & 0 deletions tests/python/py3moduleexample/example/example3/example3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def a_function() -> int:
"""A third function"""
return 3
25 changes: 25 additions & 0 deletions tests/python/py3moduleexample/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. pyexample documentation master file, created by
sphinx-quickstart on Fri May 29 13:34:37 2015.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.

Welcome to pyexample's documentation!
=====================================

.. toctree::

autoapi/index

Contents:

.. toctree::
:maxdepth: 2


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

25 changes: 25 additions & 0 deletions tests/python/test_pyintegration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,3 +1180,28 @@ def test_line_number_order(self, parse):
method_sphinx_docs = example_file.find(id="example.Foo.method_sphinx_docs")

assert method_tricky.sourceline < method_sphinx_docs.sourceline


class TestPy3ModuleExample:
@pytest.fixture(autouse=True, scope="class")
def built(self, builder):
builder("py3moduleexample")

def test_integration(self, parse):
example_file = parse("_build/html/autoapi/example/index.html")

assert "Initialize self" not in example_file
assert "a new type" not in example_file

def test_files_are_populated_correctly(self, parse):
# Assert modules/packages are documented
assert pathlib.Path("_build/html/autoapi/example/index.html").exists()
assert pathlib.Path("_build/html/autoapi/example2/index.html").exists()
assert pathlib.Path("_build/html/autoapi/example3/index.html").exists()
assert pathlib.Path("_build/html/autoapi/example3/example3/index.html").exists()

# Assert private modules/packages aren't shown
assert not pathlib.Path(
"_build/html/autoapi/_subpackage/_hidden/index.html"
).exists()
assert not pathlib.Path("_build/html/autoapi/_hidden/index.html").exists()