Skip to content

Commit db15d3c

Browse files
committed
feat: propagate-changes-from-template
1 parent 1587b9e commit db15d3c

18 files changed

+267
-122
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

.env.example

Lines changed: 0 additions & 9 deletions
This file was deleted.

.env.sample

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
MPT_API_BASE_URL=http://localhost:8000
2+
MPT_API_TOKEN=<api-token>
3+
# E2E env vars (only needed for development)
4+
MPT_API_TOKEN_CLIENT=<client-api-token>
5+
MPT_API_TOKEN_OPERATIONS=<operations-api-token>
6+
MPT_API_TOKEN_VENDOR=<vendor-api-token>
7+
RP_API_KEY=<rp-api-token>
8+
RP_ENDPOINT=https://reportportal.example.com
9+
RP_LAUNCH=dev-env

.gitignore

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ htmlcov/
4545
.cache
4646
nosetests.xml
4747
coverage.xml
48+
out.xml
4849
*.cover
4950
*.py,cover
5051
.hypothesis/
@@ -159,17 +160,15 @@ cython_debug/
159160
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
160161
#.idea/
161162

162-
.DS_Store
163-
164-
# ignore xlsx temporary files
165-
~$*.xlsx
163+
.devcontainer/
164+
.vscode
166165

167-
# ruff cache
166+
.DS_Store
168167
.ruff_cache
169168
.idea
170169

171-
# VS Code dev container
172-
.devcontainer/
170+
# Makefile
171+
make/local.mk
173172

174173
# E2E report
175174
e2e-report.xml

.pre-commit-config.yaml

Lines changed: 4 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

@@ -39,3 +39,5 @@ repos:
3939
- id: mypy
4040
args: ["--config-file=pyproject.toml", "."]
4141
pass_filenames: false
42+
additional_dependencies:
43+
- python-box==7.3.2

Dockerfile

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

3-
WORKDIR /extension
3+
WORKDIR /mpt_api_client
44

55
RUN uv venv /opt/venv
66

7-
ENV VIRTUAL_ENV=/opt/venv
7+
ENV UV_PROJECT_ENVIRONMENT=/opt/venv
88
ENV PATH=/opt/venv/bin:$PATH
99

1010
FROM base AS build
1111

12-
COPY . /extension
12+
COPY . .
1313

14-
RUN uv sync --frozen --no-cache --all-groups --active
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_api_client /opt/venv /home/appuser
29+
30+
ENV UV_CACHE_DIR=/home/appuser/.cache/uv
31+
32+
USER appuser
33+
1834
CMD ["bash"]

README.md

Lines changed: 93 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,125 @@
1+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=softwareone-platform_mpt-tool&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=softwareone-platform_mpt-tool)
2+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=softwareone-platform_mpt-tool&metric=coverage)](https://sonarcloud.io/summary/new_code?id=softwareone-platform_mpt-tool)
3+
4+
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
5+
16
# mpt-api-python-client
27

38
A Python client for interacting with the MPT API.
49

5-
## Installation
10+
## Documentation
11+
12+
📚 **[Complete Usage Guide](docs/PROJECT_DESCRIPTION.md)**
13+
14+
## Getting started
15+
16+
### Prerequisites
17+
18+
- Docker and Docker Compose plugin (`docker compose` CLI)
19+
- `make`
20+
- [CodeRabbit CLI](https://www.coderabbit.ai/cli) (optional. Used for running review check locally)
21+
22+
### Make targets overview
23+
24+
Common development workflows are wrapped in the `Makefile`. Run `make help` to see the list of available commands.
625

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

947
```bash
10-
uv add mpt-api-client
11-
cp .env.example .env
48+
git clone <repository-url>
49+
```
50+
```bash
51+
cd mpt-api-python-client
1252
```
1353

14-
## Usage
15-
16-
```python
17-
from mpt_api_client import MPTClient
54+
#### 2. Create environment configuration
1855

19-
#client = MPTClient(api_key=os.getenv("MPT_API_KEY"), base_url=os.getenv("MPT_API_URL"))
20-
client = MPTClient() # Will get the api_key and base_url from the environment variables
56+
Copy the sample environment file and update it with your values:
2157

22-
for product in client.catalog.products.iterate():
23-
print(product.name)
58+
```bash
59+
cp .env.sample .env
2460
```
2561

26-
## Async Usage
62+
Edit the `.env` file with your actual configuration values. See the [Configuration](#configuration) section for details on available variables.
2763

28-
```python
29-
import asyncio
30-
from mpt_api_client import AsyncMPTClient
64+
#### 3. Build the Docker images
3165

32-
async def main():
33-
# client = AsyncMPTClient(api_key=os.getenv("MPT_API_KEY"), base_url=os.getenv("MPT_API_URL"))
34-
client = AsyncMPTClient() # Will get the api_key and base_url from the environment variables
35-
async for product in client.catalog.products.iterate():
36-
print(product.name)
66+
Build the development environment:
3767

38-
asyncio.run(main())
68+
```bash
69+
make build
3970
```
4071

41-
## Development
72+
This will create the Docker images with all required dependencies and the virtualenv.
73+
74+
#### 4. Verify the setup
4275

43-
Clone the repository and install dependencies:
76+
Run the test suite to ensure everything is configured correctly:
4477

4578
```bash
46-
git clone https://github.com/albertsola/mpt-api-python-client.git
47-
cd mpt-api-python-client
48-
uv add -r requirements.txt
79+
make test
4980
```
5081

51-
## Testing
82+
You're now ready to start developing! See [Running the client](#running-the-client) for next steps.
83+
5284

53-
Run all validations with:
85+
## Running the client
86+
87+
Before running, ensure your `.env` file is populated.
5488

5589
```bash
56-
make test-all
90+
make run
5791
```
5892

59-
Run pytest with:
93+
## Developer utilities
94+
95+
Useful helper targets during development:
6096

6197
```bash
62-
make test-all
98+
make bash # open a bash shell in the app container
99+
make check # run ruff, flake8, and lockfile checks
100+
make check-all # run checks and tests
101+
make format # auto-format code and imports
102+
make review # check the code in the cli by running CodeRabbit
63103
```
64-
## License
65104

66-
MIT
105+
## Configuration
106+
107+
The following environment variables are typically set in `.env`. Docker Compose reads them when using the Make targets described above.
108+
109+
### Application
110+
111+
| Environment Variable | Default | Example | Description |
112+
|---------------------------------|---------|-------------------------------------------|-------------------------------------------------------------------------------------------|
113+
| `MPT_API_BASE_URL` | - | `https://portal.softwareone.com/mpt` | SoftwareONE Marketplace API URL |
114+
| `MPT_API_TOKEN` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Token |
115+
116+
### E2E
117+
118+
| Environment Variable | Default | Example | Description |
119+
|----------------------------|---------|--------------------------------------|----------------------------------------------|
120+
| `MPT_API_TOKEN_CLIENT` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Client Token |
121+
| `MPT_API_TOKEN_OPERATIONS` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Operations Token |
122+
| `MPT_API_TOKEN_VENDOR` | - | eyJhbGciOiJSUzI1N... | SoftwareONE Marketplace API Vendor Token |
123+
| `RP_API_KEY` | - | pytest_XXXXXXXXXXXXXX | ReportPortal API key |
124+
| `RP_ENDPOINT` | - | `https://reportportal.example.com` | ReportPortal endpoint |
125+
| `RP_LAUNCH` | - | `dev-env` | ReportPortal launch |

docs/PROJECT_DESCRIPTION.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# mpt-tool CLI
2+
3+
mpt-api-python-client is a Python client for interacting with the MPT API
4+
5+
## Installation
6+
7+
Install with pip or your favorite PyPI package manager:
8+
9+
```bash
10+
pip install mpt-api-client
11+
```
12+
13+
```bash
14+
uv add mpt-api-client
15+
```
16+
17+
## Prerequisites
18+
19+
- Python 3.12+ in your environment
20+
21+
## Usage
22+
23+
```python
24+
from mpt_api_client import MPTClient
25+
26+
# client = MPTClient(api_key=<your_api_key>, base_url=<mpt_api_url>)
27+
client = MPTClient() # Will get the api_key and base_url from the environment variables
28+
29+
for product in client.catalog.products.iterate():
30+
print(product.name)
31+
```
32+
33+
## Async Usage
34+
35+
```python
36+
import asyncio
37+
from mpt_api_client import AsyncMPTClient
38+
39+
async def main():
40+
# client = AsyncMPTClient(api_key=<your_api_key>, base_url=<mpt_api_url>)
41+
client = AsyncMPTClient() # Will get the api_key and base_url from the environment variables
42+
async for product in client.catalog.products.iterate():
43+
print(product.name)
44+
45+
asyncio.run(main())
46+
```
47+
48+
## Development
49+
50+
For development purposes, please, check the Readme in the GitHub repository.

make/common.mk

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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
12+
$(RUN) bash -c "ruff format --check . && ruff check . && flake8 . && mypy . && 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+
$(RUN_IT) bash -c "ipython"
24+
25+
test: ## Run test
26+
$(RUN) pytest $(if $(args),$(args), tests/unit)
27+
28+
uv-add: ## Add a production dependency (pkg=<package_name>)
29+
$(call require,pkg)
30+
$(RUN) bash -c "uv add $(pkg)"
31+
$(MAKE) build
32+
33+
uv-add-dev: ## Add a dev dependency (pkg=<package_name>)
34+
$(call require,pkg)
35+
$(RUN) bash -c "uv add --dev $(pkg)"
36+
$(MAKE) build
37+
38+
uv-upgrade: ## Upgrade all packages or a specific package (use pkg="package_name" to target one)
39+
$(RUN) bash -c "uv lock $(if $(pkg),--upgrade-package $(pkg),--upgrade) && uv sync"
40+
$(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)

0 commit comments

Comments
 (0)