Skip to content

Commit 7f88618

Browse files
authored
Merge pull request #53 from kefeimo/4pr
Squashed commit of the following:
2 parents c26c3c2 + bf68120 commit 7f88618

22 files changed

+1999
-543
lines changed

.github/workflows/deploy-pre-release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
strategy:
2121
fail-fast: false
2222
matrix:
23-
python-version: [ '3.8', '3.9', '3.10' , '3.11']
23+
python-version: [ '3.8', '3.9', '3.10' ] # 3.11+ not suppport
2424
steps:
2525
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
2626
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Install Package Test
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.9", "3.10"]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
name: Check out repository code
23+
with:
24+
submodules: recursive # Ensures submodules are checked out
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
python -m venv env
35+
source env/bin/activate
36+
37+
- name: Install and Test Package
38+
run: |
39+
pip install cmake # Install CMake
40+
python setup.py install
41+
python -c "import dnp3_python; print(dnp3_python)"
42+
env:
43+
PYTHONPATH: ${{ github.workspace }}
44+
45+
- name: Clean up
46+
if: always()
47+
run: rm -rf env

.github/workflows/tests.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Pytests
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- develop
8+
pull_request:
9+
branches:
10+
- main
11+
- develop
12+
13+
jobs:
14+
build:
15+
runs-on: ubuntu-latest
16+
strategy:
17+
matrix:
18+
python-version: ["3.9", "3.10"]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
name: Check out repository code
23+
with:
24+
submodules: recursive # Ensures submodules are checked out
25+
26+
- name: Set up Python ${{ matrix.python-version }}
27+
uses: actions/setup-python@v2
28+
with:
29+
python-version: ${{ matrix.python-version }}
30+
31+
- name: Install dependencies
32+
run: |
33+
python -m pip install --upgrade pip
34+
python -m venv env
35+
source env/bin/activate
36+
37+
- name: Install and Test Package
38+
run: |
39+
pip install cmake # Install CMake
40+
python setup.py install
41+
python -c "import dnp3_python; print(dnp3_python)"
42+
env:
43+
PYTHONPATH: ${{ github.workspace }}
44+
45+
- name: Run Tests
46+
run: |
47+
pip install pytest
48+
for file in tests/test_dnp3_python/test_*.py; do echo "Running pytest on $file"; pytest -s -vv $file; done # Note: the file needs to run separately.
49+
env:
50+
PYTHONPATH: ${{ github.workspace }}
51+
52+
- name: Clean up
53+
if: always()
54+
run: rm -rf env

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ __pycache__/
88

99
# Distribution / packaging
1010
.Python
11-
env/
11+
env*/
1212
build/
1313
develop-eggs/
1414
dist/

deps/pybind11

Submodule pybind11 updated 248 files

setup.py

Lines changed: 69 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -36,65 +36,87 @@
3636
# under Contract DE-AC05-76RL01830
3737
# }}}
3838

39-
import sys
4039
import os
41-
import subprocess
42-
import re
4340
import platform
41+
import re
42+
import subprocess
43+
import sys
44+
from distutils.version import LooseVersion
45+
from pathlib import Path
4446

45-
from setuptools import setup, Extension
47+
from setuptools import Extension, find_namespace_packages, find_packages, setup
4648
from setuptools.command.build_ext import build_ext
47-
from distutils.version import LooseVersion
4849

49-
from setuptools import find_packages, find_namespace_packages
50-
from pathlib import Path
50+
module_name = "dnp3_python"
51+
5152

52-
__version__ = '0.3.0b1'
53+
# Function to extract version from the __init__.py file at /src
54+
def find_version():
55+
here = os.path.abspath(os.path.dirname(__file__))
56+
with open(os.path.join(here, "src", module_name, "__init__.py"), "r") as f:
57+
contents = f.read()
58+
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", contents, re.M)
59+
if version_match:
60+
return version_match.group(1)
61+
raise RuntimeError("Unable to find version string.")
62+
63+
64+
__version__ = find_version()
65+
print(f"{__version__=}")
5366

5467

5568
class CMakeExtension(Extension):
56-
def __init__(self, name, sourcedir=''):
69+
def __init__(self, name, sourcedir=""):
5770
Extension.__init__(self, name, sources=[])
5871
self.sourcedir = os.path.abspath(sourcedir)
5972

6073

6174
class CMakeBuild(build_ext):
6275
def run(self):
6376
try:
64-
out = subprocess.check_output(['cmake', '--version'])
77+
out = subprocess.check_output(["cmake", "--version"])
6578
except OSError:
66-
raise RuntimeError("CMake must be installed to build the following extensions: " +
67-
", ".join(e.name for e in self.extensions))
79+
raise RuntimeError(
80+
"CMake must be installed to build the following extensions: "
81+
+ ", ".join(e.name for e in self.extensions)
82+
)
6883

6984
if platform.system() == "Windows":
70-
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1))
71-
if cmake_version < '3.1.0':
85+
cmake_version = LooseVersion(
86+
re.search(r"version\s*([\d.]+)", out.decode()).group(1)
87+
)
88+
if cmake_version < "3.1.0":
7289
raise RuntimeError("CMake >= 3.1.0 is required on Windows")
7390

7491
for ext in self.extensions:
7592
self.build_extension(ext)
7693

7794
def build_extension(self, ext):
7895
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name)))
79-
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir,
80-
'-DPYTHON_EXECUTABLE=' + sys.executable]
96+
cmake_args = [
97+
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir,
98+
"-DPYTHON_EXECUTABLE=" + sys.executable,
99+
]
81100

82-
cfg = 'Debug' if self.debug else 'Release'
83-
build_args = ['--config', cfg]
101+
cfg = "Debug" if self.debug else "Release"
102+
build_args = ["--config", cfg]
84103

85104
if platform.system() == "Windows":
86-
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
105+
cmake_args += [
106+
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir)
107+
]
87108
if sys.maxsize > 2**32:
88-
cmake_args += ['-A', 'x64']
89-
build_args += ['--', '/m']
109+
cmake_args += ["-A", "x64"]
110+
build_args += ["--", "/m"]
90111
else:
91-
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg]
92-
cmake_args += ['-DSTATICLIBS=ON']
93-
build_args += ['--', '-j2']
112+
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg]
113+
cmake_args += ["-DSTATICLIBS=ON"]
114+
build_args += ["--", "-j2"]
94115

95116
env = os.environ.copy()
96-
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''),
97-
self.distribution.get_version())
117+
env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format(
118+
env.get("CXXFLAGS", ""), self.distribution.get_version()
119+
)
98120
if not os.path.exists(self.build_temp):
99121
os.makedirs(self.build_temp)
100122

@@ -106,37 +128,41 @@ def build_extension(self, ext):
106128
#
107129
# subprocess.check_call(['git', 'apply', patch_path], cwd=dnp3_path)
108130

109-
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env)
110-
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp)
131+
subprocess.check_call(
132+
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env
133+
)
134+
subprocess.check_call(
135+
["cmake", "--build", "."] + build_args, cwd=self.build_temp
136+
)
111137

112138

113139
this_directory = Path(__file__).parent
114140
long_description = (this_directory / "README.md").read_text()
115141

116142
setup(
117-
name='dnp3-python',
143+
name="dnp3-python",
118144
version=__version__,
119-
author='Volttron Team',
120-
author_email='[email protected]',
121-
url='https://github.com/VOLTTRON/dnp3-python',
122-
description='pydnp3 -- python binding for opendnp3',
145+
author="Volttron Team",
146+
author_email="[email protected]",
147+
url="https://github.com/VOLTTRON/dnp3-python",
148+
description="pydnp3 -- python binding for opendnp3",
123149
long_description=long_description,
124-
long_description_content_type='text/markdown',
150+
long_description_content_type="text/markdown",
125151
install_requires=[
126152
# 'pybind11>=2.2',
127-
'argcomplete'],
128-
ext_modules=[CMakeExtension('pydnp3')],
153+
"argcomplete"
154+
],
155+
ext_modules=[CMakeExtension("pydnp3")],
129156
cmdclass=dict(build_ext=CMakeBuild),
130157
zip_safe=False,
131-
132158
packages=find_namespace_packages(
133-
where='src',
134-
include=['dnp3_python*', 'dnp3demo'] # to include sub-packages as well.
159+
where="src",
160+
include=[f"{module_name}*", "dnp3demo"], # to include sub-packages as well.
135161
),
136162
package_dir={"": "src"},
137163
entry_points={
138-
'console_scripts': [
139-
'dnp3demo = dnp3demo.__main__:main',
140-
]
141-
},
164+
"console_scripts": [
165+
"dnp3demo = dnp3demo.__main__:main",
166+
]
167+
},
142168
)

src/dnp3_python/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = "0.3.0b1"

0 commit comments

Comments
 (0)