Skip to content

Commit 01884b3

Browse files
committed
Load and importlib
1 parent 2b4f213 commit 01884b3

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

src/torchcodec/decoders/_core/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,6 @@ function(make_torchcodec_libraries
9797
"${decoder_library_name}"
9898
"${ffmpeg_include_dirs}"
9999
)
100-
target_compile_definitions(
101-
${pybind_ops_library_name}
102-
PUBLIC
103-
TORCHCODEC_PYBIND=_torchcodec_pybind_ops${ffmpeg_major_version}
104-
)
105100
# pybind11 quirk, see:
106101
# https://pybind11.readthedocs.io/en/stable/faq.html#someclass-declared-with-greater-visibility-than-the-type-of-its-field-someclass-member-wattributes
107102
target_compile_options(

src/torchcodec/decoders/_core/PyBindOps.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,7 @@ int64_t create_from_file_like(
3737
return reinterpret_cast<int64_t>(decoder);
3838
}
3939

40-
#ifndef TORCHCODEC_PYBIND
41-
#error TORCHCODEC_PYBIND must be defined.
42-
#endif
43-
44-
PYBIND11_MODULE(TORCHCODEC_PYBIND, m) {
40+
PYBIND11_MODULE(_torchcodec_pybind_ops, m) {
4541
m.def("create_from_file_like", &create_from_file_like);
4642
}
4743

src/torchcodec/decoders/_core/ops.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,18 @@ def load_torchcodec_extension():
3535
decoder_library_name = f"libtorchcodec_decoder{ffmpeg_major_version}"
3636
custom_ops_library_name = f"libtorchcodec_custom_ops{ffmpeg_major_version}"
3737
pybind_ops_library_name = f"libtorchcodec_pybind_ops{ffmpeg_major_version}"
38-
pybind_ops_module_name = f"_torchcodec_pybind_ops{ffmpeg_major_version}"
38+
pybind_ops_module_name = "torchcodec._torchcodec_pybind_ops"
3939
try:
4040
torch.ops.load_library(_get_extension_path(decoder_library_name))
4141
torch.ops.load_library(_get_extension_path(custom_ops_library_name))
42+
torch.ops.load_library(_get_extension_path(pybind_ops_library_name))
4243

4344
spec = importlib.util.spec_from_file_location(
4445
pybind_ops_module_name,
4546
_get_extension_path(pybind_ops_library_name),
4647
)
4748
if spec is None:
48-
raise ImportError(f"Unable to load spec for pybind_ops {_get_extension_path(pybind_ops_library_name)}")
49+
raise ImportError(f"Unable to load spec for pybind_ops")
4950

5051
global _pybind_ops
5152
_pybind_ops = importlib.util.module_from_spec(spec)

0 commit comments

Comments
 (0)