From 34747280011e875e75f2027113f41d8fb599764a Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 19:58:44 -0300 Subject: [PATCH 1/3] move utils folder to root --- cli/commands/analyze.py | 2 +- cli/commands/export/export.py | 2 +- cli/commands/hello.py | 2 +- cli/commands/version.py | 2 +- spice/analyze.py | 2 +- {spice/utils => utils}/__init__.py | 0 {spice/utils => utils}/get_lexer.py | 0 7 files changed, 5 insertions(+), 5 deletions(-) rename {spice/utils => utils}/__init__.py (100%) rename {spice/utils => utils}/get_lexer.py (100%) diff --git a/cli/commands/analyze.py b/cli/commands/analyze.py index 2ec16c4..76f4e01 100644 --- a/cli/commands/analyze.py +++ b/cli/commands/analyze.py @@ -1,6 +1,6 @@ from InquirerPy import inquirer -from cli.utils.get_translation import get_translation +from utils.get_translation import get_translation from spice.analyze import analyze_file diff --git a/cli/commands/export/export.py b/cli/commands/export/export.py index 7af48a3..c8e6ff6 100644 --- a/cli/commands/export/export.py +++ b/cli/commands/export/export.py @@ -5,7 +5,7 @@ from rich.console import Console from rich.table import Table -from cli.utils.get_translation import get_translation +from utils.get_translation import get_translation def export_results(results, format_type, output_file, messages): """ diff --git a/cli/commands/hello.py b/cli/commands/hello.py index f58f7a9..f50fcea 100644 --- a/cli/commands/hello.py +++ b/cli/commands/hello.py @@ -1,6 +1,6 @@ from rich import print # this add colors to the printed text -from cli.utils.get_translation import get_translation +from utils.get_translation import get_translation def hello_command(LANG_FILE): diff --git a/cli/commands/version.py b/cli/commands/version.py index 2e9111e..71ee7fa 100644 --- a/cli/commands/version.py +++ b/cli/commands/version.py @@ -1,7 +1,7 @@ import os from rich import print # this add colors to the printed text -from cli.utils.get_translation import get_translation +from utils.get_translation import get_translation def version_command(LANG_FILE, CURRENT_DIR): diff --git a/spice/analyze.py b/spice/analyze.py index 3c4eaa6..9545c49 100644 --- a/spice/analyze.py +++ b/spice/analyze.py @@ -46,7 +46,7 @@ def analyze_file(file_path: str, selected_stats=None): # only put the code through the lexer and proceed with tokenization if needed if any(stat in selected_stats for stat in ["function_count"]): # get the lexer for the code's language - from spice.utils.get_lexer import get_lexer_for_file + from utils.get_lexer import get_lexer_for_file LexerClass = get_lexer_for_file(file_path) # tokenize the code via lexer diff --git a/spice/utils/__init__.py b/utils/__init__.py similarity index 100% rename from spice/utils/__init__.py rename to utils/__init__.py diff --git a/spice/utils/get_lexer.py b/utils/get_lexer.py similarity index 100% rename from spice/utils/get_lexer.py rename to utils/get_lexer.py From 5437096de0f122349573a7fcee40e4cbd5565045 Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 20:00:27 -0300 Subject: [PATCH 2/3] move get translation into utils --- cli/utils/__init__.py | 0 {cli/utils => utils}/get_translation.py | 0 2 files changed, 0 insertions(+), 0 deletions(-) delete mode 100644 cli/utils/__init__.py rename {cli/utils => utils}/get_translation.py (100%) diff --git a/cli/utils/__init__.py b/cli/utils/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/cli/utils/get_translation.py b/utils/get_translation.py similarity index 100% rename from cli/utils/get_translation.py rename to utils/get_translation.py From 7f49f36dbe6a6aaf6c39f71fb3d57f3a5961d6af Mon Sep 17 00:00:00 2001 From: ManfredHair Date: Tue, 29 Apr 2025 20:02:03 -0300 Subject: [PATCH 3/3] create get langague util --- utils/get_lang.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 utils/get_lang.py diff --git a/utils/get_lang.py b/utils/get_lang.py new file mode 100644 index 0000000..83e5fbc --- /dev/null +++ b/utils/get_lang.py @@ -0,0 +1,22 @@ +import os + + +# this will read the file extension and return the correct langague +def get_lexer_for_file(file_path): + _, ext = os.path.splitext(file_path) + + if ext == ".rb": + return "ruby" + + elif ext == ".py": + from lexers.python.pythonlexer import PythonLexer + return "python" + + elif ext == ".js": + return "javascript" + + elif ext == ".go": + return "go" + + else: + raise ValueError(f"Unsupported file extension: {ext}") \ No newline at end of file