Skip to content

Commit 533f0dc

Browse files
committed
DSS_EXTENSIONS_DEBUG: Implement support for loading the debug version of the library. A new CFFI module is built for it.
1 parent dbb6c82 commit 533f0dc

5 files changed

Lines changed: 17 additions & 10 deletions

File tree

dss/_cffi_api_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def CheckForError(self, result=None):
7878
if self._errorPtr[0]:
7979
error_num = self._errorPtr[0]
8080
self._errorPtr[0] = 0
81-
raise DssException(error_num, self._get_string(self._lib.Error_Get_Description()))
81+
raise DSSException(error_num, self._get_string(self._lib.Error_Get_Description()))
8282

8383
return result
8484

dss/v7.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,14 @@
33
'''
44

55
from __future__ import absolute_import
6-
from ._dss_capi_v7 import ffi, lib
6+
import os
7+
if os.environ.get('DSS_EXTENSIONS_DEBUG', '') != '1':
8+
from ._dss_capi_v7 import ffi, lib
9+
else:
10+
import warnings
11+
warnings.warn('Environment variable DSS_EXTENSIONS_DEBUG=1 is set, loading the debug version of DSS C-API')
12+
from ._dss_capi_v7d import ffi, lib
13+
714
from ._cffi_api_util import CffiApiUtil, use_com_compat, DssException
815
from . import dss_capi_gr, dss_capi_ir, enums
916
from .enums import *

dss/v8.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
'''
2-
This module used to present an instance for the OpenDSS Version 8 implementation. It was based on the official parallel-machine version, which allow creating multiple solvers (actors) in a single process. The mechanism is being reword in DSS C-API, the library used by DSS_Python to implement OpenDSS, to reproduce a stable version in the future.
3-
'''
41
from __future__ import absolute_import
52
from .v7 import *
63
import warnings

dss_build.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,12 @@ def process_header(src, extern_py=False, implement_py=False, prefix=''):
7474
src_path = os.environ.get('SRC_DIR', '')
7575
DSS_CAPI_PATH = os.environ.get('DSS_CAPI_PATH', os.path.join(src_path, '..', 'dss_capi'))
7676

77-
for version in DSS_VERSIONS:
77+
for version in DSS_VERSIONS:
7878
ffi_builder_dss = FFI()
7979

80-
with open(os.path.join(DSS_CAPI_PATH, 'include', version, 'dss_capi.h'), 'r') as f:
80+
base_version = version.rstrip('d')
81+
82+
with open(os.path.join(DSS_CAPI_PATH, 'include', base_version, 'dss_capi.h'), 'r') as f:
8183
cffi_header_dss = process_header(f.read())
8284

8385
with open('cffi/dss_capi_custom.h', 'r') as f:
@@ -93,10 +95,10 @@ def process_header(src, extern_py=False, implement_py=False, prefix=''):
9395
ffi_builder_dss.set_source("_dss_capi_{}".format(version), extra_source_dss,
9496
libraries=["dss_capi_{}".format(version)],
9597
library_dirs=[
96-
os.path.join(DSS_CAPI_PATH, 'lib/{}/{}'.format(PLATFORM_FOLDER, version)),
98+
os.path.join(DSS_CAPI_PATH, 'lib/{}/{}'.format(PLATFORM_FOLDER, base_version)),
9799
os.path.join(DSS_CAPI_PATH, 'lib/{}'.format(PLATFORM_FOLDER))
98100
],
99-
include_dirs=[os.path.join(DSS_CAPI_PATH, 'include/{}'.format(version))],
101+
include_dirs=[os.path.join(DSS_CAPI_PATH, 'include/{}'.format(base_version))],
100102
source_extension='.c',
101103
**extra
102104
)
@@ -143,6 +145,7 @@ def process_header(src, extern_py=False, implement_py=False, prefix=''):
143145
# Is there a better way to do this? Unfortunately setup(cffi_modules=...)
144146
# needs a list of strings and cannot handle objects directly
145147
ffi_builder_v7 = ffi_builders['v7']
148+
ffi_builder_v7d = ffi_builders['v7d']
146149
# ffi_builder_v8 = ffi_builders['v8']
147150
ffi_builder_GenUserModel = ffi_builders['GenUserModel']
148151
ffi_builder_PVSystemUserModel = ffi_builders['PVSystemUserModel']

dss_setup_common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
platform_short = ''.join(filter(lambda ch: ch.isalpha(), sys.platform))
66
PLATFORM_FOLDER = '{}_{}'.format(platform_short, arch)
77

8-
DSS_VERSIONS = ('v7', )
8+
DSS_VERSIONS = ('v7', 'v7d')
99

1010
if sys.platform == 'win32':
1111
DLL_SUFFIX = '.dll'

0 commit comments

Comments
 (0)