From 686dc54774d03a638956ce4f2e49b78d0cea5c59 Mon Sep 17 00:00:00 2001 From: Joshua Lucas Date: Thu, 29 Oct 2026 13:16:20 -0500 Subject: [PATCH] Move contents of extensions to the root package directory. --- src/AuDaGe/__main__.py | 21 +++++----- src/AuDaGe/{extensions => assets}/__init__.py | 0 .../{extensions => }/assets/schema.yaml | 0 src/AuDaGe/{extensions => }/converter.py | 42 ------------------- src/AuDaGe/extensions/assets/__init__.py | 0 src/AuDaGe/formats/kepserver/__init__.py | 4 ++ src/AuDaGe/formats/pi_historian/__init__.py | 0 src/AuDaGe/formats/pi_historian/xlsx.py | 0 src/AuDaGe/frame.py | 15 ++++++- src/AuDaGe/iec/iec_type.py | 11 ++--- 10 files changed, 34 insertions(+), 59 deletions(-) rename src/AuDaGe/{extensions => assets}/__init__.py (100%) rename src/AuDaGe/{extensions => }/assets/schema.yaml (100%) rename src/AuDaGe/{extensions => }/converter.py (86%) delete mode 100644 src/AuDaGe/extensions/assets/__init__.py delete mode 100644 src/AuDaGe/formats/pi_historian/__init__.py delete mode 100644 src/AuDaGe/formats/pi_historian/xlsx.py diff --git a/src/AuDaGe/__main__.py b/src/AuDaGe/__main__.py index 4b167c0..cc77184 100644 --- a/src/AuDaGe/__main__.py +++ b/src/AuDaGe/__main__.py @@ -26,15 +26,6 @@ FC = FormatChoices def main(): args = parse_args() - if args["unsafe"]: - AuDaGe.safe = False - print( - "You have chosen the option `unsafe`. Be aware (BEWARE!) that this " - "allows execution of arbitrary, possibly unsafe code from files " - "external to the AuDaGe module. Do not specify this option unless " - "you are familiar with the contents of the specified configuration " - "files." - ) frame = load_input_file(args) dump_output_file(frame, args) @@ -55,7 +46,17 @@ def parse_args(): ) parser.add_argument("output_file", type=pathlib.Path, help="") parser.add_argument("--unsafe", action="store_true") - return parser.parse_args() + args = parser.parse_args() + if args.unsafe: + AuDaGe.safe = False + print( + "You have chosen the option `unsafe`. Be aware (BEWARE!) that this " + "allows execution of arbitrary, possibly unsafe code from files " + "external to the AuDaGe module. Do not specify this option unless " + "you are familiar with the contents of the specified configuration " + "files." + ) + return args def load_input_file(args): diff --git a/src/AuDaGe/extensions/__init__.py b/src/AuDaGe/assets/__init__.py similarity index 100% rename from src/AuDaGe/extensions/__init__.py rename to src/AuDaGe/assets/__init__.py diff --git a/src/AuDaGe/extensions/assets/schema.yaml b/src/AuDaGe/assets/schema.yaml similarity index 100% rename from src/AuDaGe/extensions/assets/schema.yaml rename to src/AuDaGe/assets/schema.yaml diff --git a/src/AuDaGe/extensions/converter.py b/src/AuDaGe/converter.py similarity index 86% rename from src/AuDaGe/extensions/converter.py rename to src/AuDaGe/converter.py index 9ed899a..0ea0375 100644 --- a/src/AuDaGe/extensions/converter.py +++ b/src/AuDaGe/converter.py @@ -348,45 +348,3 @@ class Converter: return pd.Series(frame[translator.columns[0]]) # Else, run the operations. return translator.translate(frame) - - -if __name__ == "__main__": - plcs = ("WA3252_PLC_001_1",) - tags = ("caption", "desc", "message", "tagname", "unit") - for plc in plcs: - for tag in tags: - substitutions = {"$extension$": tag.title(), "$plc$": plc} - kep_converter = Converter( - f"extensions/kepserver/strings/{tag}_csv.yaml", - substitutions=substitutions, - ) - kep = kep_converter.from_file( - f"C:/Users/j.lucas/OneDrive - Prime Controls/Customers/NTMWD/" - f"Engineering/Leonard (North) Water Treatment Plant/Programs/PLC/" - f"WA3252-PLC-001-1 Raw Water PS/{plc}.csv" - ) - af = kep_converter.to_AF(kep) - kep2 = kep_converter.from_AF(af) - kep_converter.to_file(kep2, f"tests/output/{plc}_strings_{tag}.csv") - af2 = kep_converter.to_AF(kep2) - macro_converter = Converter( - f"extensions/factorytalk/macro/{tag}_macro.yaml", - substitutions=substitutions, - ) - macro = macro_converter.from_AF(af2) - macro_converter.to_file(macro, f"tests/output/{plc}_{tag}.mcr") - kep_converter = Converter("extensions/kepserver/modbus/csv.yaml") - kep = kep_converter.from_file( - f"C:/Users/j.lucas/OneDrive - Prime Controls/Customers/NTMWD/" - f"Engineering/Leonard (North) Water Treatment Plant/Programs/PLC/" - f"WA3252-PLC-001-1 Raw Water PS/{plc}.csv" - ) - af = kep_converter.to_AF(kep) - macro_converter = Converter( - "extensions/factorytalk/macro/alarm_severity_macro.yaml", - substitutions={"$plc$": plc}, - ) - macro = macro_converter.from_AF(af) - macro_converter.to_file( - macro, f"tests/output/{plc}_alarm_severities.mcr" - ) diff --git a/src/AuDaGe/extensions/assets/__init__.py b/src/AuDaGe/extensions/assets/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/AuDaGe/formats/kepserver/__init__.py b/src/AuDaGe/formats/kepserver/__init__.py index e69de29..fc421e8 100644 --- a/src/AuDaGe/formats/kepserver/__init__.py +++ b/src/AuDaGe/formats/kepserver/__init__.py @@ -0,0 +1,4 @@ +raise DeprecationWarning( + "This module is deprecated. Please use the extension framework for " + "converting to/from Kepserver formats." +) \ No newline at end of file diff --git a/src/AuDaGe/formats/pi_historian/__init__.py b/src/AuDaGe/formats/pi_historian/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/AuDaGe/formats/pi_historian/xlsx.py b/src/AuDaGe/formats/pi_historian/xlsx.py deleted file mode 100644 index e69de29..0000000 diff --git a/src/AuDaGe/frame.py b/src/AuDaGe/frame.py index 1bf2151..7af33ac 100644 --- a/src/AuDaGe/frame.py +++ b/src/AuDaGe/frame.py @@ -207,7 +207,7 @@ class Frame(pd.DataFrame, metaclass=MetaFrame): self.to_csv(path_or_buf=path, index=False) -class AuDaGeColumns(BetterStrEnum): +class AuDaGeMandatoryColumns(BetterStrEnum): """Enum of columns required by AuDaGeFrame.""" TAGNAME = "tagname" @@ -216,7 +216,18 @@ class AuDaGeColumns(BetterStrEnum): COMMENT = "comment" -class AuDaGeFrame(Frame, mandatory_columns=AuDaGeColumns.values()): +class AuDaGeOptionalColumns(BetterStrEnum): + PARENT = "parent" + + +class AuDaGeColumns: + Mandatory = AuDaGeMandatoryColumns + Optional = AuDaGeOptionalColumns + M = Mandatory + O = Optional + + +class AuDaGeFrame(Frame, mandatory_columns=AuDaGeColumns.Mandatory.values()): """DataFrame that enforces the presence of columns matching the names in `AuDaGeColumns`. Used as intermediate format for converting between other data formats. diff --git a/src/AuDaGe/iec/iec_type.py b/src/AuDaGe/iec/iec_type.py index b134154..57cc29b 100644 --- a/src/AuDaGe/iec/iec_type.py +++ b/src/AuDaGe/iec/iec_type.py @@ -48,6 +48,7 @@ from math import ceil, prod import pandas as pd +from AuDaGe.frame import AuDaGeColumns as AC from AuDaGe.frame import AuDaGeFrame from .iec_common import * @@ -212,16 +213,16 @@ class IECType: all_indices = pd.DataFrame(dim_indices) continue columns = { - "name": all_indices.apply( + AC.M.TAGNAME: all_indices.apply( lambda row: f"{name}[{','.join(str(dim) for dim in row)}]", axis=1, ), - "type": str(self.array_type), - "address": [ + AC.M.TYPE: str(self.array_type), + AC.M.ADDRESS: [ self.array_type.length * i for i in range(len(all_indices)) ], - "comment": comment, - "parent": self.name.upper(), + AC.M.COMMENT: comment, + AC.O.PARENT: self.name.upper(), } return AuDaGeFrame(columns)