Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Squashed commit of the following: #53

Merged
merged 5 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy-pre-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.8', '3.9', '3.10' , '3.11']
python-version: [ '3.8', '3.9', '3.10' ] # 3.11+ not suppport
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
Expand Down
47 changes: 47 additions & 0 deletions .github/workflows/install-package.yml
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
54 changes: 54 additions & 0 deletions .github/workflows/tests.yml
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ __pycache__/

# Distribution / packaging
.Python
env/
env*/
build/
develop-eggs/
dist/
Expand Down
2 changes: 1 addition & 1 deletion deps/pybind11
Submodule pybind11 updated 248 files
112 changes: 69 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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",
]
},
)
1 change: 1 addition & 0 deletions src/dnp3_python/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "0.3.0b1"
Loading
Loading