Skip to content

Commit c9eeeed

Browse files
committed
logging the package requirements update
1 parent 4af1cd6 commit c9eeeed

19 files changed

Lines changed: 232 additions & 50 deletions

LOGGING.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ The library can capture native DLL messages and route them through Python's logg
170170
4. Routes messages to Python logging with `[DLL]` prefix
171171
5. Cleans up the temporary file on close
172172

173+
**Requirements:** Your HEC-DSS DLL must include the `zopenLog` function for DLL
174+
output capture to work. If `zopenLog` is not available, DLL messages will go
175+
directly to the console. To suppress console output when `zopenLog` is not
176+
available, set `message_level=0` (which is the default).
177+
173178
### Enabling DLL Capture
174179

175180
```python

poetry.lock

Lines changed: 169 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "hec-dss-python"
3-
version = "0.1.25"
3+
version = "0.1.26"
44
description = "Python wrapper for the HEC-DSS file database C library."
55
authors = ["Hydrologic Engineering Center"]
66
license = "MIT"
@@ -10,6 +10,14 @@ packages = [{ include = "hecdss", from = "src" }]
1010

1111
[tool.poetry.dependencies]
1212
python = "^3.9"
13+
numpy = "^1.20.0"
14+
# tzdata is needed for zoneinfo support on Windows
15+
tzdata = { version = "*", markers = "sys_platform == 'win32'" }
16+
# Optional dependency for downloading HEC-DSS binaries
17+
requests = { version = "^2.25.0", optional = true }
18+
19+
[tool.poetry.extras]
20+
download = ["requests"]
1321

1422
[tool.poetry.dev-dependencies]
1523
# Python Syntax highlighter, assume
@@ -68,4 +76,4 @@ build-backend = "setuptools.build_meta"
6876
log_cli = true
6977
log_cli_level = 'INFO'
7078
testpaths = ["tests"]
71-
pythonpath = "./src"
79+
pythonpath = ["./src", "./tests"]

requirements.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Core dependencies for hec-dss-python
2+
numpy>=1.20.0
3+
4+
# Required for timezone support on Windows
5+
tzdata; sys_platform == 'win32'
6+
7+
# Optional: For downloading HEC-DSS binary libraries
8+
# Uncomment if you need to download the DLL/SO files:
9+
requests>=2.25.0

setup.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = hecdss
3-
version = 0.1.25
3+
version = 0.1.26
44
author = Hydrologic Engineering Center
55
author_email =hec.dss@usace.army.mil
66
description = Python wrapper for the HEC-DSS file database C library.
@@ -19,8 +19,8 @@ packages = find:
1919
python_requires = >=3.8
2020
include_package_data = True
2121
install_requires =
22-
numpy
23-
tzdata
22+
numpy>=1.20.0
23+
tzdata; sys_platform == 'win32'
2424

2525
[options.packages.find]
2626
where=src

src/hecdss/hecdss.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,21 @@
2828
class HecDss:
2929
""" Main class for working with DSS files
3030
"""
31-
def __init__(self, filename:str, enable_dll_logging:bool = False):
31+
def __init__(self, filename:str, enable_dll_logging:bool = False, message_level:int = 0):
3232
"""constructor for HecDSS
3333
3434
Args:
3535
filename (str): DSS filename to be opened; it will be created if it doesn't exist.
3636
enable_dll_logging (bool): If True, capture DLL messages to Python logging. Default False.
37+
message_level (int): DLL message level (0-15). Default 0 (silent).
3738
"""
3839

3940
self._native = _Native()
4041
self._dll_monitor = None
4142

43+
# Set DLL message level (0 = silent by default)
44+
self._native.hec_dss_set_debug_level(message_level)
45+
4246
# Setup DLL logging if requested
4347
if enable_dll_logging:
4448
self._setup_dll_logging()
@@ -75,14 +79,17 @@ def _setup_dll_logging(self):
7579
# Create temp log file
7680
log_file_path = self._dll_monitor.setup_temp_log_file()
7781

78-
# Tell DLL to use this log file
82+
# Tell DLL to use this log file (requires zopenLog function in DLL)
7983
status = self._native.hec_dss_open_log_file(log_file_path)
84+
8085
if status == 0:
81-
# Start monitoring
86+
# zopenLog worked, monitor the file
8287
self._dll_monitor.start_monitoring()
8388
logger.debug("DLL logging enabled, monitoring: %s", log_file_path)
8489
else:
85-
logger.warning("Could not enable DLL log file, messages will not be captured")
90+
# zopenLog not available, can't capture DLL output to file
91+
logger.warning("zopenLog not available in DLL, cannot capture DLL output to file")
92+
self._dll_monitor.stop_monitoring()
8693
self._dll_monitor = None
8794
@staticmethod
8895
def set_global_debug_level(level: int) -> None:

src/hecdss/logging_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def configure_logging(
205205
class DllLogMonitor:
206206
"""
207207
Monitors HEC-DSS log file and routes messages to Python logging.
208-
Uses a temporary log file approach to capture DLL output.
208+
Uses a temporary log file approach to capture DLL output when zopenLog is available.
209209
"""
210210

211211
def __init__(self, logger: logging.Logger):

src/hecdss/native.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,17 @@ def __hec_dss_set_value(self, name: str, value: int):
9191
f.restype = c_int
9292
f(name.encode("utf-8"), value)
9393

94+
def __hec_dss_set_string(self, name: str, value: str):
95+
"""Set a string parameter via zset."""
96+
try:
97+
f = self.dll.hec_dss_set_string
98+
f.argtypes = [c_char_p, c_char_p]
99+
f.restype = c_int
100+
return f(name.encode("utf-8"), value.encode("utf-8"))
101+
except AttributeError:
102+
logger.warning("hec_dss_set_string function not found in DLL")
103+
return -1
104+
94105
# set debug level (0-15)
95106
# 0 - no output
96107
# 15 - max output

tests/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44

55
import numpy as np
6-
from file_manager import FileManager
6+
from .file_manager import FileManager
77

88
from hecdss import ArrayContainer, HecDss
99

tests/test_basics.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import unittest
44
from datetime import datetime
55

6-
from file_manager import FileManager
6+
from .file_manager import FileManager
77

88
from hecdss import Catalog, HecDss
99

0 commit comments

Comments
 (0)