Skip to content

Commit

Permalink
Improve visibility of Python public APIs to type checkers (rerun-io#6462
Browse files Browse the repository at this point in the history
)

### What

- Closes rerun-io#6459 

rerun-io#6117 removed many `__all__` statements, which cause problem for type
checkers when using our public APIs (`rr.*` and `rr.blueprint.*`). This
PR fixes this by using the `from X import Y as Y` pattern, which is
easier to maintain than `__all__`.

This required a ruff setting change, which rippled into additional
(arguably good) formatting changes.

### Checklist
* [x] I have read and agree to [Contributor
Guide](https://github.com/rerun-io/rerun/blob/main/CONTRIBUTING.md) and
the [Code of
Conduct](https://github.com/rerun-io/rerun/blob/main/CODE_OF_CONDUCT.md)
* [x] I've included a screenshot or gif (if applicable)
* [x] I have tested the web demo (if applicable):
* Using examples from latest `main` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6462?manifest_url=https://app.rerun.io/version/main/examples_manifest.json)
* Using full set of examples from `nightly` build:
[rerun.io/viewer](https://rerun.io/viewer/pr/6462?manifest_url=https://app.rerun.io/version/nightly/examples_manifest.json)
* [x] The PR title and labels are set such as to maximize their
usefulness for the next release's CHANGELOG
* [x] If applicable, add a new check to the [release
checklist](https://github.com/rerun-io/rerun/blob/main/tests/python/release_checklist)!

- [PR Build Summary](https://build.rerun.io/pr/6462)
- [Recent benchmark results](https://build.rerun.io/graphs/crates.html)
- [Wasm size tracking](https://build.rerun.io/graphs/sizes.html)

To run all checks from `main`, comment on the PR with `@rerun-bot
full-check`.
  • Loading branch information
abey79 authored May 31, 2024
1 parent ea4fc10 commit 1211f6d
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 155 deletions.
1 change: 1 addition & 0 deletions rerun_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ lint.unfixable = [

[tool.ruff.lint.isort]
required-imports = ["from __future__ import annotations"]
combine-as-imports = true # needed so keep rerun_sdk/__init__.py clean

[tool.maturin]
# We use a python package from inside the rerun_sdk folder to avoid conflicting
Expand Down
204 changes: 118 additions & 86 deletions rerun_py/rerun_sdk/rerun/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,106 +9,139 @@

# =====================================
# API RE-EXPORTS
# Important: always us the `import _ as _` format to make it explicit to type-checkers that these are public APIs.
# Background: https://github.com/microsoft/pyright/blob/1.1.365/docs/typed-libraries.md#library-interface
#
import rerun_bindings as bindings # type: ignore[attr-defined]

from ._image import ImageEncoded, ImageFormat
from . import (
blueprint as blueprint,
experimental as experimental,
)
from ._image import (
ImageEncoded as ImageEncoded,
ImageFormat as ImageFormat,
)
from ._log import (
AsComponents,
ComponentBatchLike,
IndicatorComponentBatch,
escape_entity_path_part,
log,
log_components,
log_file_from_contents,
log_file_from_path,
new_entity_path,
AsComponents as AsComponents,
ComponentBatchLike as ComponentBatchLike,
IndicatorComponentBatch as IndicatorComponentBatch,
escape_entity_path_part as escape_entity_path_part,
log as log,
log_components as log_components,
log_file_from_contents as log_file_from_contents,
log_file_from_path as log_file_from_path,
new_entity_path as new_entity_path,
)
from .any_value import (
AnyValues as AnyValues,
)
from .any_value import AnyValues
from .archetypes import (
AnnotationContext,
Arrows2D,
Arrows3D,
Asset3D,
BarChart,
Boxes2D,
Boxes3D,
Clear,
DepthImage,
DisconnectedSpace,
Image,
LineStrips2D,
LineStrips3D,
Mesh3D,
Pinhole,
Points2D,
Points3D,
Scalar,
SegmentationImage,
SeriesLine,
SeriesPoint,
Tensor,
TextDocument,
TextLog,
Transform3D,
ViewCoordinates,
AnnotationContext as AnnotationContext,
Arrows2D as Arrows2D,
Arrows3D as Arrows3D,
Asset3D as Asset3D,
BarChart as BarChart,
Boxes2D as Boxes2D,
Boxes3D as Boxes3D,
Clear as Clear,
DepthImage as DepthImage,
DisconnectedSpace as DisconnectedSpace,
Image as Image,
LineStrips2D as LineStrips2D,
LineStrips3D as LineStrips3D,
Mesh3D as Mesh3D,
Pinhole as Pinhole,
Points2D as Points2D,
Points3D as Points3D,
Scalar as Scalar,
SegmentationImage as SegmentationImage,
SeriesLine as SeriesLine,
SeriesPoint as SeriesPoint,
Tensor as Tensor,
TextDocument as TextDocument,
TextLog as TextLog,
Transform3D as Transform3D,
ViewCoordinates as ViewCoordinates,
)
from .archetypes.boxes2d_ext import (
Box2DFormat as Box2DFormat,
)
from .blueprint.api import (
BlueprintLike as BlueprintLike,
)
from .archetypes.boxes2d_ext import Box2DFormat
from .blueprint.api import BlueprintLike
from .components import (
Material,
MediaType,
OutOfTreeTransform3D,
OutOfTreeTransform3DBatch,
TextLogLevel,
Material as Material,
MediaType as MediaType,
OutOfTreeTransform3D as OutOfTreeTransform3D,
OutOfTreeTransform3DBatch as OutOfTreeTransform3DBatch,
TextLogLevel as TextLogLevel,
)
from .datatypes import (
AnnotationInfo,
ClassDescription,
Quaternion,
RotationAxisAngle,
Scale3D,
TensorData,
TimeInt,
TimeRange,
TimeRangeBoundary,
TranslationAndMat3x3,
TranslationRotationScale3D,
VisibleTimeRange,
AnnotationInfo as AnnotationInfo,
ClassDescription as ClassDescription,
Quaternion as Quaternion,
RotationAxisAngle as RotationAxisAngle,
Scale3D as Scale3D,
TensorData as TensorData,
TimeInt as TimeInt,
TimeRange as TimeRange,
TimeRangeBoundary as TimeRangeBoundary,
TranslationAndMat3x3 as TranslationAndMat3x3,
TranslationRotationScale3D as TranslationRotationScale3D,
VisibleTimeRange as VisibleTimeRange,
)
from .error_utils import (
set_strict_mode as set_strict_mode,
)
from .logging_handler import (
LoggingHandler as LoggingHandler,
)
from .memory import (
MemoryRecording as MemoryRecording,
memory_recording as memory_recording,
)
from .notebook import (
notebook_show as notebook_show,
)
from .error_utils import set_strict_mode
from .logging_handler import LoggingHandler
from .memory import MemoryRecording, memory_recording
from .notebook import notebook_show
from .recording_stream import (
BinaryStream,
RecordingStream,
binary_stream,
get_application_id,
get_data_recording,
get_global_data_recording,
get_recording_id,
get_thread_local_data_recording,
is_enabled,
new_recording,
recording_stream_generator_ctx,
set_global_data_recording,
set_thread_local_data_recording,
thread_local_stream,
BinaryStream as BinaryStream,
RecordingStream as RecordingStream,
binary_stream as binary_stream,
get_application_id as get_application_id,
get_data_recording as get_data_recording,
get_global_data_recording as get_global_data_recording,
get_recording_id as get_recording_id,
get_thread_local_data_recording as get_thread_local_data_recording,
is_enabled as is_enabled,
new_recording as new_recording,
recording_stream_generator_ctx as recording_stream_generator_ctx,
set_global_data_recording as set_global_data_recording,
set_thread_local_data_recording as set_thread_local_data_recording,
thread_local_stream as thread_local_stream,
)
from .script_helpers import (
script_add_args as script_add_args,
script_setup as script_setup,
script_teardown as script_teardown,
)
from .sinks import (
connect as connect,
disconnect as disconnect,
save as save,
send_blueprint as send_blueprint,
serve as serve,
spawn as spawn,
stdout as stdout,
)
from .script_helpers import script_add_args, script_setup, script_teardown
from .sinks import connect, disconnect, save, send_blueprint, serve, spawn, stdout
from .time import (
disable_timeline,
reset_time,
set_time_nanos,
set_time_seconds,
set_time_sequence,
disable_timeline as disable_timeline,
reset_time as reset_time,
set_time_nanos as set_time_nanos,
set_time_seconds as set_time_seconds,
set_time_sequence as set_time_sequence,
)

# Import experimental last
from . import experimental # isort: skip
from . import blueprint

# =====================================
# UTILITIES

Expand Down Expand Up @@ -321,7 +354,6 @@ def _register_on_fork() -> None:

_register_on_fork()


_TFunc = TypeVar("_TFunc", bound=Callable[..., Any])


Expand Down
77 changes: 44 additions & 33 deletions rerun_py/rerun_sdk/rerun/blueprint/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/views/spatial2d_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/views/spatial3d_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions rerun_py/rerun_sdk/rerun/blueprint/views/time_series_view.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 0 additions & 8 deletions rerun_py/tests/unit/test_box2d.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,9 @@
labels_expected,
radii_arrays,
radii_expected,
)
from .common_arrays import (
vec2ds_arrays as centers_arrays,
)
from .common_arrays import (
vec2ds_arrays as half_sizes_arrays,
)
from .common_arrays import (
vec2ds_expected as centers_expected,
)
from .common_arrays import (
vec2ds_expected as half_sizes_expected,
)

Expand Down
8 changes: 0 additions & 8 deletions rerun_py/tests/unit/test_box3d.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,9 @@
radii_arrays,
radii_expected,
rotations_arrays,
)
from .common_arrays import (
vec3ds_arrays as centers_arrays,
)
from .common_arrays import (
vec3ds_arrays as half_sizes_arrays,
)
from .common_arrays import (
vec3ds_expected as centers_expected,
)
from .common_arrays import (
vec3ds_expected as half_sizes_expected,
)

Expand Down
Loading

0 comments on commit 1211f6d

Please sign in to comment.