Skip to content

Commit 652817d

Browse files
committed
Add new oddie submodule
1 parent fb7a331 commit 652817d

2 files changed

Lines changed: 43 additions & 5 deletions

File tree

dss_python_backend/__init__.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,14 @@
1515

1616
if os.environ.get('DSS_EXTENSIONS_DEBUG', '') != '1':
1717
altdss_lib_path = altdss_lib_parent_path.joinpath('libaltdss_capi.so')
18-
pass
1918
else:
2019
import warnings
2120
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the DSS C-API library')
2221
altdss_lib_path = altdss_lib_parent_path.joinpath('libaltdss_capid.so')
23-
pass
24-
2522

2623
if not altdss_lib_path.exists():
2724
raise RuntimeError('AltDSS library not found!')
2825

29-
3026
# Basic initialization -- load the library and prepare the structures
3127
lib = _altdss_capi_loader.ffi.new('AltDSSCAPI*')
3228

@@ -44,7 +40,7 @@
4440
if _init_result != 1:
4541
raise RuntimeError(f'AltDSS library found but could not be loaded (code {_init_result})!')
4642

47-
# Ensure this is called at least once. This was moved from
43+
# For AltDSS, ensure this is called at least once. This was moved from
4844
# CffiApiUtil so we call it as soon as the DLL/so is loaded.
4945
lib.DSS_Start(ffi.NULL, 0)
5046

dss_python_backend/oddie.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'''
2+
This file provides access to the Oddie library.
3+
Note that it does not initialize the OpenDSS or OpenDSS-C libraries, that is a
4+
second step. The same Oddie instance can be used to load multiple engine libraries.
5+
'''
6+
import os
7+
from . import _altdss_capi_loader
8+
from ._altdss_capi_loader import ffi, lib as loader_lib
9+
from pathlib import Path
10+
11+
altdss_lib_parent_path = Path(_altdss_capi_loader.__file__).absolute().parent
12+
13+
if os.environ.get('DSS_EXTENSIONS_DEBUG', '') != '1':
14+
oddie_lib_path = altdss_lib_parent_path.joinpath('libaltdss_oddie_capi.so')
15+
else:
16+
import warnings
17+
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set: loading the debug version of the AltDSS Oddie library')
18+
oddie_lib_path = altdss_lib_parent_path.joinpath('libaltdss_oddie_capid.so')
19+
20+
if not oddie_lib_path.exists():
21+
print(oddie_lib_path)
22+
raise RuntimeError('Oddie library not found!')
23+
24+
# Basic initialization -- load the library and prepare the structures
25+
lib = _altdss_capi_loader.ffi.new('AltDSSCAPI*')
26+
27+
_init_result = loader_lib.AltDSSCAPILibInit(
28+
str(oddie_lib_path).encode(),
29+
ffi.NULL,
30+
b"AltDSSOddieCAPIInit",
31+
lib,
32+
ffi.sizeof(lib[0]),
33+
0,
34+
0,
35+
ffi.NULL
36+
)
37+
38+
if _init_result != 1:
39+
raise RuntimeError(f'Oddie library found but could not be loaded (code {_init_result})!')
40+
41+
# Compared to the main "lib" in __init__.py, we will not call DSS_Start yet
42+
# since the actual engine is not loaded.

0 commit comments

Comments
 (0)