Skip to content

Commit

Permalink
setting up pyproject and runtime redirections apropriately
Browse files Browse the repository at this point in the history
  • Loading branch information
teh-cmc committed Jun 12, 2023
1 parent 20486ca commit d3894a7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion rerun_py/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ required-imports = ["from __future__ import annotations"]
# See https://github.com/rerun-io/rerun/pull/1085 for more details
include = ["rerun_sdk.pth", "rerun_sdk/rerun_demo/colmap_fiat.rrd"]
locked = true
python-packages = ["rerun_sdk/rerun", "rerun_sdk/rerun_demo"]
python-packages = [
"rerun_sdk/rerun",
"rerun_sdk/rerun2",
"rerun_sdk/rerun_demo",
]
26 changes: 26 additions & 0 deletions rerun_py/rerun2/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"""
A shim necessary to make maturin dev builds work properly.
Our maturin builds stick our package inside of a "rerun_sdk" folder
to avoid conflicting with the non-rerun "rerun" package. In released
builds, we include a rerun_sdk.pth file that makes things work properly,
but that doesn't work in dev builds where maturin generates its own
.pth file that points 1 level too high.
When we encounter this file on import, we instead redirect to the
real rerun module by adding it to the path and then, and then
replacing our own module content with it.
"""
from __future__ import annotations

import pathlib
import sys

real_path = pathlib.Path(__file__).parent.parent.joinpath("rerun_sdk").resolve()

print(f"DEV ENVIRONMENT DETECTED! Re-importing rerun2 from: {real_path}", file=sys.stderr)

sys.path.insert(0, str(real_path))

del sys.modules["rerun2"]
sys.modules["rerun2"] = __import__("rerun2")

0 comments on commit d3894a7

Please sign in to comment.