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
19 changes: 10 additions & 9 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- name: Set up Python 3.13
uses: actions/setup-python@v2
- uses: actions/checkout@v7

- name: Install uv
uses: astral-sh/setup-uv@v8.2.0
with:
python-version: 3.13
enable-cache: true

- name: Set up Python 3.13
run: uv python install 3.13

- name: Install dependencies
run: |
make venv
make install-deps
run: uv sync

- name: Run py.test
run: |
make pytest
run: uv run pytest
76 changes: 22 additions & 54 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,47 @@ SHELL := /bin/bash
.SILENT:
.DEFAULT_GOAL := help

SYS_PY3=$(shell which python3)
VENV_DIR=./venv
VENV_PY3=$(VENV_DIR)/bin/python
VENV_PIP3=$(VENV_DIR)/bin/pip
UV=uv
SRC=tasks/ tests/

LAST_TASK_NUM=$(shell find tasks -name 'task*.py' | sort -V | tail -1 | sed -r 's/tasks\/task([0-9]*).*/\1/' | sed -E 's/^0+//' )
NEW_TASK_NAME=$(shell printf 'task%04d' $$(( ${LAST_TASK_NUM} + 1)) )
NEW_TEST_NAME=$(shell printf 'test_task%04d' $$(( ${LAST_TASK_NUM} + 1)) )

.PHONY: venv
## Create virtual environment
## Create virtual environment with uv
venv:
$(SYS_PY3) -m venv $(VENV_DIR)
$(UV) venv

.PHONY: install-deps
## Update pip and install all requirements from requirements.txt
install-deps: requirements.txt
$(VENV_PIP3) install --upgrade pip setuptools wheel && $(VENV_PIP3) install -r requirements.txt
## Sync all dependencies from pyproject.toml/uv.lock
install-deps: pyproject.toml
$(UV) sync

.PHONY: lock
## Regenerate uv.lock from pyproject.toml
lock:
$(UV) lock

.PHONY: pytest
## Run pytest for testing
pytest: clean-pyc
$(VENV_PY3) -m py.test
$(UV) run pytest

.PHONY: isort
## Run isort linter
isort:
$(VENV_PY3) -m isort tasks/
$(VENV_PY3) -m isort tests/
$(UV) run isort $(SRC)

.PHONY: black
## Run black linter
black:
$(VENV_PY3) -m black tasks/
$(VENV_PY3) -m black tests/
$(UV) run black $(SRC)

.PHONY: flake8
## Run flake8 linter
flake8:
$(VENV_PY3) -m flake8 tasks/
$(VENV_PY3) -m flake8 tests/

$(UV) run flake8 $(SRC)

.PHONY: test
## Run all linters and tests
Expand Down Expand Up @@ -81,41 +80,10 @@ clean: clean-cache clean-pyc
.PHONY: help
## Show this help message
help:
@echo "$$(tput bold)Available rules:$$(tput sgr0)"
@echo
@sed -n -e "/^## / { \
h; \
s/.*//; \
:doc" \
-e "H; \
n; \
s/^## //; \
t doc" \
-e "s/:.*//; \
G; \
s/\\n## /---/; \
s/\\n/ /g; \
p; \
}" ${MAKEFILE_LIST} \
| LC_ALL='C' sort --ignore-case \
| awk -F '---' \
-v ncol=$$(tput cols) \
-v indent=19 \
-v col_on="$$(tput setaf 6)" \
-v col_off="$$(tput sgr0)" \
'{ \
printf "%s%*s%s ", col_on, -indent, $$1, col_off; \
n = split($$2, words, " "); \
line_length = ncol - indent; \
for (i = 1; i <= n; i++) { \
line_length -= length(words[i]) + 1; \
if (line_length <= 0) { \
line_length = ncol - indent - length(words[i]) - 1; \
printf "\n%*s ", -indent, " "; \
} \
printf "%s ", words[i]; \
} \
printf "\n"; \
}' \
| more $(shell test $(shell uname) == Darwin && echo '--no-init --raw-control-chars')
@printf "\033[1mAvailable rules:\033[0m\n\n"
@awk 'BEGIN { FS = ":" } \
/^## / { doc = substr($$0, 4); next } \
/^[a-zA-Z0-9_-]+:/ { if (doc) printf " \033[36m%-18s\033[0m %s\n", $$1, doc; doc = "" } \
{ doc = "" }' $(MAKEFILE_LIST) \
| LC_ALL='C' sort --ignore-case

15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,28 @@

Задачки с собеседований, LeetCode, CodeWars (решаю их на Python)

Зависимости и окружение управляются через [uv](https://docs.astral.sh/uv/). Установить uv можно по [инструкции](https://docs.astral.sh/uv/getting-started/installation/).

## Как запустить

```shell
# Создаем виртуальное окружение с дефолтным для системы python3
make venv
# Устанавливаем зависимости
# Создаём виртуальное окружение и ставим все зависимости из pyproject.toml/uv.lock
make install-deps
# Запускаем все тесты (так же запускаются линтеры)
make test
# Запускаем только линтеры
make lint
```

Можно работать с uv и напрямую, без make:

```shell
# Установить зависимости
uv sync
# Запустить тесты
uv run pytest
```

## Добавить свою задачку

```shell
Expand Down
28 changes: 28 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
[project]
name = "interview-task"
version = "0.1.0"
description = "Задачки с собеседований, LeetCode, CodeWars (решаю их на Python)"
readme = "README.md"
requires-python = ">=3.9"
license = { text = "MIT" }
authors = [{ name = "Michael Savin", email = "jtprogru@gmail.com" }]
dependencies = []

[dependency-groups]
dev = [
"black==25.1.0",
"flake8==7.1.2",
"isort==6.0.1",
"pytest==8.3.5",
]

[tool.uv]
package = false

[tool.black]
line-length = 120
target-version = ['py38', 'py39']
include = '\.pyi?$'

[tool.isort]
profile = "black"
line_length = 120

[tool.pytest.ini_options]
testpaths = ["tests"]
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

Loading