Skip to content

Commit

Permalink
Merge pull request #3 from NarrativeScience/morearguments
Browse files Browse the repository at this point in the history
Allow more arguments in the custom tag methods
  • Loading branch information
jdrake authored Mar 30, 2021
2 parents 1616e9b + e9040ff commit 6deecc6
Show file tree
Hide file tree
Showing 33 changed files with 134 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ ignore = E203,E501,E731,W503,W605
import-order-style = google
# Packages added in this list should be added to the setup.cfg file as well
application-import-names =
pypants
fluxio_parser
exclude =
*vendor*
.venv
Expand Down
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ repos:
args: [--markdown-linebreak-ext=md]
# Need to define stages explicitly since `default_stages` was not being respected
stages: [commit]
- id: end-of-file-fixer

- repo: local
hooks:
Expand Down
4 changes: 2 additions & 2 deletions fluxio_parser/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Main exports"""

from .parser import parse_project_tree # noqa: F401
from fluxio_parser.parser import parse_project_tree # noqa: F401

__version__ = "0.3.0"
__version__ = "0.3.1"
4 changes: 2 additions & 2 deletions fluxio_parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import ast

from .transformers import ScriptTransformer
from .visitors import ScriptVisitor
from fluxio_parser.transformers import ScriptTransformer
from fluxio_parser.visitors import ScriptVisitor


def parse_project_tree(
Expand Down
4 changes: 2 additions & 2 deletions fluxio_parser/resource_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import ast
from typing import Any, Optional

from .exceptions import assert_supported_operation
from .util import CallableOption, GET_VALUE_MAP
from fluxio_parser.exceptions import assert_supported_operation
from fluxio_parser.util import CallableOption, GET_VALUE_MAP


def get_subscribe_status(node: Any, visitor: Optional[ast.NodeVisitor]) -> str:
Expand Down
20 changes: 11 additions & 9 deletions fluxio_parser/states/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
from .base import State
from .choice import ChoiceState
from .fail import FailState
from .map_ import MapState
from .parallel import ParallelState
from .pass_ import PassState
from .succeed import SucceedState
from .tasks import create_task_state, TaskState
from .wait import WaitState
"""Contains exports for the states subpackage"""
from fluxio_parser.states.base import State
from fluxio_parser.states.choice import ChoiceState
from fluxio_parser.states.fail import FailState
from fluxio_parser.states.map_ import MapState
from fluxio_parser.states.parallel import ParallelState
from fluxio_parser.states.pass_ import PassState
from fluxio_parser.states.succeed import SucceedState
from fluxio_parser.states.tasks import create_task_state
from fluxio_parser.states.tasks.base import TaskState
from fluxio_parser.states.wait import WaitState
9 changes: 6 additions & 3 deletions fluxio_parser/states/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import astor
import networkx as nx

from ..util import hash_node
from fluxio_parser.util import hash_node


class StateMachineFragment:
Expand All @@ -24,10 +24,12 @@ def __init__(self, state_graph: nx.DiGraph, key: str, ast_node: Any) -> None:
self._source = astor.to_source(ast_node).strip()
self._hash = hash_node(ast_node)

def __str__(self):
def __str__(self) -> str:
"""Returns string representation of the object"""
return str(self.key)

def __repr__(self):
def __repr__(self) -> str:
"""Returns REPR representation of the object"""
return f"{self.__class__.__name__}(key={self.key})"

def _set_end_or_next(self, data: Dict) -> Dict:
Expand All @@ -40,6 +42,7 @@ def _set_end_or_next(self, data: Dict) -> Dict:
Returns:
modified input data
"""
edges = self.edges
if len(edges) == 0:
Expand Down
16 changes: 11 additions & 5 deletions fluxio_parser/states/choice.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
"""Contains the classes that represent the AWS Step Functions Choice State"""
import ast
from typing import Any, Dict
from typing import Any, Dict, TYPE_CHECKING

from ..exceptions import assert_supported_operation, UnsupportedOperation
from ..util import convert_input_data_ref, hash_node
from .base import State, StateMachineFragment
from fluxio_parser.exceptions import assert_supported_operation, UnsupportedOperation
from fluxio_parser.states.base import State, StateMachineFragment
from fluxio_parser.util import convert_input_data_ref, hash_node

if TYPE_CHECKING:
import networkx as nx

# Map of either:
# * tuple of:
Expand Down Expand Up @@ -220,12 +223,14 @@ class ChoiceState(State):
"""

def __init__(self, state_graph: "nx.DiGraph", key: str, ast_node: Any) -> None:
"""
"""Initializer
Args:
state_graph: DAG of state machine fragments with edges between them
key: Key of the fragment in the state machine's States value. This only
really applies to States, not generic fragments.
ast_node: AST node for this fragment in the .sfn file
"""
super().__init__(state_graph, key, ast_node)
self.choice_branches = []
Expand All @@ -242,6 +247,7 @@ def add_choice_branch(self, node: Any) -> ChoiceBranch:
Returns:
new ChoiceBranch instance
"""
choice_branch = ChoiceBranch(
self.state_graph, f"ChoiceBranch-{hash_node(node)}", node
Expand Down
2 changes: 1 addition & 1 deletion fluxio_parser/states/fail.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains the class that represents the AWS Step Functions Fail State"""
from typing import Dict

from .base import State
from fluxio_parser.states.base import State


class FailState(State):
Expand Down
22 changes: 17 additions & 5 deletions fluxio_parser/states/map_.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
"""Contains the classes that represent the AWS Step Functions Map State"""
import ast
from typing import Any, Dict, Optional
from typing import Any, Dict, Optional, TYPE_CHECKING

from ..util import CallableOption, convert_input_data_ref, GET_VALUE_MAP, parse_options
from .base import State
from fluxio_parser.states.base import State
from fluxio_parser.util import (
CallableOption,
convert_input_data_ref,
GET_VALUE_MAP,
parse_options,
)

if TYPE_CHECKING:
import networkx as nx

# Map of task option name to an option schema
OPTION_MAP = {
Expand Down Expand Up @@ -51,15 +59,17 @@ def __init__(
state_graph: "nx.DiGraph",
key: str,
ast_node: Any,
iterator: "StateMachineVisitor",
iterator: "StateMachineVisitor", # noqa: F821
) -> None:
"""
"""Initializer
Args:
state_graph: DAG of state machine fragments with edges between them
key: Key of the fragment in the state machine's States value. This only
really applies to States, not generic fragments.
ast_node: AST node for this fragment in the .sfn file
iterator: State machine visitor for the iterator function
"""
super().__init__(state_graph, key, ast_node)
self.iterator = iterator
Expand All @@ -77,6 +87,7 @@ def _get_input_path(self) -> str:
Returns:
input path string
"""
if len(self.ast_node.value.args) > 0:
return convert_input_data_ref(self.ast_node.value.args[0])
Expand All @@ -91,6 +102,7 @@ def _get_result_path(self) -> Optional[str]:
Returns:
result path string or None
"""
if isinstance(self.ast_node, ast.Assign) and len(self.ast_node.targets) > 0:
return convert_input_data_ref(self.ast_node.targets[0])
Expand Down
4 changes: 2 additions & 2 deletions fluxio_parser/states/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@

import networkx as nx

from .base import State
from fluxio_parser.states.base import State

if TYPE_CHECKING:
from ..visitors import StateMachineVisitor
from fluxio_parser.visitors import StateMachineVisitor


class ParallelState(State):
Expand Down
13 changes: 9 additions & 4 deletions fluxio_parser/states/pass_.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

import astor

from ..constants import INVALID_RESULT_PATH_PATTERN, RESERVED_INPUT_DATA_KEYS
from ..exceptions import assert_supported_operation, UnsupportedOperation
from ..util import convert_input_data_ref
from .base import State
from fluxio_parser.constants import (
INVALID_RESULT_PATH_PATTERN,
RESERVED_INPUT_DATA_KEYS,
)
from fluxio_parser.exceptions import assert_supported_operation, UnsupportedOperation
from fluxio_parser.states.base import State
from fluxio_parser.util import convert_input_data_ref


class PassState(State):
Expand Down Expand Up @@ -67,6 +70,7 @@ def _parse_result(self) -> Any:
Returns:
result value
"""
if isinstance(self.ast_node, ast.Assign):
source = astor.to_source(self.ast_node.value).strip()
Expand Down Expand Up @@ -94,6 +98,7 @@ def _parse_result_path(self) -> str:
Returns:
result path string
"""
if isinstance(self.ast_node, ast.Assign):
result_path = convert_input_data_ref(self.ast_node.targets[0])
Expand Down
9 changes: 3 additions & 6 deletions fluxio_parser/states/succeed.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains the class that represents the AWS Step Functions Succeed State"""
from typing import Dict

from .base import State
from fluxio_parser.states.base import State


class SucceedState(State):
Expand All @@ -12,15 +12,12 @@ class SucceedState(State):
See: https://docs.aws.amazon.com/step-functions/latest/dg/amazon-states-language-succeed-state.html
For example::
return
resolves to::
For example, ``return`` resolves to::
{
"Type": "Succeed"
}
"""

TERMINAL = True
Expand Down
17 changes: 9 additions & 8 deletions fluxio_parser/states/tasks/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
"""Contains a factory function for creating new Task state instances"""
from typing import Any, Union

from ...util import parse_options
from .base import OPTION_MAP, TaskState
from .codebuild import CodeBuildTaskState
from .ecs import ECSTaskState
from .ecs_worker import ECSWorkerTaskState
from .lambda_function import LambdaTaskState
from .lambda_pexpm_runner import LambdaPEXPMRunnerTaskState
from .state_machine import StateMachineTaskState
from fluxio_parser.states.tasks.base import OPTION_MAP
from fluxio_parser.states.tasks.codebuild import CodeBuildTaskState
from fluxio_parser.states.tasks.ecs import ECSTaskState
from fluxio_parser.states.tasks.ecs_worker import ECSWorkerTaskState
from fluxio_parser.states.tasks.lambda_function import LambdaTaskState
from fluxio_parser.states.tasks.lambda_pexpm_runner import LambdaPEXPMRunnerTaskState
from fluxio_parser.states.tasks.state_machine import StateMachineTaskState
from fluxio_parser.util import parse_options

#: Map of service key to task state class
TASK_STATE_MAP = {
Expand Down Expand Up @@ -37,6 +37,7 @@ def create_task_state(
Returns:
new task state
"""
service = visitor.attributes.get("service", "lambda")
options = {}
Expand Down
15 changes: 9 additions & 6 deletions fluxio_parser/states/tasks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,22 @@

import astor

from ...constants import INVALID_RESULT_PATH_PATTERN, RESERVED_INPUT_DATA_KEYS
from ...exceptions import assert_supported_operation
from ...transformers import DataDictTransformer
from ...util import (
from fluxio_parser.constants import (
INVALID_RESULT_PATH_PATTERN,
RESERVED_INPUT_DATA_KEYS,
)
from fluxio_parser.exceptions import assert_supported_operation
from fluxio_parser.states.base import State, StateMachineFragment
from fluxio_parser.states.tasks.retry import Retry, RETRY_OPTION_MAP
from fluxio_parser.transformers import DataDictTransformer
from fluxio_parser.util import (
CallableOption,
convert_input_data_ref,
GET_VALUE_MAP,
hash_node,
parse_options,
serialize_error_name,
)
from ..base import State, StateMachineFragment
from .retry import Retry, RETRY_OPTION_MAP


def convert_data_dict(node: Any, visitor: ast.NodeVisitor) -> str:
Expand Down
2 changes: 1 addition & 1 deletion fluxio_parser/states/tasks/codebuild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import json
from typing import Dict, Set

from .base import TaskState
from fluxio_parser.states.tasks.base import TaskState


class CodeBuildTaskState(TaskState):
Expand Down
2 changes: 1 addition & 1 deletion fluxio_parser/states/tasks/ecs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains class for a Task State that runs an ECS task"""
from typing import Dict, Set

from .base import TaskState
from fluxio_parser.states.tasks.base import TaskState


class ECSTaskState(TaskState):
Expand Down
2 changes: 1 addition & 1 deletion fluxio_parser/states/tasks/ecs_worker.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Contains class for a Task State that feeds an ECS worker"""
from typing import Dict, Set

from .base import TaskState
from fluxio_parser.states.tasks.base import TaskState


class ECSWorkerTaskState(TaskState):
Expand Down
4 changes: 2 additions & 2 deletions fluxio_parser/states/tasks/lambda_function.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Contains class used to represent a Task State that integrates with Lambda"""
from typing import Dict, Set

from .base import TaskState
from .retry import Retry
from fluxio_parser.states.tasks.base import TaskState
from fluxio_parser.states.tasks.retry import Retry


class LambdaTaskState(TaskState):
Expand Down
4 changes: 2 additions & 2 deletions fluxio_parser/states/tasks/lambda_pexpm_runner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Contains a class representing a Task State for Lambda via the PEXPM Runner"""
from typing import Dict, Set

from .base import TaskState
from .retry import Retry
from fluxio_parser.states.tasks.base import TaskState
from fluxio_parser.states.tasks.retry import Retry


class LambdaPEXPMRunnerTaskState(TaskState):
Expand Down
2 changes: 1 addition & 1 deletion fluxio_parser/states/tasks/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import ast
from typing import Dict, List

from ...util import CallableOption, GET_VALUE_MAP, serialize_error_name # noqa
from fluxio_parser.util import CallableOption, GET_VALUE_MAP, serialize_error_name

RETRY_OPTION_MAP = {
"on_exceptions": CallableOption(
Expand Down
Loading

0 comments on commit 6deecc6

Please sign in to comment.