-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrust.py
More file actions
28 lines (26 loc) · 1023 Bytes
/
rust.py
File metadata and controls
28 lines (26 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from djc_core import djc_core
# API that was exposed from the Rust `djc-core` crate.
#
# For some reason, when running pytest, trying to import from nested modules
# of the generated `djc_core` module fails:
#
# ```python
# from ..djc_core.template_parser import parse_tag
# ModuleNotFoundError: No module named 'djc_core.djc_core.template_parser'; 'djc_core.djc_core' is not a package
# ```
#
# The issue likely lies in the fact that `djc_core.template_parser` is a VIRTUAL module.
# It's not an actual file, but a submodule that exists only inside the Rust binary that
# was generated by `maturin`.
#
# To resolve this, we extract the nested modules from the Rust binary in this file.
# Then, in other files, we import from this file, and access the API of individual Rust crates
# via their namespace:
#
# ```python
# from djc_core.rust import template_parser
# template_parser.parse_tag(...)
# ```
html_transformer = djc_core.html_transformer
safe_eval = djc_core.safe_eval
template_parser = djc_core.template_parser