Skip to content

Commit 3d8a646

Browse files
fix docker compose pathing
1 parent fd20e6c commit 3d8a646

File tree

2 files changed

+40
-46
lines changed

2 files changed

+40
-46
lines changed

app.py

Lines changed: 26 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from textual.app import App, ComposeResult
44
from textual.containers import Container, Horizontal
55
from textual.widgets import Button, Footer, MarkdownViewer, Header, TextArea, Select, Label
6-
from textual import log
76

87
from exercises_utils import EXERCISES_DIR, ExercisesUtils
98
from project_generators.base_project_generator import BaseProjectGenerator
@@ -43,67 +42,57 @@ def compose(self) -> ComposeResult:
4342
def on_mount(self) -> None:
4443
"""Initial setup when the app starts."""
4544
self.show_menu()
45+
menu = self.query_one("#menu")
46+
menu.notify(title="Hello World!", message="Pick an exercise you find interesting, read it by clicking on "
47+
"'View', create a template for a project by clicking on 'Start "
48+
"Project', and once you are done implementing the exercise, "
49+
"you can verify you did everything right by clicking on 'Run "
50+
"Tests'. Pretty Simple. But not easy :)\n\n"
51+
"Also... don't forget to read the README.md file once you click "
52+
"'Start Project'", timeout=30)
4653

4754
def show_menu(self) -> None:
48-
"""Display the menu with available exercises."""
49-
log("entered show menu")
5055
menu = self.query_one("#menu")
5156
menu.remove_children()
57+
5258
exercises = list(EXERCISES_DIR.glob("*.md"))
53-
log(f"exercises = {exercises}")
54-
log(f"map = {self.files_view_names}")
5559
exercise_names = [(self.files_view_names[exercise.stem], exercise.stem) for exercise in exercises]
5660
select_file_widget = Select(options=exercise_names, prompt="Select Exercise", id="exercise_select", classes="menu_widget", tooltip="Select an exercise to preview")
61+
5762
menu.mount(select_file_widget)
5863
menu.mount(Button("View", id="view", variant="primary", classes="menu_widget"))
59-
menu.mount(Button("Run Tests", id="test", variant="success", classes="menu_widget"))
60-
61-
# select_lang_widget = Select(options=[('python', 'python'), ('javascript', 'javascript')], prompt="Select Programming Language", id="lang_select", classes="menu_widget", tooltip="Select a language to create your project's template")
62-
# menu.mount(select_lang_widget)
6364
menu.mount(Button("Start Project", id="start", variant="warning", classes="menu_widget"))
65+
menu.mount(Button("Run Tests", id="test", variant="success", classes="menu_widget"))
6466

6567
async def on_button_pressed(self, event: Button.Pressed) -> None:
66-
"""Handle button press events."""
6768
button_id = event.button.id
6869
select_widget = self.query_one("#exercise_select", Select)
6970
exercise_name = select_widget.value
7071
selected_exercise = EXERCISES_DIR / f"{exercise_name}.md"
7172

72-
# select_lang_widget = self.query_one("#lang_select", Select)
73-
# lang = select_lang_widget.value
74-
75-
if button_id in ('view', 'test'):
76-
if exercise_name == Select.BLANK:
77-
select_widget.notify("Please select a file", severity="error", timeout=5)
78-
return
79-
80-
if button_id == "view":
81-
self.current_markdown_path = selected_exercise
82-
markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer)
83-
await markdown_viewer.go(selected_exercise)
84-
self.query_one("#content").display = True
85-
86-
elif button_id == "test":
87-
log("about to test")
88-
self.run_tests(exercise_name)
89-
90-
if button_id == 'start':
91-
if exercise_name == Select.BLANK:
92-
select_widget.notify("Please select a file", severity="error", timeout=5)
93-
return
94-
# if lang == Select.BLANK:
95-
# select_lang_widget.notify("Please select a language", severity="error")
96-
# return
73+
if exercise_name == Select.BLANK:
74+
select_widget.notify("Please select a file", severity="error", timeout=5)
75+
return
76+
77+
if button_id == "view":
78+
self.current_markdown_path = selected_exercise
79+
markdown_viewer = self.query_one("#markdown_viewer", MarkdownViewer)
80+
await markdown_viewer.go(selected_exercise)
81+
self.query_one("#content").display = True
82+
83+
elif button_id == "test":
84+
self.run_tests(exercise_name)
85+
86+
elif button_id == 'start':
9787
self.start_project(exercise_name)
9888

9989
def start_project(self, exercise_name: str) -> None:
10090
test_output = self.query_one("#test_output", TextArea)
10191
project_path = BaseProjectGenerator().generate(exercise_name)
102-
test_output.notify(f'Creating project structure for lang project {exercise_name}')
92+
test_output.notify(f'Creating project structure for project {exercise_name}')
10393
ExercisesUtils.open_file_in_explorer(project_path)
10494

10595
def run_tests(self, exercise_name: str) -> None:
106-
"""Run tests for the selected exercise and display the output."""
10796
test_output = self.query_one("#test_output", TextArea)
10897
docker_compose_file_name = ExercisesUtils.get_resource_path(f"exercises_test_suites/docker_compose_{exercise_name}.yml")
10998
command = f"docker-compose -f {docker_compose_file_name} up --build"

project_generators/base_project_generator.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import os
22

3+
from exercises_utils import ExercisesUtils
4+
35

46
class BaseProjectGenerator:
57
def generate(self, project_name: str) -> str:
@@ -8,26 +10,24 @@ def generate(self, project_name: str) -> str:
810
Returns the path to the Dockerfile.
911
"""
1012
# Create the project directory
11-
project_dir = os.path.join(os.getcwd(), 'my_solutions', project_name)
13+
project_dir = ExercisesUtils.get_resource_path(f"my_solutions/{project_name}")
14+
# project_dir = os.path.join(os.getcwd(), '', project_name)
1215
src_dir = os.path.join(project_dir, 'src')
1316
os.makedirs(src_dir, exist_ok=True)
1417

1518
# Define a generic Dockerfile content
16-
dockerfile_content = """
19+
dockerfile_content = f"""
1720
# Use an official runtime as a parent image
1821
FROM <runtime_image>
1922
2023
# Set the working directory in the container
21-
WORKDIR /app
22-
23-
# Copy the requirements file into the container
24-
COPY requirements.txt ./
24+
WORKDIR /{project_name}
2525
2626
# Install any dependencies
2727
RUN <install_command>
2828
2929
# Copy the current directory contents into the container at /app
30-
COPY . .
30+
COPY src/ .
3131
3232
# Make port 5000 available to the world outside this container
3333
EXPOSE 5000
@@ -43,10 +43,15 @@ def generate(self, project_name: str) -> str:
4343

4444
# Create a README file with guidelines
4545
readme_content = f"""
46-
# {project_name}
46+
# {' '.join(project_name.split('_')).title()}
47+
48+
##
49+
## Supported Languages?
4750
48-
## Project Setup
51+
**Every language and every API framework is supported.**
52+
You will be required to correctly write a dockerfile (given the template and the guide below), and the tests are on us.
4953
54+
## Project Setup
5055
1. **Install Dependencies**: Ensure you have Docker installed.
5156
2. **Build the Docker Image**: Run the following command in the project directory:
5257
```

0 commit comments

Comments
 (0)