Skip to content

Commit b298ace

Browse files
committed
additional simplification
1 parent 1f0f491 commit b298ace

File tree

3 files changed

+15
-50
lines changed

3 files changed

+15
-50
lines changed

src/pash/preprocessor/pash_preprocessor.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,7 @@
1616
from shasta.ast_node import AstNode
1717

1818
from ast_util import PreprocessedAST, UnparsedScript, unzip
19-
from transformation_options import (
20-
TransformationType,
21-
TransformationState,
22-
AirflowTransformationState,
23-
AbstractTransformationState,
24-
)
19+
from transformation_options import TransformationState
2520
from walk_preprocess import WalkPreprocess, PreprocessContext
2621
from parse import parse_shell_to_asts, from_ast_objects_to_shell
2722
from util import log, logging_prefix, print_time_delta
@@ -90,7 +85,6 @@ def __init__(self, *args, **kwargs):
9085
help="(experimental) interpret the input as a bash script file",
9186
action="store_true",
9287
)
93-
self.set_defaults(preprocess_mode="pash")
9488

9589

9690
@logging_prefix(LOGGING_PREFIX)
@@ -164,7 +158,7 @@ def preprocess(input_script_path, args):
164158

165159
def preprocess_asts(ast_objects, args):
166160
"""
167-
Preprocess AST objects based on the transformation mode.
161+
Preprocess AST objects by replacing candidate dataflow regions.
168162
169163
Args:
170164
ast_objects: List of parsed AST objects
@@ -173,13 +167,7 @@ def preprocess_asts(ast_objects, args):
173167
Returns:
174168
List of preprocessed AST objects
175169
"""
176-
trans_mode = TransformationType(args.preprocess_mode)
177-
178-
if trans_mode is TransformationType.AIRFLOW:
179-
trans_options = AirflowTransformationState()
180-
else:
181-
trans_options = TransformationState()
182-
170+
trans_options = TransformationState()
183171
return replace_ast_regions(ast_objects, trans_options)
184172

185173

@@ -188,7 +176,7 @@ def preprocess_asts(ast_objects, args):
188176

189177
def preprocess_node(
190178
ast_node: AstNode,
191-
trans_options: AbstractTransformationState,
179+
trans_options: TransformationState,
192180
last_object: bool,
193181
) -> PreprocessedAST:
194182
"""
@@ -197,7 +185,7 @@ def preprocess_node(
197185
198186
Parameters:
199187
ast_node (AstNode): The AstNode to parse
200-
trans_options (AbstractTransformationState):
188+
trans_options (TransformationState):
201189
A concrete transformation state instance corresponding to the output target
202190
last_object (bool): Flag for whether this is the last AstNode
203191
@@ -208,7 +196,7 @@ def preprocess_node(
208196
return _pash_walker.walk(ast_node, ctx)
209197

210198

211-
def replace_ast_regions(ast_objects, trans_options: AbstractTransformationState):
199+
def replace_ast_regions(ast_objects, trans_options: TransformationState):
212200
"""
213201
Replace candidate dataflow AST regions with calls to PaSh's runtime.
214202
"""

src/pash/preprocessor/transformation_options.py

Lines changed: 7 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
"""
2-
Transformation options and state classes for AST preprocessing.
2+
Transformation state for AST preprocessing.
33
"""
44

5-
from abc import ABC, abstractmethod
6-
from enum import Enum
75
import os
86
import pickle
97

@@ -20,15 +18,13 @@
2018
RUNTIME_EXECUTABLE = os.path.join(PASH_TOP, "jit_runtime/jit.sh")
2119

2220

23-
class TransformationType(Enum):
24-
"""Types of AST-to-AST transformations."""
21+
class TransformationState:
22+
"""
23+
Transformation state for PaSh preprocessing.
2524
26-
PASH = "pash"
27-
AIRFLOW = "airflow"
28-
29-
30-
class AbstractTransformationState(ABC):
31-
"""Base class for transformation state."""
25+
Manages node IDs and generates replacement AST nodes that call the
26+
PaSh runtime for dataflow region compilation.
27+
"""
3228

3329
def __init__(self):
3430
self._node_counter = 0
@@ -45,16 +41,6 @@ def get_current_id(self):
4541
def get_number_of_ids(self):
4642
return self._node_counter
4743

48-
@abstractmethod
49-
def replace_df_region(
50-
self, asts, disable_parallel_pipelines=False, ast_text=None
51-
) -> AstNode:
52-
pass
53-
54-
55-
class TransformationState(AbstractTransformationState):
56-
"""Standard PaSh transformation state."""
57-
5844
def replace_df_region(
5945
self, asts, disable_parallel_pipelines=False, ast_text=None
6046
) -> AstNode:
@@ -104,12 +90,6 @@ def make_call_to_pash_runtime(
10490
return runtime_node
10591

10692

107-
class AirflowTransformationState(TransformationState):
108-
"""Airflow transformation state (same as standard PaSh for now)."""
109-
110-
pass
111-
112-
11393
def get_shell_from_ast(asts, ast_text=None) -> str:
11494
"""Get shell text from AST, using original text if available."""
11595
if ast_text is None:

src/pash/preprocessor/walk_preprocess.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
from __future__ import annotations
1010
from dataclasses import dataclass
11-
from typing import Any, TYPE_CHECKING
11+
from typing import Any
1212

1313
from shasta.ast_node import (
1414
AstNode,
@@ -21,17 +21,14 @@
2121
)
2222
from shasta.ast_walker import CommandVisitor, command_child_attrs
2323

24-
if TYPE_CHECKING:
25-
from transformation_options import AbstractTransformationState
26-
2724
from ast_util import PreprocessedAST
2825

2926

3027
@dataclass
3128
class PreprocessContext:
3229
"""Context threaded through preprocessing traversal."""
3330

34-
trans_options: Any # AbstractTransformationState
31+
trans_options: Any # TransformationState
3532
last_object: bool = False
3633

3734

0 commit comments

Comments
 (0)