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

tag unstable functionality #404

Merged
merged 7 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ module zenoh
:undoc-members:

module zenoh.handlers
============
=====================

.. automodule:: zenoh.handlers
:members:
Expand Down
20 changes: 18 additions & 2 deletions docs/stubs_to_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,23 @@
referencing a type not declared yet (i.e. forward reference)."""

import ast
import inspect
from collections import defaultdict
from pathlib import Path

PACKAGE = (Path(__file__) / "../../zenoh").resolve()
__INIT__ = PACKAGE / "__init__.py"


def _unstable(item):
warning = ".. warning:: This API has been marked as unstable: it works as advertised, but it may be changed in a future release."
if item.__doc__:
item.__doc__ += "\n" + warning
else:
item.__doc__ = warning
return item


class RemoveOverload(ast.NodeTransformer):
def __init__(self):
self.current_cls = None
Expand Down Expand Up @@ -95,10 +105,16 @@ def main():
entry.rename(PACKAGE / f"{entry.stem}.py")
# read stub code
with open(__INIT__) as f:
stub = ast.parse(f.read())
stub: ast.Module = ast.parse(f.read())
# replace _unstable
for i, stmt in enumerate(stub.body):
if isinstance(stmt, ast.FunctionDef) and stmt.name == "_unstable":
stub.body[i] = ast.parse(inspect.getsource(_unstable))
# remove overload
stub = RemoveOverload().visit(stub)
# write modified code
with open(__INIT__, "w") as f:
f.write(ast.unparse(RemoveOverload().visit(stub)))
f.write(ast.unparse(stub))


if __name__ == "__main__":
Expand Down
4 changes: 4 additions & 0 deletions zenoh/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@
from . import ext
except ImportError:
pass


def _unstable(item):
DenisBiryukov91 marked this conversation as resolved.
Show resolved Hide resolved
return item
11 changes: 10 additions & 1 deletion zenoh/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ _RustHandler = (
_PythonCallback = Callable[[_T], Any]
_PythonHandler = tuple[_PythonCallback[_T], _H]

def _unstable(item: _T) -> _T:
"""marker for unstable functionality"""

@final
class ZError(Exception): ...

Expand Down Expand Up @@ -349,6 +352,7 @@ class KeyExpr:
_IntoKeyExpr = KeyExpr | str

@final
@_unstable
DenisBiryukov91 marked this conversation as resolved.
Show resolved Hide resolved
class Liveliness:
def declare_token(self, key_expr: _IntoKeyExpr) -> LivelinessToken:
"""Create a LivelinessToken for the given key expression."""
Expand Down Expand Up @@ -414,6 +418,7 @@ class Liveliness:
"""Create a Subscriber for liveliness changes matching the given key expression."""

@final
@_unstable
class LivelinessToken:
def __enter__(self) -> Self: ...
def __exit__(self, *_args, **_kwargs): ...
Expand Down Expand Up @@ -484,6 +489,7 @@ class Publisher:
@property
def priority(self) -> Priority: ...
@property
@_unstable
def reliability(self) -> Reliability: ...
def put(
self,
Expand Down Expand Up @@ -574,8 +580,9 @@ class Queryable(Generic[_H]):
def __iter__(self) -> Never: ...

@final
@_unstable
class Querier:
"""A querier that allows to send queries to a queryable..
"""A querier that allows to send queries to a queryable.
Queriers are automatically undeclared when dropped."""

def __enter__(self) -> Self: ...
Expand Down Expand Up @@ -642,6 +649,7 @@ class QueryTarget(Enum):
DEFAULT = BEST_MATCHING

@final
@_unstable
class Reliability(Enum):
BEST_EFFORT = auto()
RELIABLE = auto()
Expand Down Expand Up @@ -944,6 +952,7 @@ class Session:
) -> Publisher:
"""Create a Publisher for the given key expression."""

@_unstable
def declare_querier(
self,
key_expr: _IntoKeyExpr,
Expand Down
Loading