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"
49 changes: 20 additions & 29 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,49 +11,40 @@ jobs:
runs-on: ubuntu-latest

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

- name: Install poetry
run: pipx install poetry

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

- name: Install dependencies
run: poetry install
- uses: astral-sh/setup-uv@v9.0.0
with:
version: "latest"
prune-cache: true

- 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@v7

- name: Install poetry
run: pipx install poetry

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

- name: Install dependencies
run: poetry install
- uses: astral-sh/setup-uv@v9.0.0
with:
version: "latest"
prune-cache: true

- name: Run main
run: make run

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

This file was deleted.

41 changes: 28 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,28 +1,43 @@
all: test
COLOR_CYAN := \033[36m
COLOR_RESET := \033[0m

SRCS := $(shell git ls-files *.py)
SRCS := $(shell git ls-files '*.py')

.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: run
run:
./main.py
run: ## Run the sample entry point
uv run python main.py

.PHONY: test
test:
pytest test_*.py
test: ## Run tests
uv run pytest test_*.py

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

.PHONY: format-check
format-check:
yapf --diff $(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
97 changes: 87 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Hyper-optimized telemetry kata in Python

[![CI](https://github.com/Coding-Cuddles/hyper-optimized-telemetry-python-kata/actions/workflows/main.yml/badge.svg)](https://github.com/Coding-Cuddles/hyper-optimized-telemetry-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/hyper-optimized-telemetry-python-kata)
[![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)

## Overview

Expand Down Expand Up @@ -98,28 +99,104 @@ type as allocated by the system:
| `unsigned int` | 32 bit | 0 | +4_294_967_295 |
| `unsigned long` | 64 bit | 0 | +18_446_744_073_709_551_615 |

## Usage
Setup is complete when the existing test suite passes.

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

### Prerequisites
Required:

* [Python 3.8+](https://www.python.org/)
* [pytest](https://pytest.org)
- [Git](https://git-scm.com/downloads)
- [uv](https://docs.astral.sh/uv/getting-started/installation/)

### Run main
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/hyper-optimized-telemetry-python-kata.git
```

2. Enter the repository directory:

```console
cd hyper-optimized-telemetry-python-kata
```

3. Run the existing 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 `65 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

Implement `TelemetryBuffer.to_buffer()` and `TelemetryBuffer.from_buffer()` in
`telemetry_buffer.py`. `bit_converter.py` contains the integer conversion helpers.

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 passes.

## Run the sample entry point

Use Make when it is installed:

```console
make run
```

### Run tests
Otherwise, run `main.py` through `uv` directly:

```console
make test
uv run python main.py
```

The command prints `Hello World!`.

## Make command reference

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

| Command | Result |
| ------------------- | --------------------------------------- |
| `make all` | Run the test suite |
| `make help` | Show the command reference |
| `make run` | Run the sample entry point |
| `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 |

## Credits and references

* <https://exercism.org/tracks/csharp/exercises/hyper-optimized-telemetry>
1 change: 0 additions & 1 deletion bit_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ def _int_to_bytes_helper(value, length, *, signed=False):


class BitConverter:

@staticmethod
def int16_to_bytes(value):
"""Convert the specified 16-bit signed integer value to bytes."""
Expand Down
Loading