Skip to content

Commit

Permalink
Update mage_to_python_utils.py
Browse files Browse the repository at this point in the history
  • Loading branch information
JarcauCristian authored Nov 18, 2024
1 parent 2f38b42 commit 11d585d
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions mage_to_cwl/mage_to_python_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,18 @@ def visit_Module(self, node):
node.body = [self.visit(stmt) for stmt in node.body if stmt is not None]
return node

def remove_unused_code(self, code):
try:
tree = ast.parse(code)

transformer = UnusedCodeRemover()
sanitized_tree = transformer.visit(tree)

sanitized_code = ast.unparse(sanitized_tree)
return sanitized_code
except Exception as e:
print(f"Error while removing unused code: {e}")
return code
def remove_unused_code(code):
try:
tree = ast.parse(code)

transformer = RemoveUnusedCode()
sanitized_tree = transformer.visit(tree)

sanitized_code = ast.unparse(sanitized_tree)
return sanitized_code
except Exception as e:
print(f"Error while removing unused code: {e}")
return code


class MageToPythonTransformer(ast.NodeTransformer):
Expand Down Expand Up @@ -234,8 +234,7 @@ def remove_imports_with_word(code_string: str, word: str, block_name: str, previ
cleaned_tree.body.insert(1, pandas_import)

cleaned_code = ast.unparse(cleaned_tree)
cleaner = RemoveUnusedCode()
cleaned_code = cleaner.remove_unused_code(cleaned_code)
cleaned_code = remove_unused_code(cleaned_code)
return cleaned_code, transformer.env_vars


Expand Down

0 comments on commit 11d585d

Please sign in to comment.