diff --git a/snakelings/__init__.py b/snakelings/__init__.py index 6488a91..ba95da7 100644 --- a/snakelings/__init__.py +++ b/snakelings/__init__.py @@ -1 +1 @@ -__version__ = "1.0.0dev4" \ No newline at end of file +__version__ = "1.0.0dev5" \ No newline at end of file diff --git a/snakelings/__main__.py b/snakelings/__main__.py index 74e33bd..18b74f0 100644 --- a/snakelings/__main__.py +++ b/snakelings/__main__.py @@ -14,6 +14,8 @@ from devgoldyutils import Colours from rich.markdown import Markdown +from . import terminal + from .exercise import Exercise from .execution import test_exercise from .logger import snakelings_logger @@ -42,7 +44,6 @@ def start( True, "--ets/--no-ets", "--enter-to-continue/--no-enter-to-continue", - is_flag = True, help = "ON by default, this enforces you to press enter before moving onto the next exercise." ), wait_to_continue: bool = typer.Option( @@ -76,16 +77,16 @@ def start( for exercise in sorted(handler.get_exercises(), key = lambda x: x.id): no_exercises = False + if exercise_id >= exercise.id and not exercise.id == exercise_id: + continue + if exercise.completed: result, _ = test_exercise(exercise) if result is True: continue - if exercise_id >= exercise.id and not exercise.id == exercise_id: - continue - - console.clear() + terminal.proper_clear() markdown = Markdown(exercise.readme) console.print(markdown) @@ -95,8 +96,8 @@ def start( print(f"\n{Colours.RED.apply('[šŸ›‘ Problem]')} \n{output}") - print(Colours.ORANGE.apply(f"šŸš§ Progress: {exercise.id} / {exercise_count}")) - print(Colours.CLAY.apply(f"āš” Complete the '{exercise.title}' exercise!")) + print(Colours.ORANGE.apply(f"\nšŸš§ Progress: {exercise.id} / {exercise_count}")) + print(Colours.CLAY.apply(f"āš” Complete the '{exercise.title}' exercise!\n")) watch_exercise_complete(exercise) # This will halt here until the exercise is marked complete @@ -153,6 +154,8 @@ def init( snakelings_logger.debug("Copying exercises from snakelings module...") if exercises_folder_path.exists() and next(exercises_folder_path.iterdir(), None) is not None: + # TODO: if it's a hidden file like .pytest_cache for + # example then it shouldn't count as the folder not being empty. snakelings_logger.error( f"The exercises folder ({exercises_folder_path.absolute()}) is not empty!" \ "\nIf you would like to update your exercises use 'snakelings update' instead." diff --git a/snakelings/execution.py b/snakelings/execution.py index 27ba12a..e84b12c 100644 --- a/snakelings/execution.py +++ b/snakelings/execution.py @@ -47,7 +47,10 @@ def test_exercise_with_pytest(exercise: Exercise) -> Tuple[bool, str]: sys.executable, "-m", "pytest", - "--quiet" + "--quiet", + "--log-cli-level=warning", + "--color=yes", + "--tb=line" ] args.extend( diff --git a/snakelings/exercises/2_print_from_scratch/config.toml b/snakelings/exercises/2_print_from_scratch/config.toml index 8a00dba..9fd5220 100644 --- a/snakelings/exercises/2_print_from_scratch/config.toml +++ b/snakelings/exercises/2_print_from_scratch/config.toml @@ -2,6 +2,8 @@ version = 1 title = "Print from scratch" +hint = "Look at what the assertion error is telling you." + [pytest] test_scripts = [ {module = "test_stdout.py"} diff --git a/snakelings/exercises/2_print_from_scratch/test_stdout.py b/snakelings/exercises/2_print_from_scratch/test_stdout.py index 14e9f86..fd00ff2 100644 --- a/snakelings/exercises/2_print_from_scratch/test_stdout.py +++ b/snakelings/exercises/2_print_from_scratch/test_stdout.py @@ -14,4 +14,4 @@ def test_output(capsys): fuzzy_value = fuzz.ratio(captured.out, EXCEPTED_OUTPUT) - assert fuzzy_value > 80 \ No newline at end of file + assert fuzzy_value > 80, "You're not printing 'Hello, Snakelings!', check your code again." \ No newline at end of file diff --git a/snakelings/exercises/3_assign_variable/config.toml b/snakelings/exercises/3_assign_variable/config.toml index 5957f26..9732cbe 100644 --- a/snakelings/exercises/3_assign_variable/config.toml +++ b/snakelings/exercises/3_assign_variable/config.toml @@ -2,9 +2,6 @@ version = 1 title = "Assign a varible" -[code] -execute_first = true - [pytest] test_scripts = [ {module = "test_kitty_amount.py"} diff --git a/snakelings/exercises/4_assign_variable_wo_equal/config.toml b/snakelings/exercises/4_assign_variable_wo_equal/config.toml index 3e1735e..a85c519 100644 --- a/snakelings/exercises/4_assign_variable_wo_equal/config.toml +++ b/snakelings/exercises/4_assign_variable_wo_equal/config.toml @@ -2,10 +2,6 @@ version = 1 title = "Assign a varible" -[code] -use_pytest = true -execute_first = true - [pytest] test_scripts = [ {module = "test_meow_meow.py"} diff --git a/snakelings/exercises/4_assign_variable_wo_equal/readme.md b/snakelings/exercises/4_assign_variable_wo_equal/readme.md index 289fcef..7183b63 100644 --- a/snakelings/exercises/4_assign_variable_wo_equal/readme.md +++ b/snakelings/exercises/4_assign_variable_wo_equal/readme.md @@ -1,3 +1,4 @@ +# Let's assign some variables! (2nd Edition) Okay now, same thing as the last exercise but we're gonna change some *stuff* and you must keep the `:int` there. # The Task! diff --git a/snakelings/exercises/5_basic_math/config.toml b/snakelings/exercises/5_basic_math/config.toml index 6c4f6da..bf839ca 100644 --- a/snakelings/exercises/5_basic_math/config.toml +++ b/snakelings/exercises/5_basic_math/config.toml @@ -2,7 +2,6 @@ version = 1 [code] execute_first = true -use_pytest = true [pytest] test_scripts = [ diff --git a/snakelings/terminal.py b/snakelings/terminal.py new file mode 100644 index 0000000..33e9669 --- /dev/null +++ b/snakelings/terminal.py @@ -0,0 +1,17 @@ +import os +import sys + +__all__ = () + +def proper_clear(): + """ + Handles clearing the terminal cross platform **properly**. + WIP! Only supports Linux and Windows atm. + """ + + if sys.platform == "win32": + os.system("clear") + + # Simply using the clear command won't work on terminals + # that have scrollback and will lead to side effects. + os.system("echo -ne '\033c'") \ No newline at end of file