Skip to content

Commit 4ba7c46

Browse files
authored
ci!: Move to uv, add Renovate configuration (#131)
1 parent 5cba250 commit 4ba7c46

File tree

10 files changed

+1404
-1854
lines changed

10 files changed

+1404
-1854
lines changed

.github/workflows/publish.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818

19-
- uses: actions/setup-python@v4
19+
- name: Set up Python
20+
uses: astral-sh/setup-uv@v6
2021
with:
21-
python-version: 3.12
22-
23-
- name: Install Poetry
24-
run: pipx install poetry
22+
enable-cache: true
2523

2624
- name: Build Package
27-
run: poetry build
25+
run: uv build
2826

2927
- uses: actions/upload-artifact@v4
3028
with:

.github/workflows/python-test.yml

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -19,40 +19,19 @@ jobs:
1919
matrix:
2020
python-version: ["3.11", "3.12"]
2121

22-
services:
23-
default-database:
24-
image: postgres:15.5-alpine
25-
env:
26-
POSTGRES_HOST_AUTH_METHOD: trust
27-
ports: ["6543:5432"]
28-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
29-
30-
task-processor-database:
31-
image: postgres:15.5-alpine
32-
env:
33-
POSTGRES_HOST_AUTH_METHOD: trust
34-
ports: ["6544:5432"]
35-
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
36-
3722
steps:
3823
- uses: actions/checkout@v4
3924

40-
- uses: actions/setup-python@v4
25+
- name: Set up Python
26+
uses: astral-sh/setup-uv@v6
4127
with:
28+
enable-cache: true
4229
python-version: ${{ matrix.python-version }}
4330

44-
- name: Install Poetry
45-
run: pipx install poetry
46-
47-
- name: Install Dependencies
48-
env:
49-
opts: --with dev
50-
run: make install-packages
51-
5231
- name: Check for missing migrations
5332
env:
5433
opts: --no-input --dry-run --check
55-
run: make django-make-migrations
34+
run: make docker-up django-make-migrations
5635

5736
- name: Check for new typing errors
5837
run: make typecheck

.pre-commit-config.yaml

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ repos:
88
args: [--fix]
99
# Run the formatter.
1010
- id: ruff-format
11-
- repo: https://github.com/python-poetry/poetry
12-
rev: 2.2.1
11+
- repo: https://github.com/astral-sh/uv-pre-commit
12+
rev: 0.9.7
1313
hooks:
14-
- id: poetry-check
15-
- id: poetry-lock
14+
- id: uv-lock
1615
- repo: https://github.com/pre-commit/pre-commit-hooks
1716
rev: v6.0.0
1817
hooks:
@@ -24,11 +23,11 @@ repos:
2423
- id: python-typecheck
2524
name: python-typecheck
2625
language: system
27-
entry: poetry run mypy .
26+
entry: make typecheck
2827
require_serial: true
2928
pass_filenames: false
3029
types: [python]
3130

3231
ci:
33-
skip: [python-typecheck, poetry-lock]
32+
skip: [python-typecheck, uv-lock]
3433
autoupdate_commit_msg: "ci: pre-commit autoupdate"

Makefile

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,64 @@
22

33
DOTENV_OVERRIDE_FILE ?= .env
44

5-
POETRY_VERSION ?= 2.1.3
6-
75
COMPOSE_FILE ?= docker/docker-compose.local.yml
86
COMPOSE_PROJECT_NAME ?= flagsmith-common
97

108
-include $(DOTENV_OVERRIDE_FILE)
119

12-
.PHONY: install-pip
13-
install-pip:
14-
python -m pip install --upgrade pip
10+
.PHONY: install-packages
11+
install-packages: ## Install all required packages
12+
uv sync $(or $(opts),'--all-extras')
1513

16-
.PHONY: install-poetry
17-
install-poetry:
18-
curl -sSL https://install.python-poetry.org | python3 - --version ${POETRY_VERSION}
14+
.PHONY: install-pre-commit ## Install pre-commit hooks
15+
install-pre-commit:
16+
uv run pre-commit install
1917

20-
.PHONY: install-packages
21-
install-packages:
22-
poetry install $(opts)
18+
.PHONY: ensure-dotenv
19+
ensure-dotenv: ## Create an .env file suitable for running tests
20+
@if [ ! -f .env ]; then cp .env-ci .env; echo ".env file created from .env-ci. Please update it with your settings."; fi
2321

2422
.PHONY: install
25-
install: install-pip install-poetry install-packages
23+
install: install-packages install-pre-commit ensure-dotenv ## Ensure the environment is set up
2624

2725
.PHONY: lint
28-
lint:
29-
poetry run pre-commit run -a
26+
lint: ## Run linters
27+
uv run --all-extras pre-commit run --all-files
3028

3129
.PHONY: docker-up
32-
docker-up:
30+
docker-up: ## Start Docker containers
3331
docker compose up --force-recreate --remove-orphans -d
3432
docker compose ps
3533

3634
.PHONY: docker-down
37-
docker-down:
35+
docker-down: ## Stop Docker containers
3836
docker compose down
3937

4038
.PHONY: test
41-
test:
42-
poetry run pytest $(opts)
39+
test: docker-up ## Run all tests
40+
uv run --all-extras pytest $(opts)
4341

4442
.PHONY: typecheck
45-
typecheck:
46-
poetry run mypy .
47-
43+
typecheck: ## Run mypy
44+
uv run --all-extras mypy src tests
4845
.PHONY: django-make-migrations
49-
django-make-migrations:
50-
poetry run python manage.py waitfordb
51-
poetry run python manage.py makemigrations $(opts)
46+
django-make-migrations: ## Create new migrations based on the changes detected to your models
47+
uv run --all-extras python manage.py waitfordb
48+
uv run --all-extras python manage.py makemigrations $(opts)
5249

5350
.PHONY: django-squash-migrations
54-
django-squash-migrations:
55-
poetry run python manage.py waitfordb
56-
poetry run python manage.py squashmigrations $(opts)
51+
django-squash-migrations: ## Squash migrations for apps
52+
uv run --all-extras python manage.py waitfordb
53+
uv run --all-extras python manage.py squashmigrations $(opts)
5754

5855
.PHONY: django-migrate
59-
django-migrate:
60-
poetry run python manage.py waitfordb
61-
poetry run python manage.py migrate
62-
poetry run python manage.py createcachetable
56+
django-migrate: ## Apply migrations to the database
57+
uv run --all-extras python manage.py waitfordb
58+
uv run --all-extras python manage.py migrate
59+
uv run --all-extras python manage.py createcachetable
60+
61+
help:
62+
@echo "Usage: make [target]"
63+
@echo ""
64+
@echo "Available targets:"
65+
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-30s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

README.md

Lines changed: 25 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,28 @@
44

55
Flagsmith's common library
66

7-
### Development Setup
7+
## Local development
88

9-
This project uses [Poetry](https://python-poetry.org/) for dependency management and includes a Makefile to simplify common development tasks.
9+
The project assumes the following tools installed:
1010

11-
#### Prerequisites
11+
- [uv](https://github.com/astral-sh/uv)
12+
- [GNU Make](https://www.gnu.org/software/make/)
1213

13-
- Python >= 3.11
14-
- Make
14+
To list available Makefile targets, run `make help`.
1515

16-
#### Installation
16+
To set up local development environment, run `make install`.
1717

18-
You can set up your development environment using the provided Makefile:
18+
To run linters, run `make lint`.
1919

20-
```bash
21-
# Install everything (pip, poetry, and project dependencies)
22-
make install
20+
To run tests, run `make test`.
2321

24-
# Individual installation steps are also available
25-
make install-pip # Upgrade pip
26-
make install-poetry # Install Poetry
27-
make install-packages # Install project dependencies
28-
```
29-
30-
#### Development
31-
32-
Run linting checks using pre-commit:
33-
34-
```bash
35-
make lint
36-
```
37-
38-
Additional options can be passed to the `install-packages` target:
39-
40-
```bash
41-
# Install with development dependencies
42-
make install-packages opts="--with dev"
43-
44-
# Install with specific extras
45-
make install-packages opts="--extras 'feature1 feature2'"
46-
```
47-
48-
### Usage
22+
## Usage
4923

50-
#### Installation
24+
### Installation
5125

52-
1. `poetry add flagsmith-common`
26+
1. Install all runtime packages: `uv add flagsmith-common[common-core,task-processor]`
5327

54-
2. `poetry add --G dev flagsmith-common[test-tools]` — this will enable the Pytest fixtures. Skipping this step will make Pytest collection fail due to missing dependencies.
28+
2. To enable the Pytest fixtures, run `uv add --G dev flagsmith-common[test-tools]`. Skipping this step will make Pytest collection fail due to missing dependencies.
5529

5630
3. Make sure `"common.core"` is in the `INSTALLED_APPS` of your settings module.
5731
This enables the `manage.py flagsmith` commands.
@@ -61,11 +35,11 @@ This enables the `route` label for Prometheus HTTP metrics.
6135

6236
5. To enable the `/metrics` endpoint, set the `PROMETHEUS_ENABLED` setting to `True`.
6337

64-
#### Test tools
38+
### Test tools
6539

66-
##### Fixtures
40+
#### Fixtures
6741

68-
###### `assert_metric`
42+
##### `assert_metric`
6943

7044
To test your metrics using the `assert_metric` fixture:
7145

@@ -84,44 +58,44 @@ def test_my_code__expected_metrics(assert_metric: AssertMetricFixture) -> None:
8458
)
8559
```
8660

87-
###### `saas_mode`
61+
##### `saas_mode`
8862

8963
The `saas_mode` fixture makes all `common.core.utils.is_saas` calls return `True`.
9064

91-
###### `enterprise_mode`
65+
##### `enterprise_mode`
9266

9367
The `enterprise_mode` fixture makes all `common.core.utils.is_enterprise` calls return `True`.
9468

95-
##### Markers
69+
#### Markers
9670

97-
###### `pytest.mark.saas_mode`
71+
##### `pytest.mark.saas_mode`
9872

9973
Use this mark to auto-use the `saas_mode` fixture.
10074

101-
###### `pytest.mark.enterprise_mode`
75+
##### `pytest.mark.enterprise_mode`
10276

10377
Use this mark to auto-use the `enterprise_mode` fixture.
10478

105-
#### Metrics
79+
### Metrics
10680

10781
Flagsmith uses Prometheus to track performance metrics.
10882

10983
The following default metrics are exposed:
11084

111-
##### Common metrics
85+
#### Common metrics
11286

11387
- `flagsmith_build_info`: Has the labels `version` and `ci_commit_sha`.
11488
- `flagsmith_http_server_request_duration_seconds`: Histogram labeled with `method`, `route`, and `response_status`.
11589
- `flagsmith_http_server_requests_total`: Counter labeled with `method`, `route`, and `response_status`.
116-
- `flagsmith_http_server_response_size_bytes`:Histogram labeled with `method`, `route`, and `response_status`.
90+
- `flagsmith_http_server_response_size_bytes`: Histogram labeled with `method`, `route`, and `response_status`.
11791
- `flagsmith_task_processor_enqueued_tasks_total`: Counter labeled with `task_identifier`.
11892

119-
##### Task Processor metrics
93+
#### Task Processor metrics
12094

12195
- `flagsmith_task_processor_finished_tasks_total`: Counter labeled with `task_identifier`, `task_type` (`"recurring"`, `"standard"`) and `result` (`"success"`, `"failure"`).
12296
- `flagsmith_task_processor_task_duration_seconds`: Histogram labeled with `task_identifier`, `task_type` (`"recurring"`, `"standard"`) and `result` (`"success"`, `"failure"`).
12397

124-
##### Guidelines
98+
#### Guidelines
12599

126100
Try to come up with meaningful metrics to cover your feature with when developing it. Refer to [Prometheus best practices][1] when naming your metric and labels.
127101

0 commit comments

Comments
 (0)