Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
ImShyMike committed Jan 26, 2025
1 parent 1beebf1 commit 3eca7ba
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
10 changes: 7 additions & 3 deletions eryx/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

from eryx.__init__ import CURRENT_VERSION
from eryx.packages.packages import (
DEFAULT_SERVER,
delete_package,
install,
list_packages,
Expand All @@ -17,7 +18,6 @@
from eryx.runtime.repl import start_repl
from eryx.runtime.runner import run_code
from eryx.server.ide import start_ide
from eryx.packages.packages import DEFAULT_SERVER

init(autoreset=True)
current_path = os.path.dirname(os.path.abspath(__file__))
Expand Down Expand Up @@ -106,15 +106,19 @@ def main():
)

# 'package uninstall' subcommand
uninstall_parser = package_subparsers.add_parser("uninstall", help="Uninstall a package")
uninstall_parser = package_subparsers.add_parser(
"uninstall", help="Uninstall a package"
)
uninstall_parser.add_argument("package", type=str, help="Package to uninstall")

# 'package list' subcommand
package_subparsers.add_parser("list", help="List all installed packages")

# 'package upload' subcommand
upload_parser = package_subparsers.add_parser("upload", help="Upload a package")
upload_parser.add_argument("package_folder", type=str, help="Package folder to upload")
upload_parser.add_argument(
"package_folder", type=str, help="Package folder to upload"
)
upload_parser.add_argument(
"--server",
type=str,
Expand Down
4 changes: 1 addition & 3 deletions eryx/runtime/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -706,9 +706,7 @@ def eval_assignment_expression(

if isinstance(node.assigne, Identifier):
value = assignment_helper(node.assigne, node, environment)
environment.assign_variable(
node.assigne.symbol, value
)
environment.assign_variable(node.assigne.symbol, value)
return value

if isinstance(node.assigne, MemberExpression):
Expand Down
12 changes: 6 additions & 6 deletions eryx/tests/run_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,19 @@ def test_eryx_code(test_folder: str, capfd: pytest.CaptureFixture):
test_ast = parser.produce_ast(test_code)

expected_ast = read_file(ast_expected_path)
assert (
pprint(test_ast, use_color=False, print_output=False) == expected_ast
), f"AST for {test_folder} does not match expected result."
assert pprint(test_ast, use_color=False, print_output=False) == expected_ast, (
f"AST for {test_folder} does not match expected result."
)

# Step 2: Evaluate the AST
evaluate(test_ast, environment)

# Step 3: Check printed output
captured = capfd.readouterr()
expected_output = read_file(output_expected_path)
assert (
captured.out.strip() == expected_output
), f"Printed output for {test_folder} does not match expected output."
assert captured.out.strip() == expected_output, (
f"Printed output for {test_folder} does not match expected output."
)


if __name__ == "__main__":
Expand Down
22 changes: 14 additions & 8 deletions eryx/utils/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,27 @@ def syntax_error(
source_code: str, pos: tuple[int, int, int], error_message: str
) -> None:
"""Handle a syntax error."""
line, col, length = pos # Unpack the position tuple
line, col, length = pos # Unpack the position tuple

line_text = get_line_strings(source_code, line) # Get a snippet of the code
line_text = get_line_strings(source_code, line) # Get a snippet of the code

error_line = f"{Fore.CYAN}{str(line).rjust(3)}:{Fore.RESET} {line_text}" # Format the error line
error_line = f"{Fore.CYAN}{str(line).rjust(3)}:{Fore.RESET} {line_text}" # Format the error line

marker = "^" * length # Under the error line, add a marker to show where the error is
marker = (
"^" * length
) # Under the error line, add a marker to show where the error is

line_number_size = len(str(line).rjust(3)) # Get the size of the line number
line_number_size = len(str(line).rjust(3)) # Get the size of the line number

positioned_marker = marker.rjust(col + line_number_size + 1 + len(marker)) # Position the marker
positioned_marker = marker.rjust(
col + line_number_size + 1 + len(marker)
) # Position the marker

formatted_marker = f"{Fore.YELLOW}{positioned_marker}{Fore.RESET}" # Format the marker
formatted_marker = (
f"{Fore.YELLOW}{positioned_marker}{Fore.RESET}" # Format the marker
)

error_msg = f"{Fore.RED}SyntaxError{Fore.RESET}: {error_message}" # Format the error message
error_msg = f"{Fore.RED}SyntaxError{Fore.RESET}: {error_message}" # Format the error message

# pylint pls dont crash this time
raise SyntaxError(f"{error_line}\n{formatted_marker}\n{error_msg}")

0 comments on commit 3eca7ba

Please sign in to comment.