generated from ansys/template
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Mohamed Koubaa <[email protected]> Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
3961bd9
commit 9a5eb07
Showing
16 changed files
with
440 additions
and
94 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
Empty file.
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,15 @@ | ||
import abc | ||
import typing | ||
|
||
class KeywordHandler(metaclass=abc.ABCMeta): | ||
"""Abstract base class for keyword handlers.""" | ||
|
||
@abc.abstractmethod | ||
def handle(self, kwd_data: typing.Dict[str, typing.Any], settings: typing.Dict[str, typing.Any]) -> None: | ||
"""Transform `kwd_data` based on `settings`.""" | ||
raise NotImplementedError | ||
|
||
@abc.abstractmethod | ||
def post_process(self, kwd_data: typing.Dict[str, typing.Any]) -> None: | ||
"""Run after all handlers have run.""" | ||
raise NotImplementedError |
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,67 @@ | ||
import typing | ||
|
||
import keyword_generation.handlers.handler_base | ||
|
||
def do_negative_shared_fields(kwd_data: typing.Dict): | ||
negative_shared_fields = kwd_data.get("negative_shared_fields", []) | ||
num_cards = len(kwd_data["cards"]) | ||
options = kwd_data.get("options", []) | ||
option_cards = [] | ||
for options in kwd_data.get("options", []): | ||
option_cards.extend(options["cards"]) | ||
for setting in negative_shared_fields: | ||
indices = [-i for i in setting["cards"]] | ||
fields = [] | ||
for index in indices: | ||
if index >= num_cards: | ||
for options in kwd_data.get("options", []): | ||
for card in options["cards"]: | ||
if card["index"] == index: | ||
for field in card["fields"]: | ||
if field["name"] == setting["name"]: | ||
fields.append(field) | ||
else: | ||
assert False, "TODO - support negative indices for shared fields for non-options" | ||
assert len(fields) > 1 | ||
if not setting["applied_card_indices"]: | ||
fields[0]["card_indices"] = indices | ||
for field in fields[1:]: | ||
field["redundant"] = True | ||
|
||
|
||
def handle_shared_field(kwd_data, settings): | ||
# positive card indices are applied in handler | ||
# negative card indices are marked and handled after transformations (after_handle) | ||
for setting in settings: | ||
setting["applied_card_indices"] = False | ||
cards = setting["cards"] | ||
num_positive = len([c for c in cards if c > 0]) | ||
|
||
# either or - we cannot support some positive some negative in the same setting now | ||
assert num_positive == 0 or num_positive == len(cards) | ||
if num_positive > 0: | ||
fields = [] | ||
for card in kwd_data["cards"]: | ||
for field in card["fields"]: | ||
if field["name"] == setting["name"]: | ||
fields.append(field) | ||
assert len(fields) > 1 | ||
fields[0]["card_indices"] = cards | ||
setting["applied_card_indices"] = True | ||
for field in fields[1:]: | ||
field["redundant"] = True | ||
else: | ||
if "negative_shared_fields" not in kwd_data: | ||
kwd_data["negative_shared_fields"] = [] | ||
kwd_data["negative_shared_fields"].append(setting) | ||
|
||
|
||
class SharedFieldHandler(keyword_generation.handlers.handler_base.KeywordHandler): | ||
|
||
def handle(self, kwd_data: typing.Dict[str, typing.Any], settings: typing.Dict[str, typing.Any]) -> None: | ||
"""Transform `kwd_data` based on `settings`.""" | ||
return handle_shared_field(kwd_data, settings) | ||
|
||
def post_process(self, kwd_data: typing.Dict[str, typing.Any]) -> None: | ||
"""Run after all handlers have run.""" | ||
return do_negative_shared_fields(kwd_data) |
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
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 @@ | ||
fix: Options api rework |
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
Oops, something went wrong.