Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 18 additions & 32 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,35 @@ jobs:
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: '3.8'
cache: 'poetry'
python-version: "3.8"

- name: Install dependencies
run: poetry install
- uses: astral-sh/setup-uv@v6
with:
version: "latest"

- name: Check formatting
run: |
source $(poetry env info --path)/bin/activate
make format-check
run: make format-check

test:
runs-on: ubuntu-latest
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Install poetry
run: pipx install poetry

- name: Set up Python
uses: actions/setup-python@v4
- uses: actions/setup-python@v4
with:
python-version: '3.8'
cache: 'poetry'

- name: Install dependencies
run: poetry install
python-version: "3.8"

- name: Run main
run: make run
- uses: astral-sh/setup-uv@v6
with:
version: "latest"

- name: Test
run: |
source $(poetry env info --path)/bin/activate
make test
run: make test
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/inspectionProfiles/profiles_settings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/smart-home-refactoring-python-kata.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 0 additions & 19 deletions .replit

This file was deleted.

5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ms-python.python",
]
}
15 changes: 15 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python Debugger: Current File",
"type": "debugpy",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
}
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"."
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
23 changes: 23 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run Tests",
"type": "shell",
"command": "make test",
"group": {
"kind": "test",
"isDefault": true
},
},
{
"label": "Format",
"type": "shell",
"command": "make format",
"presentation": {
"reveal": "silent"
},
"problemMatcher": []
},
]
}
19 changes: 13 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
all: test

UV := $(shell command -v uv 2> /dev/null)
SRCS := $(shell git ls-files *.py)

.PHONY: run
run:
./main.py
ifdef UV
RUNNER := uv run
else
RUNNER :=
endif

.PHONY: test
test:
pytest test_*.py
$(RUNNER) pytest test_*.py

.PHONY: format
format:
yapf -i $(SRCS)
$(RUNNER) ruff format $(SRCS)

.PHONY: format-check
format-check:
yapf --diff $(SRCS) \
$(RUNNER) ruff format --check $(SRCS) \
|| (echo "Some files require formatting. Run 'make format' to fix." && exit 1)

.PHONY: clean
clean:
git clean -Xfd

ifndef VERBOSE
.SILENT:
endif
26 changes: 8 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# Smart Home Refactoring Python Kata

[![CI](https://github.com/Coding-Cuddles/smart-home-refactoring-python-kata/actions/workflows/main.yml/badge.svg)](https://github.com/Coding-Cuddles/smart-home-refactoring-python-kata/actions/workflows/main.yml)
[![Replit](https://img.shields.io/badge/Try%20with%20Replit-black?logo=replit)](https://replit.com/new/github/Coding-Cuddles/smart-home-refactoring-python-kata)

## Overview

This kata complements [Clean Code: SOLID, Ep. 13 - Dependency Inversion Principle](https://cleancoders.com/episode/clean-code-episode-13).

In this exercise, you'll practice refactoring code to adhere to the Dependency
Inversion Principle (DIP). You'll be working with a smart home system that
controls different types of lights and an air conditioner.
controls different types of lights and air conditioner.

## Instructions

Expand Down Expand Up @@ -40,7 +39,7 @@ Here are some guidelines to follow:
1. Modify any constructors or method calls as necessary to accommodate the
refactoring.

> **Note**
> [!NOTE]
>
> Remember that in this exercise, we assume all devices are in an ideal state
> and don't account for error cases such as a network connection failure or an
Expand All @@ -58,7 +57,7 @@ implementing two additional scenarios (methods) in `SmartHomeController`:
1. Add the `make_quick_breakfast` scenario to open the blinds and make a
predefined coffee type.
1. Add `Blinds` device class with `open` and `close` methods
(blinds are always powered and does not have on/off function).
(blinds are always powered and does not have an on/off function).
1. Add `make_quick_breakfast` method to `SmartHomeController`.

1. Add automatic vacuum cleaner and the `schedule_night_cleaning` scenario, which
Expand All @@ -69,23 +68,14 @@ implementing two additional scenarios (methods) in `SmartHomeController`:
calling this method, the vacuum cleaner should start cleaning once all
other devices are turned off.

Evaluate whether or not your refactoring made life easier for you, or not.
Evaluate whether your refactoring made life easier for you or not.

## Usage

You can import this project into [Replit](https://replit.com), and it will
handle all dependencies automatically.

### Prerequisites

* [Python 3.8+](https://www.python.org/)
* [pytest](https://pytest.org)
## Prerequisites

### Run main
- [Python 3.8+](https://www.python.org/)
- [pytest](https://pytest.org)

```console
make run
```
## Usage

### Run tests

Expand Down
4 changes: 0 additions & 4 deletions main.py

This file was deleted.

Loading
Loading