diff --git a/noxfile.py b/noxfile.py index 11ac9c5..c533569 100644 --- a/noxfile.py +++ b/noxfile.py @@ -1,12 +1,27 @@ import nox +import os @nox.session def lint(session): session.install('ruff') 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 def tests(session): 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') diff --git a/pyproject.toml b/pyproject.toml index 98bfe92..e65998f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,18 +1,31 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + +[tool.hatch.build.targets.wheel] +packages = ["src/pyfroniusreg"] + [project] -name = "Python Fronius Registers" +name = "pyFroniusReg" version = "0.0.1" authors = [ { 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" requires-python = ">=3.8" classifiers = [ "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", + "Development Status :: 1 - Planning", ] +dependencies = [ + "pymodbus" + ] + [project.urls] Homepage = "https://git.pwarren.id.au/pwarren/PyFroniusReg/" -Issues = "https://git.pwarren.id.au/pwarren/PyFroniusReg/issues" \ No newline at end of file +Issues = "https://git.pwarren.id.au/pwarren/PyFroniusReg/issues" + diff --git a/read_regs.py b/read_regs.py index bfd58f1..00bea36 100755 --- a/read_regs.py +++ b/read_regs.py @@ -1,7 +1,8 @@ #!/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 fronius1 = ModbusTcpClient("172.19.107.211", port=502, timeout=10) diff --git a/src/froniusreg.py b/src/pyfroniusreg/froniusreg.py similarity index 98% rename from src/froniusreg.py rename to src/pyfroniusreg/froniusreg.py index 250d47b..9c51e0a 100644 --- a/src/froniusreg.py +++ b/src/pyfroniusreg/froniusreg.py @@ -42,7 +42,7 @@ class DataType(Enum): return int(2) 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): return str(decoder.decode_string(16).decode('utf-8')) @@ -66,7 +66,7 @@ class DataType(Enum): return str(decoder.decode_bits()) 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): return encoder.add_string(value).build() diff --git a/tests/test_datatype.py b/tests/test_datatype.py index 83e2cb0..fb1176f 100644 --- a/tests/test_datatype.py +++ b/tests/test_datatype.py @@ -1,12 +1,12 @@ #!/usr/bin/env python3 import unittest -import pyFroniusReg.froniusreg as froniusreg +import pyfroniusreg.froniusreg as froniusreg -class TestDataTypes(unittest.testCase): +class TestDataTypes(unittest.TestCase): 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__':