-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move DesignMatrixArgs into seperate file and rename to DesignMatrix
- Loading branch information
Showing
2 changed files
with
55 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from __future__ import annotations | ||
|
||
from dataclasses import dataclass | ||
from pathlib import Path | ||
from typing import List | ||
|
||
from ._option_dict import option_dict | ||
from .parsing import ( | ||
ConfigValidationError, | ||
ErrorInfo, | ||
) | ||
|
||
|
||
@dataclass | ||
class DesignMatrix: | ||
xls_filename: Path | ||
designsheet: str | ||
defaultsheet: str | ||
|
||
@classmethod | ||
def from_config_list(cls, config_list: List[str]) -> "DesignMatrix": | ||
filename = Path(config_list[0]) | ||
options = option_dict(config_list, 1) | ||
design_sheet = options.get("DESIGN_SHEET") | ||
default_sheet = options.get("DEFAULT_SHEET") | ||
errors = [] | ||
if filename.suffix not in { | ||
".xlsx", | ||
".xls", | ||
}: | ||
errors.append( | ||
ErrorInfo( | ||
f"DESIGN_MATRIX must be of format .xls or .xslx; is {filename}" | ||
).set_context(config_list) | ||
) | ||
if design_sheet is None: | ||
errors.append( | ||
ErrorInfo("Missing required DESIGN_SHEET").set_context(config_list) | ||
) | ||
if default_sheet is None: | ||
errors.append( | ||
ErrorInfo("Missing required DEFAULT_SHEET").set_context(config_list) | ||
) | ||
if errors: | ||
raise ConfigValidationError.from_collected(errors) | ||
assert design_sheet is not None | ||
assert default_sheet is not None | ||
return cls( | ||
xls_filename=filename, | ||
designsheet=design_sheet, | ||
defaultsheet=default_sheet, | ||
) |