-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #53 from kefeimo/4pr
Squashed commit of the following:
- Loading branch information
Showing
22 changed files
with
1,999 additions
and
543 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
name: Install Package Test | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
name: Check out repository code | ||
with: | ||
submodules: recursive # Ensures submodules are checked out | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m venv env | ||
source env/bin/activate | ||
- name: Install and Test Package | ||
run: | | ||
pip install cmake # Install CMake | ||
python setup.py install | ||
python -c "import dnp3_python; print(dnp3_python)" | ||
env: | ||
PYTHONPATH: ${{ github.workspace }} | ||
|
||
- name: Clean up | ||
if: always() | ||
run: rm -rf env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Pytests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
- develop | ||
pull_request: | ||
branches: | ||
- main | ||
- develop | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.9", "3.10"] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
name: Check out repository code | ||
with: | ||
submodules: recursive # Ensures submodules are checked out | ||
|
||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m venv env | ||
source env/bin/activate | ||
- name: Install and Test Package | ||
run: | | ||
pip install cmake # Install CMake | ||
python setup.py install | ||
python -c "import dnp3_python; print(dnp3_python)" | ||
env: | ||
PYTHONPATH: ${{ github.workspace }} | ||
|
||
- name: Run Tests | ||
run: | | ||
pip install pytest | ||
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. | ||
env: | ||
PYTHONPATH: ${{ github.workspace }} | ||
|
||
- name: Clean up | ||
if: always() | ||
run: rm -rf env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ __pycache__/ | |
|
||
# Distribution / packaging | ||
.Python | ||
env/ | ||
env*/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,65 +36,87 @@ | |
# under Contract DE-AC05-76RL01830 | ||
# }}} | ||
|
||
import sys | ||
import os | ||
import subprocess | ||
import re | ||
import platform | ||
import re | ||
import subprocess | ||
import sys | ||
from distutils.version import LooseVersion | ||
from pathlib import Path | ||
|
||
from setuptools import setup, Extension | ||
from setuptools import Extension, find_namespace_packages, find_packages, setup | ||
from setuptools.command.build_ext import build_ext | ||
from distutils.version import LooseVersion | ||
|
||
from setuptools import find_packages, find_namespace_packages | ||
from pathlib import Path | ||
module_name = "dnp3_python" | ||
|
||
|
||
__version__ = '0.3.0b1' | ||
# Function to extract version from the __init__.py file at /src | ||
def find_version(): | ||
here = os.path.abspath(os.path.dirname(__file__)) | ||
with open(os.path.join(here, "src", module_name, "__init__.py"), "r") as f: | ||
contents = f.read() | ||
version_match = re.search(r"^__version__ = ['\"]([^'\"]*)['\"]", contents, re.M) | ||
if version_match: | ||
return version_match.group(1) | ||
raise RuntimeError("Unable to find version string.") | ||
|
||
|
||
__version__ = find_version() | ||
print(f"{__version__=}") | ||
|
||
|
||
class CMakeExtension(Extension): | ||
def __init__(self, name, sourcedir=''): | ||
def __init__(self, name, sourcedir=""): | ||
Extension.__init__(self, name, sources=[]) | ||
self.sourcedir = os.path.abspath(sourcedir) | ||
|
||
|
||
class CMakeBuild(build_ext): | ||
def run(self): | ||
try: | ||
out = subprocess.check_output(['cmake', '--version']) | ||
out = subprocess.check_output(["cmake", "--version"]) | ||
except OSError: | ||
raise RuntimeError("CMake must be installed to build the following extensions: " + | ||
", ".join(e.name for e in self.extensions)) | ||
raise RuntimeError( | ||
"CMake must be installed to build the following extensions: " | ||
+ ", ".join(e.name for e in self.extensions) | ||
) | ||
|
||
if platform.system() == "Windows": | ||
cmake_version = LooseVersion(re.search(r'version\s*([\d.]+)', out.decode()).group(1)) | ||
if cmake_version < '3.1.0': | ||
cmake_version = LooseVersion( | ||
re.search(r"version\s*([\d.]+)", out.decode()).group(1) | ||
) | ||
if cmake_version < "3.1.0": | ||
raise RuntimeError("CMake >= 3.1.0 is required on Windows") | ||
|
||
for ext in self.extensions: | ||
self.build_extension(ext) | ||
|
||
def build_extension(self, ext): | ||
extdir = os.path.abspath(os.path.dirname(self.get_ext_fullpath(ext.name))) | ||
cmake_args = ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + extdir, | ||
'-DPYTHON_EXECUTABLE=' + sys.executable] | ||
cmake_args = [ | ||
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=" + extdir, | ||
"-DPYTHON_EXECUTABLE=" + sys.executable, | ||
] | ||
|
||
cfg = 'Debug' if self.debug else 'Release' | ||
build_args = ['--config', cfg] | ||
cfg = "Debug" if self.debug else "Release" | ||
build_args = ["--config", cfg] | ||
|
||
if platform.system() == "Windows": | ||
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)] | ||
cmake_args += [ | ||
"-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}".format(cfg.upper(), extdir) | ||
] | ||
if sys.maxsize > 2**32: | ||
cmake_args += ['-A', 'x64'] | ||
build_args += ['--', '/m'] | ||
cmake_args += ["-A", "x64"] | ||
build_args += ["--", "/m"] | ||
else: | ||
cmake_args += ['-DCMAKE_BUILD_TYPE=' + cfg] | ||
cmake_args += ['-DSTATICLIBS=ON'] | ||
build_args += ['--', '-j2'] | ||
cmake_args += ["-DCMAKE_BUILD_TYPE=" + cfg] | ||
cmake_args += ["-DSTATICLIBS=ON"] | ||
build_args += ["--", "-j2"] | ||
|
||
env = os.environ.copy() | ||
env['CXXFLAGS'] = '{} -DVERSION_INFO=\\"{}\\"'.format(env.get('CXXFLAGS', ''), | ||
self.distribution.get_version()) | ||
env["CXXFLAGS"] = '{} -DVERSION_INFO=\\"{}\\"'.format( | ||
env.get("CXXFLAGS", ""), self.distribution.get_version() | ||
) | ||
if not os.path.exists(self.build_temp): | ||
os.makedirs(self.build_temp) | ||
|
||
|
@@ -106,37 +128,41 @@ def build_extension(self, ext): | |
# | ||
# subprocess.check_call(['git', 'apply', patch_path], cwd=dnp3_path) | ||
|
||
subprocess.check_call(['cmake', ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env) | ||
subprocess.check_call(['cmake', '--build', '.'] + build_args, cwd=self.build_temp) | ||
subprocess.check_call( | ||
["cmake", ext.sourcedir] + cmake_args, cwd=self.build_temp, env=env | ||
) | ||
subprocess.check_call( | ||
["cmake", "--build", "."] + build_args, cwd=self.build_temp | ||
) | ||
|
||
|
||
this_directory = Path(__file__).parent | ||
long_description = (this_directory / "README.md").read_text() | ||
|
||
setup( | ||
name='dnp3-python', | ||
name="dnp3-python", | ||
version=__version__, | ||
author='Volttron Team', | ||
author_email='[email protected]', | ||
url='https://github.com/VOLTTRON/dnp3-python', | ||
description='pydnp3 -- python binding for opendnp3', | ||
author="Volttron Team", | ||
author_email="[email protected]", | ||
url="https://github.com/VOLTTRON/dnp3-python", | ||
description="pydnp3 -- python binding for opendnp3", | ||
long_description=long_description, | ||
long_description_content_type='text/markdown', | ||
long_description_content_type="text/markdown", | ||
install_requires=[ | ||
# 'pybind11>=2.2', | ||
'argcomplete'], | ||
ext_modules=[CMakeExtension('pydnp3')], | ||
"argcomplete" | ||
], | ||
ext_modules=[CMakeExtension("pydnp3")], | ||
cmdclass=dict(build_ext=CMakeBuild), | ||
zip_safe=False, | ||
|
||
packages=find_namespace_packages( | ||
where='src', | ||
include=['dnp3_python*', 'dnp3demo'] # to include sub-packages as well. | ||
where="src", | ||
include=[f"{module_name}*", "dnp3demo"], # to include sub-packages as well. | ||
), | ||
package_dir={"": "src"}, | ||
entry_points={ | ||
'console_scripts': [ | ||
'dnp3demo = dnp3demo.__main__:main', | ||
] | ||
}, | ||
"console_scripts": [ | ||
"dnp3demo = dnp3demo.__main__:main", | ||
] | ||
}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.3.0b1" |
Oops, something went wrong.