nox running!

This commit is contained in:
Paul Warren 2024-10-09 18:18:24 +11:00
parent d489d2c5b9
commit a833069eb5
5 changed files with 40 additions and 11 deletions

View file

@ -1,12 +1,27 @@
import nox import nox
import os
@nox.session @nox.session
def lint(session): def lint(session):
session.install('ruff') session.install('ruff')
session.run('ruff', 'check', '--exclude', 'examples') session.run('ruff', 'check', '--exclude', 'examples')
@nox.session
def build_and_check_dists(session):
session.install("build", "check-manifest >= 0.42", "twine")
# session.run("check-manifest", "--ignore", "noxfile.py,tests/**,examples/**")
session.run("python", "-m", "build")
session.run("python", "-m", "twine", "check", "dist/*")
@nox.session @nox.session
def tests(session): def tests(session):
session.install('pytest') session.install('pytest')
build_and_check_dists(session)
generated_files = os.listdir("dist/")
generated_sdist = os.path.join("dist/", generated_files[1])
session.install(generated_sdist)
session.run('pytest') session.run('pytest')

View file

@ -1,18 +1,31 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[tool.hatch.build.targets.wheel]
packages = ["src/pyfroniusreg"]
[project] [project]
name = "Python Fronius Registers" name = "pyFroniusReg"
version = "0.0.1" version = "0.0.1"
authors = [ authors = [
{ name = "Paul Warren", email="pwarren@pwarren.id.au" } { name = "Paul Warren", email="pwarren@pwarren.id.au" }
] ]
description = "A library to make interacting with Fronius Inverters and Charging systems simpler" description = "A library to make interacting with Fronius inverters and storage systems simpler"
readme = "README.md" readme = "README.md"
requires-python = ">=3.8" requires-python = ">=3.8"
classifiers = [ classifiers = [
"Programming Language :: Python :: 3", "Programming Language :: Python :: 3",
"License :: OSI Approved :: AGPL License", "License :: OSI Approved :: GNU Affero General Public License v3 or later (AGPLv3+)",
"Operating System :: OS Independent", "Operating System :: OS Independent",
"Development Status :: 1 - Planning",
] ]
dependencies = [
"pymodbus"
]
[project.urls] [project.urls]
Homepage = "https://git.pwarren.id.au/pwarren/PyFroniusReg/" Homepage = "https://git.pwarren.id.au/pwarren/PyFroniusReg/"
Issues = "https://git.pwarren.id.au/pwarren/PyFroniusReg/issues" Issues = "https://git.pwarren.id.au/pwarren/PyFroniusReg/issues"

View file

@ -1,7 +1,8 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
from froniusreg import froniusreg #from PyFroniusReg import froniusreg
#import src.froniusreg
import src.pyfroniusreg.froniusreg as froniusreg
from pymodbus.client.tcp import ModbusTcpClient from pymodbus.client.tcp import ModbusTcpClient
fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10) fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10)

View file

@ -42,7 +42,7 @@ class DataType(Enum):
return int(2) return int(2)
def decode(self, value): def decode(self, value):
decoder = BinaryPayloadDecoder.fromRegisters(value.registers, byteorder=Endian.Big, wordorder=Endian.Big) decoder = BinaryPayloadDecoder.fromRegisters(value.registers, byteorder=Endian.BIG, wordorder=Endian.BIG)
if (self == DataType.String8) or (self == DataType.String16) or (self == DataType.String32): if (self == DataType.String8) or (self == DataType.String16) or (self == DataType.String32):
return str(decoder.decode_string(16).decode('utf-8')) return str(decoder.decode_string(16).decode('utf-8'))
@ -66,7 +66,7 @@ class DataType(Enum):
return str(decoder.decode_bits()) return str(decoder.decode_bits())
def encode(self, value): def encode(self, value):
encoder = BinaryPayloadBuilder(byteorder=Endian.Big, wordorder=Endian.Big) encoder = BinaryPayloadBuilder(byteorder=Endian.BIG, wordorder=Endian.BIG)
if (self == DataType.String8) or (self == DataType.String16) or (self == DataType.String32): if (self == DataType.String8) or (self == DataType.String16) or (self == DataType.String32):
return encoder.add_string(value).build() return encoder.add_string(value).build()

View file

@ -1,12 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import unittest import unittest
import pyFroniusReg.froniusreg as froniusreg import pyfroniusreg.froniusreg as froniusreg
class TestDataTypes(unittest.testCase): class TestDataTypes(unittest.TestCase):
def test_int16(self): def test_int16(self):
assert froniusreg.int16.decode(froniusreg.int16.encode(65536)) == 65535 assert froniusreg.int16.decode(froniusreg.int16.encode(1024)) == 1024
if __name__ == '__main__': if __name__ == '__main__':