From 877b79da5aa50150bfb10ab770bf32dd18d8d711 Mon Sep 17 00:00:00 2001 From: briantu Date: Tue, 5 Nov 2024 18:31:04 -0500 Subject: [PATCH] Only generated files --- .../antlr_asset_selection/Makefile | 4 -- .../antlr_asset_selection/README.md | 13 +++++- .../antlr_asset_selection.py | 31 ------------- .../antlr_asset_selection/fix_imports.py | 44 ------------------ .../generated/AssetSelectionLexer.py | 11 +++-- .../generated/AssetSelectionListener.py | 7 ++- .../generated/AssetSelectionParser.py | 11 +++-- .../generated/AssetSelectionVisitor.py | 8 +++- .../test_antlr_asset_selection.py | 46 ------------------- 9 files changed, 36 insertions(+), 139 deletions(-) delete mode 100644 python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/Makefile delete mode 100644 python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/antlr_asset_selection.py delete mode 100644 python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/fix_imports.py delete mode 100644 python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/test_antlr_asset_selection.py diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/Makefile b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/Makefile deleted file mode 100644 index 0bb2d0c2fef50..0000000000000 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -generate: - antlr4 -Dlanguage=Python3 -visitor AssetSelection.g4 -o generated - python fix_imports.py - ruff format \ No newline at end of file diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/README.md b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/README.md index 70648999cbd53..08f6482cada27 100644 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/README.md +++ b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/README.md @@ -65,7 +65,16 @@ pip install antlr4-python3-runtime Under the `python_modules/dagster/dagster/_core/definitions/asset_selection` directory, run ```bash -$ antlr4 -Dlanguage=Python3 -visitor AssetSelection.g4 +$ antlr4 -Dlanguage=Python3 -visitor AssetSelection.g4 -o generated ``` -This will generate the lexer, listener, parser, and visitor files from the grammar file `AssetSelection.g4`. +This will generate the following files from the grammar file `AssetSelection.g4` in a `generated` folder: + +- `AssetSelection.interp` +- `AssetSelection.tokens` +- `AssetSelectionLexer.interp` +- `AssetSelectionLexer.py` +- `AssetSelectionLexer.tokens` +- `AssetSelectionListener.py` +- `AssetSelectionParser.py` +- `AssetSelectionVisitor.py` diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/antlr_asset_selection.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/antlr_asset_selection.py deleted file mode 100644 index 3d39e5f73033f..0000000000000 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/antlr_asset_selection.py +++ /dev/null @@ -1,31 +0,0 @@ -from antlr4 import CommonTokenStream, InputStream - -from dagster._annotations import experimental -from dagster._core.definitions.antlr_asset_selection.generated.AssetSelectionLexer import ( - AssetSelectionLexer, -) -from dagster._core.definitions.antlr_asset_selection.generated.AssetSelectionParser import ( - AssetSelectionParser, -) -from dagster._core.definitions.antlr_asset_selection.generated.AssetSelectionVisitor import ( - AssetSelectionVisitor, -) - - -@experimental -class AntlrAssetSelection: - _visitor: AssetSelectionVisitor = AssetSelectionVisitor() - - def __init__(self, selection_str: str): - lexer = AssetSelectionLexer(InputStream(selection_str)) - stream = CommonTokenStream(lexer) - parser = AssetSelectionParser(stream) - self._tree = parser.start() - self._tree_str = self._tree.toStringTree(recog=parser) - - @property - def tree_str(self) -> str: - return self._tree_str - - # def assets(self) -> AssetSelection: - # return AntlrAssetSelection._visitor.visit(self._tree) diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/fix_imports.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/fix_imports.py deleted file mode 100644 index 089bb45cb686a..0000000000000 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/fix_imports.py +++ /dev/null @@ -1,44 +0,0 @@ -def fix_imports(file_path): - with open(file_path, "r") as file: - lines = file.readlines() - updated_lines = [] - i = 0 - while i < len(lines): - line = lines[i] - if "if sys.version_info[1] > 5:" in line or 'if "." in __name__:' in line: - updated_lines.append(lines[i + 1].strip()) - i += 4 - else: - updated_lines.append(line) - i += 1 - with open(file_path, "w") as file: - file.writelines(updated_lines) - - -def add_lines_to_start(file_path, lines_to_add): - with open(file_path, "r") as file: - original_content = file.readlines() - - updated_content = lines_to_add + original_content - - with open(file_path, "w") as file: - file.writelines(updated_content) - - -files = [ - "generated/AssetSelectionLexer.py", - "generated/AssetSelectionListener.py", - "generated/AssetSelectionParser.py", - "generated/AssetSelectionVisitor.py", -] - -for file in files: - fix_imports(file) - add_lines_to_start(file, ["# flake8: noqa\n"]) - if file == "AssetSelectionParser.py": - add_lines_to_start( - file, - [ - "# type: ignore\n", - ], - ) diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionLexer.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionLexer.py index 29999210362a3..0e8afe0cae5fc 100644 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionLexer.py +++ b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionLexer.py @@ -1,9 +1,12 @@ -# flake8: noqa # Generated from AssetSelection.g4 by ANTLR 4.13.2 -from antlr4 import * -from io import StringIO import sys -from typing import TextIO + +from antlr4 import * + +if sys.version_info[1] > 5: + from typing import TextIO +else: + from typing.io import TextIO def serializedATN(): diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionListener.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionListener.py index 076b4d6c01fa1..f371ad15b1950 100644 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionListener.py +++ b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionListener.py @@ -1,7 +1,10 @@ -# flake8: noqa # Generated from AssetSelection.g4 by ANTLR 4.13.2 from antlr4 import * -from .AssetSelectionParser import AssetSelectionParser + +if "." in __name__: + from .AssetSelectionParser import AssetSelectionParser +else: + from AssetSelectionParser import AssetSelectionParser # This class defines a complete listener for a parse tree produced by AssetSelectionParser. diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionParser.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionParser.py index d5811de9a1b99..e310e23417f7e 100644 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionParser.py +++ b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionParser.py @@ -1,10 +1,13 @@ -# flake8: noqa # Generated from AssetSelection.g4 by ANTLR 4.13.2 # encoding: utf-8 -from antlr4 import * -from io import StringIO import sys -from typing import TextIO + +from antlr4 import * + +if sys.version_info[1] > 5: + from typing import TextIO +else: + from typing.io import TextIO def serializedATN(): diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionVisitor.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionVisitor.py index 0fdbd89562319..d3c1480064887 100644 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionVisitor.py +++ b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/generated/AssetSelectionVisitor.py @@ -1,7 +1,11 @@ -# flake8: noqa # Generated from AssetSelection.g4 by ANTLR 4.13.2 from antlr4 import * -from .AssetSelectionParser import AssetSelectionParser + +if "." in __name__: + from .AssetSelectionParser import AssetSelectionParser +else: + from AssetSelectionParser import AssetSelectionParser + # This class defines a complete generic visitor for a parse tree produced by AssetSelectionParser. diff --git a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/test_antlr_asset_selection.py b/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/test_antlr_asset_selection.py deleted file mode 100644 index 927cc8ab48d35..0000000000000 --- a/python_modules/dagster/dagster/_core/definitions/antlr_asset_selection/test_antlr_asset_selection.py +++ /dev/null @@ -1,46 +0,0 @@ -import pytest - -from dagster._core.definitions.antlr_asset_selection.antlr_asset_selection import ( - AntlrAssetSelection, -) - - -@pytest.mark.parametrize( - "selection_str, expected_tree_str", - [ - ('"a"', '(start (expr (assetExpr "a")) )'), - ('sinks("a")', '(start (expr (functionName sinks) ( (expr (assetExpr "a")) )) )'), - ('roots("a")', '(start (expr (functionName roots) ( (expr (assetExpr "a")) )) )'), - ("tag:foo=bar", "(start (expr (attributeExpr tag : (value foo) = (value bar))) )"), - ("owner:billing", "(start (expr (attributeExpr owner : (value billing))) )"), - ( - 'group:"my_group"', - '(start (expr (attributeExpr group : (value "my_group"))) )', - ), - ("kind:my_kind", "(start (expr (attributeExpr kind : (value my_kind))) )"), - ( - "codelocation:my_location", - "(start (expr (attributeExpr codelocation : (value my_location))) )", - ), - ( - '((("a")))', - '(start (expr ( (expr ( (expr ( (expr (assetExpr "a")) )) )) )) )', - ), - ('not not "not"', '(start (expr not (expr not (expr (assetExpr "not")))) )'), - ( - '(roots("a") and owner:billing)*', - '(start (expr (expr ( (expr (expr (functionName roots) ( (expr (assetExpr "a")) )) and (expr (attributeExpr owner : (value billing)))) )) (traversal *)) )', - ), - ( - '++("a"+)', - '(start (expr (traversal + +) (expr ( (expr (expr (assetExpr "a")) (traversal +)) ))) )', - ), - ( - '"a"* and *"b"', - '(start (expr (expr (expr (assetExpr "a")) (traversal *)) and (expr (traversal *) (expr (assetExpr "b")))) )', - ), - ], -) -def test_antlr_tree(selection_str, expected_tree_str): - asset_selection = AntlrAssetSelection(selection_str) - assert asset_selection.tree_str == expected_tree_str