Skip to content

Commit 6888d15

Browse files
committed
feat: propagate-changes-from-template
1 parent 5dea70b commit 6888d15

File tree

12 files changed

+142
-39
lines changed

12 files changed

+142
-39
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ indent_size = 2
1212

1313
[*.py]
1414
indent_size = 4
15+
16+
[{Makefile,*.mk}]
17+
indent_style = tab

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,9 @@ cython_debug/
167167
.ruff_cache
168168
.idea
169169

170-
# Specific project gitignore
170+
# Makefile
171+
make/local.mk
172+
173+
# mpt-tool
171174
migrations/
172175
.migrations-state.json
173-
settings.py

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ repos:
2828
- id: flake8
2929
additional_dependencies:
3030
[
31-
Flake8-pyproject==1.2.*,
32-
Flake8-AAA==0.17.*,
31+
flake8-aaa==0.17.*,
32+
flake8-pyproject==1.2.*,
3333
wemake-python-styleguide==1.5.*,
3434
]
3535

Dockerfile

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,33 @@ FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS base
22

33
WORKDIR /mpt_tool
44

5-
COPY . ./
6-
75
RUN uv venv /opt/venv
86

9-
ENV VIRTUAL_ENV=/opt/venv
7+
ENV UV_PROJECT_ENVIRONMENT=/opt/venv
108
ENV PATH=/opt/venv/bin:$PATH
119

1210
FROM base AS build
1311

14-
RUN uv sync --frozen --no-cache --all-groups --active
12+
COPY . .
13+
14+
RUN uv sync --frozen --no-cache --no-dev
1515

1616
FROM build AS dev
1717

18+
RUN uv sync --frozen --no-cache --dev
19+
20+
CMD ["bash"]
21+
22+
FROM build AS prod
23+
24+
RUN rm -rf tests/
25+
26+
RUN groupadd -r appuser && useradd -r -g appuser -m -d /home/appuser appuser && \
27+
mkdir -p /home/appuser/.cache/uv && \
28+
chown -R appuser:appuser /mpt_tool /opt/venv /home/appuser
29+
30+
ENV UV_CACHE_DIR=/home/appuser/.cache/uv
31+
32+
USER appuser
33+
1834
CMD ["bash"]
File renamed without changes.

README.md

Lines changed: 54 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,58 +19,82 @@ to manage both schema and data migrations across multiple backends, ensuring con
1919
- Docker and Docker Compose plugin (`docker compose` CLI)
2020
- `make`
2121
- [CodeRabbit CLI](https://www.coderabbit.ai/cli) (optional. Used for running review check locally)
22-
- Copy .env.sample to .env
22+
2323

2424
### Make targets overview
2525

26-
Common development workflows are wrapped in the `makefile`:
26+
Common development workflows are wrapped in the `Makefile`. Run `make help` to see the list of available commands.
27+
28+
### How the Makefile works
29+
30+
The project uses a modular Makefile structure that organizes commands into logical groups:
31+
32+
- **Main Makefile** (`Makefile`): Entry point that automatically includes all `.mk` files from the `make/` directory
33+
- **Modular includes** (`make/*.mk`): Commands are organized by category:
34+
- `common.mk` - Core development commands (build, test, format, etc.)
35+
- `repo.mk` - Repository management and dependency commands
36+
- `migrations.mk` - Database migration commands (Only available in extension repositories)
37+
- `external_tools.mk` - Integration with external tools
38+
39+
40+
You can extend the Makefile with your own custom commands creating a `local.mk` file inside make folder. This file is
41+
automatically ignored by git, so your personal commands won't affect other developers or appear in version control.
42+
2743

28-
- `make help` – list available commands
29-
- `make bash` – start the app container and open a bash shell
30-
- `make build` – build the application image for development
31-
- `make check` – run code quality checks (ruff, flake8, lockfile check)
32-
- `make check-all` – run checks and tests
33-
- `make format` – apply formatting and import fixes
34-
- `make down` – stop and remove containers
35-
- `make review` – check the code in the cli by running CodeRabbit
36-
- `make run` – run the CLI tool
37-
- `make test` – run the test suite with pytest
44+
### Setup
3845

39-
## Running CLI commands
46+
Follow these steps to set up the development environment:
47+
48+
#### 1. Clone the repository
4049

41-
Run the CLI tool:
4250
```bash
43-
make run
51+
git clone <repository-url>
52+
```
53+
```bash
54+
cd mpt-tool
4455
```
4556

46-
## Running tests
57+
#### 2. Create environment configuration
4758

48-
Tests run inside Docker using the dev configuration.
59+
Copy the sample environment file and update it with your values:
4960

50-
Run the full test suite:
61+
```bash
62+
cp .env.sample .env
63+
```
64+
65+
Edit the `.env` file with your actual configuration values. See the [Configuration](#configuration) section for details on available variables.
66+
67+
In the project root, create and configure the following files.
68+
69+
#### 3. Build the Docker images
70+
71+
Build the development environment:
5172

5273
```bash
53-
make test
74+
make build
5475
```
5576

56-
Pass additional arguments to pytest using the `args` variable:
77+
This will create the Docker images with all required dependencies and the virtualenv.
78+
79+
#### 4. Verify the setup
80+
81+
Run the test suite to ensure everything is configured correctly:
5782

5883
```bash
59-
make test args="-k test_cli -vv"
60-
make test args="tests/test_cli.py"
84+
make test
6185
```
6286

63-
## Pre-commit
87+
You're now ready to start developing! See [Running the cli](#running-the-cli) for next steps.
88+
6489

65-
Checking migrations with pre-commit:
90+
## Running the cli
6691

67-
Add this to your .pre-commit-config.yaml
92+
Before running, ensure your `.env` file is populated.
6893

69-
```yaml
70-
- repo: https://github.com/softwareone-platform/mpt-tool
71-
rev: '' # Use the sha / tag you want to point at
72-
hooks:
73-
- id: check-migrations
94+
Start the cli:
95+
96+
```bash
97+
make run
7498
```
7599

76100
## Developer utilities

docs/PROJECT_DESCRIPTION.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,18 @@ Run `mpt-service-cli --help` to see all available commands and params:
340340
- Create a new migration with the updated logic
341341
- Never modify an already-applied migration in production
342342
343+
## Pre-commit
344+
345+
Checking migrations with pre-commit:
346+
347+
Add this to your .pre-commit-config.yaml
348+
349+
```yaml
350+
- repo: https://github.com/softwareone-platform/mpt-tool
351+
rev: '' # Use the sha / tag you want to point at
352+
hooks:
353+
- id: check-migrations
354+
```
343355
344356
## Development
345357

make/common.mk

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
DC = docker compose -f compose.yaml
2+
RUN = $(DC) run --rm app
3+
RUN_IT = $(DC) run --rm -it app
4+
5+
bash: ## Open a bash shell
6+
$(RUN_IT) bash
7+
8+
build: ## Build images
9+
$(DC) build
10+
11+
check: ## Check code quality with ruff
12+
$(RUN) bash -c "ruff format --check . && ruff check . && flake8 . && uv lock --check"
13+
14+
check-all: check test ## Run checks and tests
15+
16+
down: ## Stop and remove containers
17+
$(DC) down
18+
19+
format: ## Format code
20+
$(RUN) bash -c "ruff check --select I --fix . && ruff format ."
21+
22+
run: ## Run service
23+
$(DC) up
24+
25+
shell: ## Open Django shell
26+
$(RUN_IT) bash -c "swoext shell"
27+
28+
test: ## Run test
29+
$(RUN) pytest $(if $(args),$(args),.)
30+
31+
uv-add: ## Add a production dependency (pkg=<package_name>)
32+
$(call require,pkg)
33+
$(RUN) bash -c "uv add $(pkg)"
34+
$(MAKE) build
35+
36+
uv-add-dev: ## Add a dev dependency (pkg=<package_name>)
37+
$(call require,pkg)
38+
$(RUN) bash -c "uv add --dev $(pkg)"
39+
$(MAKE) build
40+
41+
uv-upgrade: ## Upgrade all packages or a specific package (use pkg="package_name" to target one)
42+
$(RUN) bash -c "uv lock $(if $(pkg),--upgrade-package $(pkg),--upgrade) && uv sync"
43+
$(MAKE) build

make/external_tools.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
review: ## Run CodeRabbit code review in interactive mode. Pass args=<options> to override or include more options
2+
coderabbit review $(args)

make/repo.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
## Add repo-specific targets here. Do not modify the shared *.mk files.

0 commit comments

Comments
 (0)