Skip to content

Commit 72ac94f

Browse files
authored
Merge pull request #28 from michaeltryby/dev
Reorganizes package layout and automates build
2 parents 4a97e3f + 96ebc67 commit 72ac94f

19 files changed

Lines changed: 204 additions & 110 deletions

File tree

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,14 @@ target/
6363

6464
# Testing
6565
.pytest_cache/
66-
toolkit/tests/data/test.*
66+
epanet_python/toolkit/tests/data/test.*
67+
epanet_python/toolkit/tests/data/test_reopen.inp
6768

6869
# Wrapped libraries
6970
*.h
7071
*.dll
7172
*.lib
73+
buildlib/
7274

7375
# SWIG wrappers
7476
output.py

appveyor.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
2+
3+
environment:
4+
matrix:
5+
- PYTHON: "C:\\Python36-x64"
6+
7+
install:
8+
- choco install swig
9+
- "%PYTHON%\\python.exe -m pip install wheel tox"
10+
11+
12+
build: off
13+
14+
15+
test_script:
16+
- before_build.bat %APPVEYOR_BUILD_FOLDER%
17+
- "%PYTHON%\\python.exe -m tox -v"

before_build.bat

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
::
2+
:: before_build.bat - Prepares for epanet toolkit and output module builds
3+
::
4+
:: Date Created: 12/12/2018
5+
::
6+
:: Author: Michael E. Tryby
7+
:: US EPA - ORD/NRMRL
8+
::
9+
10+
set PROJECT_PATH=%~1
11+
12+
set TOOLKIT_PATH=\epanet_python\toolkit\epanet\toolkit
13+
set OUTPUT_PATH=\epanet_python\output\epanet\output
14+
15+
16+
mkdir buildlib
17+
cd buildlib
18+
git clone --branch=dev-swig-redux https://github.com/michaeltryby/EPANET.git
19+
cd epanet
20+
21+
22+
mkdir buildprod
23+
cd buildprod
24+
cmake -G"Visual Studio 14 2015 Win64" -DBUILD_TESTS=0 ..
25+
cmake --build . --config Release
26+
27+
28+
copy /Y .\bin\Release\epanet2.dll %PROJECT_PATH%\%TOOLKIT_PATH%
29+
copy /Y .\lib\Release\epanet2.lib %PROJECT_PATH%\%TOOLKIT_PATH%
30+
copy /Y ..\include\*.h %PROJECT_PATH%\%TOOLKIT_PATH%
31+
32+
copy /Y .\bin\Release\epanet-output.dll %PROJECT_PATH%\%OUTPUT_PATH%
33+
copy /Y .\lib\Release\epanet-output.lib %PROJECT_PATH%\%OUTPUT_PATH%
34+
copy /Y ..\tools\epanet-output\include\*.h %PROJECT_PATH%\%OUTPUT_PATH%
File renamed without changes.
File renamed without changes.
Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# -*- coding: utf-8 -*-
22
#
3-
# setup.py
4-
#
3+
# setup.py
4+
#
55
# Created: 9/20/2017
66
# Author: Michael E. Tryby
77
# US EPA - ORD/NRMRL
8-
#
8+
#
99
# Setup up script for en_outputapi python extension
1010
#
1111
# Requires:
12-
# Platform C language compiler
12+
# Platform C language compiler
1313
# Python packages: numpy
1414
#
1515

@@ -20,9 +20,12 @@
2020
from distutils.core import setup, Extension
2121
from distutils.command.build_ext import build_ext
2222

23+
24+
microlib_name = 'epanet.output'
25+
2326
setup(
24-
name = "epanet_output",
25-
version = "0.1.1-alpha",
27+
name = microlib_name,
28+
version = "0.1.2a0",
2629
ext_modules = [
2730
Extension("epanet.output._output",
2831
include_dirs = ['epanet/output'],
@@ -33,11 +36,11 @@
3336
language = 'C'
3437
)
3538
],
36-
packages = {'epanet.output'},
37-
py_modules = ['output'],
38-
package_data = {'epanet.output':['*epanet-output.dll', '*epanet-output.so']},
39-
40-
install_requires = [
41-
'aenum'
42-
]
39+
namespace_packages=['epanet'],
40+
packages = {microlib_name},
41+
# py_modules = ['output'],
42+
# include_package_data=True
43+
package_data = {microlib_name:['*epanet-output.dll', '*epanet-output.so']},
44+
45+
# install_requires = []
4346
)
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,38 @@
1-
1+
import os
22

33
import pytest
44
import numpy as np
55

66
from epanet.output import OutputMetadata
77
from epanet.output import output as oapi
88

9-
from data import OUTPUT_FILE_EXAMPLE1
109

10+
DATA_PATH = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'data')
11+
OUTPUT_FILE_EXAMPLE1 = os.path.join(DATA_PATH, 'net1.out')
1112

1213

1314
@pytest.fixture()
14-
def handle(request):
15+
def handle(request):
1516
_handle = oapi.init()
1617
oapi.open(_handle, OUTPUT_FILE_EXAMPLE1)
17-
18+
1819
def close():
1920
oapi.close(_handle)
20-
21-
request.addfinalizer(close)
22-
return _handle
21+
22+
request.addfinalizer(close)
23+
return _handle
2324

2425

2526
def test_outputmetadata_handle(handle):
26-
27+
2728
om = OutputMetadata(handle)
28-
29+
2930
ref = {
3031
oapi.NodeAttribute.DEMAND: ("Demand", "gal/min"),
3132
oapi.NodeAttribute.HEAD: ("Head", "ft"),
3233
oapi.NodeAttribute.PRESSURE: ("Pressure", "psi"),
3334
oapi.NodeAttribute.QUALITY: ("Quality", "mg/L"),
34-
35+
3536
oapi.LinkAttribute.FLOW: ("Flow", "gal/min"),
3637
oapi.LinkAttribute.VELOCITY: ("Velocity", "ft/sec"),
3738
oapi.LinkAttribute.HEADLOSS: ("Unit Headloss", "ft/1000ft"),
@@ -40,18 +41,18 @@ def test_outputmetadata_handle(handle):
4041
oapi.LinkAttribute.SETTING: ("Setting", ""),
4142
oapi.LinkAttribute.RX_RATE: ("Reaction Rate", "mg/hr"),
4243
oapi.LinkAttribute.FRCTN_FCTR: ("Friction Factor", "unitless")}
43-
44+
4445
for attr in oapi.NodeAttribute:
4546
temp = om.get_attribute_metadata(attr)
4647
assert temp == ref[attr]
47-
48+
4849
for attr in oapi.LinkAttribute:
4950
temp = om.get_attribute_metadata(attr)
5051
assert temp == ref[attr]
5152

5253

5354
def test_getnodeSeries(handle):
54-
55+
5556
ref_array = np.array(
5657
[119.25731,
5758
120.45029,
@@ -63,37 +64,37 @@ def test_getnodeSeries(handle):
6364
122.90379,
6465
123.40434,
6566
123.81807])
66-
67+
6768
array = oapi.getnodeseries(handle, 2, oapi.NodeAttribute.PRESSURE, 0, 10)
6869
assert len(array) == 10
69-
70+
7071
assert np.allclose(array, ref_array)
71-
72-
72+
73+
7374
def test_getlinkseries(handle):
7475
pass
7576

7677
def test_getnodeattribute(handle):
77-
ref_array = np.array([ 1., 0.44407997, 0.43766347, 0.42827705, 0.41342604,
78+
ref_array = np.array([ 1., 0.44407997, 0.43766347, 0.42827705, 0.41342604,
7879
0.42804748, 0.44152543, 0.40502965, 0.38635802, 1., 0.96745253])
7980

8081
array = oapi.getnodeattribute(handle, 1, oapi.NodeAttribute.QUALITY)
8182
assert len(array) == 11
8283
assert np.allclose(array, ref_array)
83-
84+
8485

8586
def test_getlinkattribute(handle):
86-
ref_array = np.array([ 1848.58117676, 1220.42736816, 130.11161804,
87-
187.68930054, 119.88839722, 40.46448898, -748.58111572, 478.15377808,
87+
ref_array = np.array([ 1848.58117676, 1220.42736816, 130.11161804,
88+
187.68930054, 119.88839722, 40.46448898, -748.58111572, 478.15377808,
8889
191.73458862, 30.11160851, 140.4644928, 59.53551483, 1848.58117676])
89-
90+
9091
array = oapi.getlinkattribute(handle, 1, oapi.LinkAttribute.FLOW)
91-
assert len(array) == 13
92+
assert len(array) == 13
9293
assert np.allclose(array, ref_array)
9394

9495

9596
def test_getnoderesult(handle):
9697
pass
9798

9899
def test_getlinkresult(handle):
99-
pass
100+
pass
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)