Skip to content

Commit

Permalink
[doc][api] add a function to check if an api has a private name
Browse files Browse the repository at this point in the history
Signed-off-by: can <[email protected]>
  • Loading branch information
can-anyscale committed Jun 25, 2024
1 parent 50926ac commit 5379d75
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ci/ray_ci/doc/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,3 +118,20 @@ def get_canonical_name(self) -> str:
attribute = getattr(attribute, token)

return f"{attribute.__module__}.{attribute.__qualname__}"

def _is_private_name(self) -> bool:
"""
Check if this API has a private name. Private names are those that start with
underscores.
"""
return self.name.split(".")[-1].startswith("_")

def is_public(self) -> bool:
"""
Check if this API is public. Public APIs are those that are annotated as public
and not have private names.
"""
return (
self.annotation_type == AnnotationType.PUBLIC_API
and not self._is_private_name()
)
40 changes: 40 additions & 0 deletions ci/ray_ci/doc/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,45 @@ def test_get_canonical_name():
)


def test_is_private_name():
test_data = [
{
"input": "a.b._private_function",
"output": True,
},
{
"input": "b.c.public_class",
"output": False,
},
]
for test in test_data:
assert (
API(
name=test["input"],
annotation_type=AnnotationType.UNKNOWN,
code_type=CodeType.FUNCTION,
)._is_private_name()
== test["output"]
)


def test_is_public():
assert not API(
name="a.b._private_function",
annotation_type=AnnotationType.PUBLIC_API,
code_type=CodeType.FUNCTION,
).is_public()
assert not API(
name="a.b.public_function",
annotation_type=AnnotationType.DEPRECATED,
code_type=CodeType.FUNCTION,
).is_public()
assert API(
name="a.b.public_function",
annotation_type=AnnotationType.PUBLIC_API,
code_type=CodeType.FUNCTION,
).is_public()


if __name__ == "__main__":
sys.exit(pytest.main(["-v", __file__]))

0 comments on commit 5379d75

Please sign in to comment.