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
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* @Coding-Cuddles/kata-maintainers
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: 2

updates:
- package-ecosystem: "uv"
directory: "/"
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
18 changes: 10 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- uses: actions/setup-python@v4
- uses: actions/setup-python@v7
with:
python-version: "3.8"
python-version: "3.11"

- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v9.0.0
with:
version: "latest"
prune-cache: true

- name: Check formatting
run: make format-check
Expand All @@ -31,15 +32,16 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v7

- uses: actions/setup-python@v4
- uses: actions/setup-python@v7
with:
python-version: "3.8"
python-version: "3.11"

- uses: astral-sh/setup-uv@v6
- uses: astral-sh/setup-uv@v9.0.0
with:
version: "latest"
prune-cache: true

- name: Test
run: make test
42 changes: 25 additions & 17 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,31 +1,39 @@
all: test
COLOR_CYAN := \033[36m
COLOR_RESET := \033[0m

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

ifdef UV
RUNNER := uv run
else
RUNNER :=
endif
.DEFAULT_GOAL := help

.PHONY: all
all: test ## Run tests

.PHONY: help
help: ## Show this help message
@awk 'BEGIN {FS = ":.*##"; printf "Usage: make [options] $(COLOR_CYAN)[target] ...$(COLOR_RESET)\n\n"} \
/^[a-zA-Z_-]+:.*##/ {printf " $(COLOR_CYAN)%-20s$(COLOR_RESET) %s\n", $$1, $$2}' \
$(MAKEFILE_LIST)

.PHONY: test
test:
$(RUNNER) pytest test_*.py
test: ## Run tests
uv run pytest test_*.py

.PHONY: format
format:
$(RUNNER) ruff format $(SRCS)
format: ## Format Python sources in place
uv run ruff format $(SRCS)

.PHONY: format-check
format-check:
$(RUNNER) ruff format --check $(SRCS) \
format-check: ## Fail if Python sources require formatting
uv run ruff format --check $(SRCS) \
|| (echo "Some files require formatting. Run 'make format' to fix." && exit 1)

.PHONY: clean
clean:
git clean -Xfd
clean: ## Remove generated caches
find . \( -path ./.git -o -path ./.venv -o -path ./venv \) -prune \
-o -type d -name __pycache__ -exec rm -rf {} +
rm -rf .pytest_cache .ruff_cache
rm -f .coverage .coverage.*

ifndef VERBOSE
ifneq ($(VERBOSE),1)
.SILENT:
endif
85 changes: 78 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# 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)
[![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

Refactor the smart-home controller toward the Dependency Inversion Principle without changing its
behavior. Setup is complete when all four tests pass.

## Overview

Expand Down Expand Up @@ -72,13 +77,79 @@ Evaluate whether your refactoring made life easier for you or not.

## Prerequisites

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

- [Git](https://git-scm.com/downloads)
- [uv](https://docs.astral.sh/uv/getting-started/installation/)

Optional:

- [GNU Make](https://www.gnu.org/software/make/), for shorter commands. Every required task also
has a direct `uv` command.

You do not need to install Python or pytest separately. `uv` installs a compatible Python version
and the locked project dependencies when needed.

## Set up the kata

1. Clone the repository:

```console
git clone https://github.com/Coding-Cuddles/smart-home-refactoring-python-kata.git
```

2. Enter the repository directory:

```console
cd smart-home-refactoring-python-kata
```

3. Run the tests. Use Make when it is installed:

```console
make test
```

Otherwise, run pytest through `uv` directly:

```console
uv run pytest
```

The first run may install Python and the project dependencies. Setup is complete when pytest
reports `4 passed`.

If the command fails with `uv: command not found`, install
[uv](https://docs.astral.sh/uv/getting-started/installation/) and repeat this step.

## Work on the kata

1. Refactor `SmartHomeController` and its devices in `smart_home.py` without changing their
observable behavior.

2. Run the tests after each change. Use Make when it is installed:

```console
make test
```

Otherwise, run pytest through `uv` directly:

```console
uv run pytest
```

Continue when the test run completes without failures.

## Usage
## Make command reference

### Run tests
Make is optional. Run `make` or `make help` to list these commands in the terminal.

```console
make test
```
| Command | Result |
| ------------------- | --------------------------------------- |
| `make all` | Run the test suite |
| `make help` | Show the available Make targets |
| `make test` | Run the test suite |
| `make format` | Format tracked Python files |
| `make format-check` | Check formatting without changing files |
| `make clean` | Remove generated caches |
12 changes: 8 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,19 @@ name = "smart-home-refactoring-python-kata"
version = "1.0.0"
description = "Smart home refactoring kata in Python"
authors = [{ name = "Codding Cuddles" }]
requires-python = ">=3.8"
requires-python = ">=3.11"

dependencies = [
"pytest>=8.0",
"ruff>=0.11.0"
"pytest>=9.1.1"
]

[dependency-groups]
dev = [
"ruff>=0.16.1"
]

[tool.ruff]
target-version = "py38"
target-version = "py311"
line-length = 100

[tool.ruff.format]
Expand Down
Loading