From 0ee34076df0a0f8b04352c1898aa2c87442f0f45 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 26 May 2024 21:03:59 +0200 Subject: [PATCH] feat: optimize imports and streamline processing Removed unused imports across various modules, streamlining the codebase by eliminating the `ast` and `tokenize` modules where not directly utilized. This clean-up not only simplifies the code making it more maintainable but also potentially improves runtime performance by reducing overhead. Additionally, redundant variables and comments that do not contribute to clarity or functionality, such as `script_dir` and detailed notes on module path construction, were pruned to further enhance code readability and efficiency. This change underscores our commitment to maintaining a lean and efficient codebase, facilitating easier updates and modifications in the future. --- src/deuthon/__main__.py | 3 --- src/deuthon/importer.py | 7 ------- src/deuthon/transformer.py | 1 - 3 files changed, 11 deletions(-) diff --git a/src/deuthon/__main__.py b/src/deuthon/__main__.py index fefd73d..a7491cf 100755 --- a/src/deuthon/__main__.py +++ b/src/deuthon/__main__.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -import ast -import tokenize import pathlib import sys import traceback @@ -25,7 +23,6 @@ def main(): if args.file: script_path = pathlib.Path(args.file).absolute() - script_dir = script_path.parent # Read and transpile the German code with open(script_path) as f: diff --git a/src/deuthon/importer.py b/src/deuthon/importer.py index b179247..c215daa 100644 --- a/src/deuthon/importer.py +++ b/src/deuthon/importer.py @@ -32,7 +32,6 @@ class DeuthonSourceLoader(importlib.machinery.SourceFileLoader): def source_to_code(self, data, path, *, _optimize=-1): reader = tokenize.open(path) try: - encoding = reader.encoding source_data = reader.read() finally: reader.close() @@ -122,12 +121,6 @@ class DeuthonModuleFinder(importlib.abc.MetaPathFinder): if deuthon_path: path.extend(deuthon_path.split(os.pathsep)) - # The base name for the file we're trying to find will be the last component of 'fullname' - # e.g., for 'testmodul.submodul.test', we want to end up with 'test.deu' - module_basename = ( - fullname.rpartition(".")[-1] + self.extension - ) # e.g., 'test.deu' - for entry in path: module_full_path = os.path.join( entry, fullname.replace(".", "/") + self.extension diff --git a/src/deuthon/transformer.py b/src/deuthon/transformer.py index 72404e4..f52fa7e 100644 --- a/src/deuthon/transformer.py +++ b/src/deuthon/transformer.py @@ -1,4 +1,3 @@ -import ast import tokenize from io import BytesIO