Skip to content

Commit

Permalink
refactor: updates "filter" variables to avoid clash with builtin func…
Browse files Browse the repository at this point in the history
…tion (#72)

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 authored Oct 31, 2023
1 parent 0dafb63 commit e93a4e1
Show file tree
Hide file tree
Showing 10 changed files with 31 additions and 26 deletions.
4 changes: 2 additions & 2 deletions tests/trestlebot/tasks/test_assemble_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,13 +96,13 @@ def test_assemble_task_with_skip(tmp_trestle_dir: str, skip_list: List[str]) ->

mock = Mock(spec=AuthorObjectBase)

filter = ModelFilter(skip_list, ["*"])
model_filter = ModelFilter(skip_list, ["*"])

assemble_task = AssembleTask(
working_dir=tmp_trestle_dir,
authored_model=AuthoredType.CATALOG.value,
markdown_dir=cat_md_dir,
filter=filter,
model_filter=model_filter,
)

with patch(
Expand Down
4 changes: 2 additions & 2 deletions tests/trestlebot/tasks/test_regenerate_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ def test_regenerate_task_with_skip(tmp_trestle_dir: str, skip_list: List[str]) -

mock = Mock(spec=AuthorObjectBase)

filter = ModelFilter(skip_list, ["*"])
model_filter = ModelFilter(skip_list, ["*"])

regenerate_task = RegenerateTask(
working_dir=tmp_trestle_dir,
authored_model=AuthoredType.CATALOG.value,
markdown_dir=cat_md_dir,
filter=filter,
model_filter=model_filter,
)

with patch(
Expand Down
4 changes: 2 additions & 2 deletions tests/trestlebot/tasks/test_rule_transform_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ def test_rule_transform_task_with_skip(tmp_trestle_dir: str) -> None:
setup_rules_view(trestle_root, test_comp, test_rules_dir)
transformer = ToRulesYAMLTransformer()

filter = ModelFilter([test_comp], [])
model_filter = ModelFilter([test_comp], [])
rule_transform_task = RuleTransformTask(
tmp_trestle_dir, test_rules_dir, transformer, filter=filter
tmp_trestle_dir, test_rules_dir, transformer, model_filter=model_filter
)
return_code = rule_transform_task.execute()
assert return_code == 0
Expand Down
7 changes: 4 additions & 3 deletions trestlebot/entrypoints/autosync.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def run(self, args: argparse.Namespace) -> None:
logger.error("Must set ssp_index_path when using SSP as oscal model.")
sys.exit(const.ERROR_EXIT_CODE)

filter: ModelFilter = ModelFilter(
# Allow any model to be skipped from the args, by default include all
model_filter: ModelFilter = ModelFilter(
skip_patterns=comma_sep_to_list(args.skip_items),
include_patterns=["*"],
)
Expand All @@ -133,7 +134,7 @@ def run(self, args: argparse.Namespace) -> None:
authored_model=args.oscal_model,
markdown_dir=args.markdown_path,
ssp_index_path=args.ssp_index_path,
filter=filter,
model_filter=model_filter,
)
pre_tasks.append(assemble_task)
else:
Expand All @@ -145,7 +146,7 @@ def run(self, args: argparse.Namespace) -> None:
authored_model=args.oscal_model,
markdown_dir=args.markdown_path,
ssp_index_path=args.ssp_index_path,
filter=filter,
model_filter=model_filter,
)
pre_tasks.append(regenerate_task)
else:
Expand Down
6 changes: 3 additions & 3 deletions trestlebot/entrypoints/create_cd.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,23 @@ def run(self, args: argparse.Namespace) -> None:

# In this case we only want to do the transformation and generation for this component
# definition, so we skip all other component definitions and components.
workspace_filter: ModelFilter = ModelFilter(
model_filter: ModelFilter = ModelFilter(
[], [args.compdef_name, args.component_title, f"{RULE_PREFIX}*"]
)

rule_transform_task: RuleTransformTask = RuleTransformTask(
working_dir=args.working_dir,
rules_view_dir=RULES_VIEW_DIR,
rule_transformer=transformer,
filter=workspace_filter,
model_filter=model_filter,
)
pre_tasks.append(rule_transform_task)

regenerate_task = RegenerateTask(
working_dir=args.working_dir,
authored_model=AuthoredType.COMPDEF.value,
markdown_dir=args.markdown_path,
filter=workspace_filter,
model_filter=model_filter,
)
pre_tasks.append(regenerate_task)

Expand Down
5 changes: 3 additions & 2 deletions trestlebot/entrypoints/rule_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def run(self, args: argparse.Namespace) -> None:
validation_handler: ValidationHandler = ValidationHandler(parameter_validation)
transformer: ToRulesYAMLTransformer = ToRulesYAMLTransformer(validation_handler)

filter: ModelFilter = ModelFilter(
# Allow any model to be skipped from the args, by default include all
model_filter: ModelFilter = ModelFilter(
skip_patterns=comma_sep_to_list(args.skip_items),
include_patterns=["*"],
)
Expand All @@ -72,7 +73,7 @@ def run(self, args: argparse.Namespace) -> None:
working_dir=args.working_dir,
rules_view_dir=args.rules_view_path,
rule_transformer=transformer,
filter=filter,
model_filter=model_filter,
)
pre_tasks: List[TaskBase] = [rule_transform_task]

Expand Down
7 changes: 4 additions & 3 deletions trestlebot/tasks/assemble_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
authored_model: str,
markdown_dir: str,
ssp_index_path: str = "",
filter: Optional[ModelFilter] = None,
model_filter: Optional[ModelFilter] = None,
) -> None:
"""
Initialize assemble task.
Expand All @@ -50,13 +50,14 @@ def __init__(
authored_model: String representation of model type
markdown_dir: Location of directory to write Markdown in
ssp_index_path: Path of ssp index JSON in the workspace
filter: Optional filter to apply to the task to include or exclude models from processing
model_filter: Optional filter to apply to the task to include or exclude models
from processing
"""

self._authored_model = authored_model
self._markdown_dir = markdown_dir
self._ssp_index_path = ssp_index_path
super().__init__(working_dir, filter)
super().__init__(working_dir, model_filter)

def execute(self) -> int:
"""Execute task"""
Expand Down
6 changes: 3 additions & 3 deletions trestlebot/tasks/base_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,16 @@ class TaskBase(ABC):
Abstract base class for tasks with a work directory.
"""

def __init__(self, working_dir: str, filter: Optional[ModelFilter]) -> None:
def __init__(self, working_dir: str, model_filter: Optional[ModelFilter]) -> None:
"""
Initialize base task.
Args:
working_dir: Working directory to complete operations in.
filter: Model filter to use for this task.
model_filter: Model filter to use for this task.
"""
self._working_dir = working_dir
self.filter: Optional[ModelFilter] = filter
self.filter: Optional[ModelFilter] = model_filter

@property
def working_dir(self) -> str:
Expand Down
7 changes: 4 additions & 3 deletions trestlebot/tasks/regenerate_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
authored_model: str,
markdown_dir: str,
ssp_index_path: str = "",
filter: Optional[ModelFilter] = None,
model_filter: Optional[ModelFilter] = None,
) -> None:
"""
Initialize regenerate task.
Expand All @@ -50,13 +50,14 @@ def __init__(
authored_model: String representation of model type
markdown_dir: Location of directory to write Markdown in
ssp_index_path: Path of ssp index JSON in the workspace
filter: Optional filter to apply to the task to include or exclude models from processing.
model_filter: Optional filter to apply to the task to include or exclude models
from processing.
"""

self._authored_model = authored_model
self._markdown_dir = markdown_dir
self._ssp_index_path = ssp_index_path
super().__init__(working_dir, filter)
super().__init__(working_dir, model_filter)

def execute(self) -> int:
"""Execute task"""
Expand Down
7 changes: 4 additions & 3 deletions trestlebot/tasks/rule_transform_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def __init__(
working_dir: str,
rules_view_dir: str,
rule_transformer: ToRulesYAMLTransformer,
filter: Optional[ModelFilter] = None,
model_filter: Optional[ModelFilter] = None,
) -> None:
"""
Initialize transform task.
Expand All @@ -55,7 +55,8 @@ def __init__(
working_dir: Working directory to complete operations in
rule_view_dir: Location of directory containing components with to read rules from
rule_transformer: Transformer to use for rule transformation to TrestleRule
filter: Optional filter to apply to the task to include or exclude models from processing.
model_filter: Optional filter to apply to the task to include or exclude models
from processing.
Notes:
The rule_view_dir is expected to be a directory containing directories of
Expand All @@ -66,7 +67,7 @@ def __init__(

self._rule_view_dir = rules_view_dir
self._rule_transformer: ToRulesYAMLTransformer = rule_transformer
super().__init__(working_dir, filter)
super().__init__(working_dir, model_filter)

def execute(self) -> int:
"""Execute task"""
Expand Down

0 comments on commit e93a4e1

Please sign in to comment.