Skip to content

Commit

Permalink
Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
energinet-ajw committed Dec 6, 2024
1 parent cba20e2 commit 90dd6e9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from dataclasses import dataclass

@dataclass
class ElectricalHeatingArgs:
electrical_heating_id: str
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import argparse
import sys
import configargparse
from argparse import Namespace
from telemetry_logging import Logger, logging_configuration
from source.electrical_heating.electrical_heating_job.entry_points.job_args.electrical_heating_args import ElectricalHeatingArgs

def parse_command_line_arguments() -> Namespace:
return _parse_args_or_throw(sys.argv[1:])


def parse_job_arguments(
job_args: Namespace,
) -> ElectricalHeatingArgs:
logger = Logger(__name__)
logger.info(f"Command line arguments: {repr(job_args)}")

with logging_configuration.start_span("electrical_heating.parse_job_arguments"):

electrical_heating_args = ElectricalHeatingArgs(
electrical_heating_id=job_args.electrical_heating_id,
)

return electrical_heating_args

def _parse_args_or_throw(command_line_args: list[str]) -> argparse.Namespace:
p = configargparse.ArgParser(
description="Execute electrical heating calculation",
formatter_class=configargparse.ArgumentDefaultsHelpFormatter,
)

# Run parameters
p.add_argument("--electrical-heating-id", type=str, required=True)

args, unknown_args = p.parse_known_args(args=command_line_args)
if len(unknown_args):
unknown_args_text = ", ".join(unknown_args)
raise Exception(f"Unknown args: {unknown_args_text}")

return args

0 comments on commit 90dd6e9

Please sign in to comment.