Skip to content

Commit

Permalink
Migrate away from Tox to UV and Make (#84)
Browse files Browse the repository at this point in the history
* Migrate away from Tox to UV and Make
* Add --frozen to uv run
* Combine optional deps into dev
  • Loading branch information
MichaelThamm authored Dec 4, 2024
1 parent e27da3a commit 37878a4
Show file tree
Hide file tree
Showing 8 changed files with 1,518 additions and 116 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,43 @@ __pycache__/
*.py[cod]
.idea
.vscode/

# UV-related files
requirements*.txt
.venv/

# Local .terraform directories
**/.terraform/*

# .tfstate files
*.tfstate
*.tfstate.*

# Crash log files
crash.log
crash.*.log

# Exclude all .tfvars files, which are likely to contain sensitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
*.tfvars
*.tfvars.json

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
.terraform.lock.hcl
66 changes: 66 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
PROJECT := $(dir $(abspath $(lastword $(MAKEFILE_LIST))))

SRC := $(PROJECT)src
TESTS := $(PROJECT)tests
ALL := $(SRC) $(TESTS)

export PYTHONPATH = $(PROJECT):$(PROJECT)/lib:$(SRC)
export PY_COLORS=1

# Update uv.lock with the latest deps
lock:
uv lock --upgrade --no-cache

# Generate requirements.txt from pyproject.toml
requirements:
uv export --frozen --no-hashes --format=requirements-txt -o requirements.txt

# Lint the code
lint:
uv run --frozen --isolated --extra dev \
codespell $(PROJECT) \
--skip $(PROJECT).git \
--skip $(PROJECT).venv \
--skip $(PROJECT)build \
--skip $(PROJECT)lib
uv run --frozen --isolated --extra dev \
ruff check $(ALL)
uv run --frozen --isolated --extra dev \
ruff format --check --diff $(ALL)

# Run static checks
static:
uv run --frozen --isolated --extra dev pyright

# Format the code
fmt:
uv run --frozen --isolated --extra dev \
ruff check --fix-only $(ALL)
uv run --frozen --isolated --extra dev \
ruff format $(ALL)

# Run unit tests
unit:
uv run --frozen --isolated --extra dev \
coverage run \
--source=$(SRC) \
-m pytest \
--tb native \
--verbose \
--capture=no \
$(TESTS)/unit \
$(ARGS)
uv run --frozen --isolated --extra dev \
coverage report

# Run integration tests
integration:
uv run --frozen --isolated --extra dev \
pytest \
--verbose \
--exitfirst \
--capture=no \
--tb native \
--log-cli-level=INFO \
$(TESTS)/integration \
$(ARGS)
20 changes: 18 additions & 2 deletions charmcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ bases:
- name: ubuntu
channel: "22.04"


parts:
charm:
build-snaps:
- astral-uv
build-packages:
- git
- libffi-dev
- libssl-dev
- pkg-config

charm-binary-python-packages:
- pydantic>2.0
- pydantic-core
override-build: |
make requirements
craftctl default
# charm-requirements defaults to requirements.txt, but without setting it (counter-intuitive)
# the charm does not respect the requirements.txt when generated dynamically during build.
charm-requirements: [requirements.txt]
prime:
- -*.charm
- -.venv
- -CONTRIBUTING.md
- -Makefile
- -pyproject.toml
- -README.md
- -tests/
- -uv.lock
- -*.egg-info
1 change: 0 additions & 1 deletion metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ requires:
interface: mimir_cluster
limit: 1


storage:
data:
type: filesystem
Expand Down
33 changes: 33 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,36 @@
[project]
name = "mimir-worker-k8s"
version = "0.0" # this is in fact irrelevant
requires-python = "==3.10.*" # https://packages.ubuntu.com/jammy/python3

dependencies = [
"ops>=1.5.0",
# Charm relation interfaces
"pydantic",

# ---PYDEPS---
"cosl>=0.0.43",
# lib/charms/tempo_coordinator_k8s/v0/charm_tracing.py
"opentelemetry-exporter-otlp-proto-http==1.21.0",
]

[project.optional-dependencies]
dev = [
# Linting
"ruff",
"codespell",
# Static
"pyright",
# Unit
"pytest",
"coverage[toml]",
# Integration
"minio",
"tenacity",
"juju",
"pytest-operator",
]

# Testing tools configuration
[tool.coverage.run]
branch = true
Expand Down
8 changes: 0 additions & 8 deletions requirements.txt

This file was deleted.

105 changes: 0 additions & 105 deletions tox.ini

This file was deleted.

Loading

0 comments on commit 37878a4

Please sign in to comment.