Skip to content

Commit ef8f5b7

Browse files
committed
Installation config; #204, #162, #163, #184, #180
1 parent 11f2a60 commit ef8f5b7

36 files changed

+841
-281
lines changed

python/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ project(
1313
# Define build options
1414
find_package(PythonExtensions REQUIRED)
1515
find_package(Cython REQUIRED)
16+
find_package(Python3 REQUIRED COMPONENTS Interpreter Development)
1617

1718
# Append local dir to module search path
1819
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)

python/MANIFEST.in

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
include LICENSE
2+
include README.md
3+
recursive-include *.py
4+
recursive-include docs *.rst
5+
recursive-include tests *.csv
6+
global-exclude *.pyc

python/epaswmm/CMakeLists.txt

+5-8
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,20 @@
22
# Created by: Caleb Buahin (EPA/ORD/CESER/WID)
33
# Created on: 2024-11-19
44

5-
# Find Python extensions
6-
find_package(PythonExtensions REQUIRED)
7-
85
# Add Cython targets for epaswmm
9-
add_cython_target(epaswmm epaswmm.pyx CXX PY3)
6+
add_cython_target(_epaswmm _epaswmm.pyx CXX PY3)
107

118
# Create Python extension modules
12-
add_library(epaswmm MODULE ${epaswmm})
9+
add_library(_epaswmm MODULE ${_epaswmm})
1310

14-
python_extension_module(epaswmm)
11+
python_extension_module(_epaswmm)
1512

1613
# Install the epaswmm module
17-
install(TARGETS epaswmm LIBRARY DESTINATION epaswmm)
14+
install(TARGETS _epaswmm LIBRARY DESTINATION epaswmm)
1815

1916
# Include the current source directory
2017
target_include_directories(
21-
epaswmm PRIVATE
18+
_epaswmm PRIVATE
2219
${CMAKE_CURRENT_SOURCE_DIR}
2320
)
2421

python/epaswmm/__init__.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,4 @@
1919
else:
2020
os.environ["PATH"] = lib_dir + ";" + os.environ["PATH"]
2121

22-
from .epaswmm import *
23-
from . import solver
24-
from . import output
22+
from epaswmm import *
File renamed without changes.

python/epaswmm/_epaswmm.pyx

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
2+
# Description: Cython module for encoding and decoding SWMM datetimes
3+
# Created by: Caleb Buahin (EPA/ORD/CESER/WID)
4+
# Created on: 2024-11-19
5+
6+
# cython: language_level=3
7+
8+
9+
# python imports
10+
11+
# third-party imports
12+
13+
# project imports
14+
from epaswmm cimport epaswmm
15+

python/epaswmm/epaswmm.pxd

-7
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,7 @@
44

55
# cython: language_level=3
66
# python imports
7-
from cpython.datetime cimport datetime
87

98
# third-party imports
109

1110
# project imports
12-
13-
# Define the number of days since 01/01/00
14-
cpdef double encode_swmm_datetime(datetime pdatetime)
15-
16-
# Define the number of days since 01/01/00
17-
cpdef datetime decode_swmm_datetime(double swmm_datetime)

python/epaswmm/epaswmm.pyx

-157
This file was deleted.

python/epaswmm/output/CMakeLists.txt

+6-10
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,23 @@
33
# Created by: Caleb Buahin (EPA/ORD/CESER/WID)
44
# Created on: 2024-11-19
55

6-
# Find Python
7-
find_package(Python3 REQUIRED COMPONENTS Development)
8-
find_package(PythonExtensions REQUIRED)
9-
10-
add_cython_target(output output.pyx LANGUAGE CXX PY3)
6+
add_cython_target(_output _output.pyx LANGUAGE CXX PY3)
117

128
# Add Cython target
13-
add_library(output MODULE ${output})
9+
add_library(_output MODULE ${_output})
1410

1511
# Add library
16-
target_link_libraries(output swmm-output)
12+
target_link_libraries(_output swmm-output)
1713

1814
# Specify that this is a Python extension module
19-
python_extension_module(output)
15+
python_extension_module(_output)
2016

2117
# Install the target
22-
install(TARGETS output LIBRARY DESTINATION epaswmm/output)
18+
install(TARGETS _output LIBRARY DESTINATION epaswmm/output)
2319

2420
# Include directories
2521
target_include_directories(
26-
output PRIVATE
22+
_output PUBLIC
2723
${CMAKE_CURRENT_SOURCE_DIR}
2824
$<TARGET_PROPERTY:swmm-output,INCLUDE_DIRECTORIES>
2925
)

python/epaswmm/output/__init__.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .output cimport *

python/epaswmm/output/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from .output import (
1+
from ._output import (
22
UnitSystem,
33
FlowUnits,
44
ConcentrationUnits,
File renamed without changes.

python/epaswmm/output/output.pyx python/epaswmm/output/_output.pyx

+9-5
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ from libc.stdlib cimport free, malloc
1313
# external imports
1414

1515
# local python and cython imports
16-
cimport epaswmm.epaswmm as cepaswmm
17-
cimport epaswmm.output.output as coutput
16+
from ..solver import (
17+
decode_swmm_datetime,
18+
)
1819

19-
from epaswmm.output.output cimport (
20+
from .output cimport (
2021
SMO_unitSystem,
2122
SMO_flowUnits,
2223
SMO_concUnits,
@@ -26,6 +27,9 @@ from epaswmm.output.output cimport (
2627
SMO_nodeAttribute,
2728
SMO_linkAttribute,
2829
SMO_systemAttribute,
30+
SMO_Handle,
31+
MAXFILENAME,
32+
MAXELENAME,
2933
SMO_init,
3034
SMO_open,
3135
SMO_close,
@@ -302,7 +306,7 @@ cdef class Output:
302306
:cvar _num_periods: Number of reporting periods.
303307
:cvar _times: Times of the simulation in the SWMM output file.
304308
"""
305-
cdef coutput.SMO_Handle _output_file_handle
309+
cdef SMO_Handle _output_file_handle
306310
cdef int _version
307311
cdef int* _units
308312
cdef int _units_length
@@ -568,7 +572,7 @@ cdef class Output:
568572
error_code = SMO_getStartDate(self._output_file_handle, &swmm_datetime)
569573
self.__validate_error_code(error_code)
570574

571-
return cepaswmm.decode_swmm_datetime(swmm_datetime)
575+
return decode_swmm_datetime(swmm_datetime)
572576

573577
@property
574578
def times(self) -> List[datetime]:

python/epaswmm/solver/CMakeLists.txt

+6-12
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,24 @@
44
# Created on: 2024-11-19
55
#
66

7-
# Find Python
8-
find_package(Python3 REQUIRED COMPONENTS Development)
9-
10-
# Find Python extensions
11-
find_package(PythonExtensions REQUIRED)
12-
137
# Add Cython target
14-
add_cython_target(solver solver.pyx CXX PY3)
8+
add_cython_target(_solver _solver.pyx CXX PY3)
159

1610
# Add library
17-
add_library(solver MODULE ${solver})
11+
add_library(_solver MODULE ${_solver})
1812

1913
# Link to SWMM and Python libraries
20-
target_link_libraries(solver swmm5 Python3::Python)
14+
target_link_libraries(_solver swmm5 Python3::Python)
2115

2216
# Specify that this is a Python extension module
23-
python_extension_module(solver)
17+
python_extension_module(_solver)
2418

2519
# Install the target
26-
install(TARGETS solver LIBRARY DESTINATION epaswmm/solver)
20+
install(TARGETS _solver LIBRARY DESTINATION epaswmm/solver)
2721

2822
# Include directories
2923
target_include_directories(
30-
solver PUBLIC
24+
_solver PUBLIC
3125
${CMAKE_CURRENT_SOURCE_DIR}
3226
$<TARGET_PROPERTY:swmm5,INCLUDE_DIRECTORIES>
3327
${Python3_INCLUDE_DIRS}

python/epaswmm/solver/__init__.pxd

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .solver cimport *

python/epaswmm/solver/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Created by: Caleb Buahin (EPA/ORD/CESER/WID)
33
# Created on: 2024-11-19
44

5-
from .solver import (
5+
from ._solver import (
66
SWMMObjects,
77
SWMMNodeTypes,
88
SWMMRainGageProperties,

python/epaswmm/solver/solver.pyi python/epaswmm/solver/_solver.pyi

+10
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,16 @@ class Solver:
575575
"""
576576
A class to represent a SWMM solver.
577577
"""
578+
def __init__(self, inp_file: str, rpt_file: str = ..., out_file: str = ...) -> None:
579+
"""
580+
Constructor to initialize the solver.
581+
582+
:param inp_file: Input file name
583+
:param rpt_file: Report file name
584+
:param out_file: Output file name
585+
"""
586+
...
587+
578588
def __enter__(self): # -> Self@Solver:
579589
"""
580590
Enter method for context manager.

0 commit comments

Comments
 (0)