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
12 changes: 4 additions & 8 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/python-3/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/devcontainers/python:3-3.15-trixie

ARG VARIANT=“3.7-bullseye”
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
ENV PYTHONOPTIMIZE 1
ENV PYTHONUNBUFFERED TRUE
RUN apt-get update && apt-get install gnupg2 -y
COPY --from=ghcr.io/astral-sh/uv:0.13.8 /uv /uvx /usr/local/bin/

ENV PYTHONUNBUFFERED=1
84 changes: 29 additions & 55 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"VARIANT": "3.10-bullseye",
"NODE_VERSION": "lts/*"
}
},
"customizations": {
"vscode": {
"settings": {
"editor.defaultFormatter": "ms-python.black-formatter",
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.venvFolders": [
"~/.virtualenvs",
"~/.local/share/virtualenvs"
],
"python.terminal.activateEnvInCurrentTerminal": true,
"python.terminal.activateEnvironment": true,
"python.languageServer": "Pylance",
"python.analysis.indexing": true,
"python.analysis.completeFunctionParens": true,
"python.analysis.autoImportCompletions": true,
"python.analysis.inlayHints.variableTypes": false,
"python.analysis.typeCheckingMode": "strict",
"python.linting.pylintEnabled": false,
"vsintellicode.python.completionsEnabled": true,
"vsintellicode.sql.completionsEnabled": true,
"intellicodeCompletions.language.python": true,
"python.envFile": "${workspaceFolder}/.env",
"python.linting.mypyEnabled": true
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-python.isort",
"ms-python.black-formatter",
"GitHub.codespaces",
"ms-vscode-remote.remote-containers",
"VisualStudioExptTeam.vscodeintellicode",
"VisualStudioExptTeam.vscodeintellicode-completions",
"VisualStudioExptTeam.intellicode-api-usage-examples"
]
}
},
"postCreateCommand": "pipenv install --dev",
"waitFor": "postCreateCommand",
"remoteUser": "vscode",
"features": {
"git": "os-provided",
"github-cli": "latest"
}
}
"name": "Python Mopé",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "${workspaceFolder}/.venv/bin/python",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.ruff": "explicit",
"source.organizeImports.ruff": "explicit"
}
}
},
"extensions": [
"ms-python.python",
"charliermarsh.ruff",
"astral-sh.ty"
]
}
},
"postCreateCommand": "uv sync --locked",
"waitFor": "postCreateCommand",
"remoteUser": "vscode"
}
87 changes: 72 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,86 @@
name: build

on:
push:
branches: [ master ]
branches: [master]
pull_request:
branches: [ master ]
branches: [master]
workflow_call:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.13.8"
enable-cache: true
- name: Install Python and dependencies
run: |
uv python install
uv sync --locked
- name: Lint and check formatting
run: |
uv run --locked ruff check .
uv run --locked ruff format --check .
- name: Check types
run: uv run --locked ty check
- name: Verify release version
if: github.event_name == 'release'
env:
RELEASE_TAG: ${{ github.event.release.tag_name }}
run: |
uv run --locked python - <<'PY'
import os
from importlib.metadata import version

package_version = version("python-mope")
tag = os.environ["RELEASE_TAG"]
if tag not in {package_version, f"v{package_version}"}:
raise SystemExit(f"Release tag {tag!r} does not match {package_version}")
PY
- name: Build distributions
run: uv build --no-sources
- name: Upload distributions
uses: actions/upload-artifact@v7
with:
name: distributions
path: dist/*
if-no-files-found: error

test:
needs: build
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.11", "3.12", "3.13", "3.14", "3.15"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/checkout@v7
- name: Install uv and Python ${{ matrix.python-version }}
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
version: "0.13.8"
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pipenv
pipenv install --dev
- name: Lint with Black
enable-cache: true
- name: Download distributions
uses: actions/download-artifact@v8
with:
name: distributions
path: dist
- name: Install dependencies and built wheel
run: |
pipenv run black --check .
- name: Test with pytest
uv sync --locked
uv pip install --no-deps --reinstall dist/*.whl
- name: Test installed package
run: uv run --no-sync python -I -m pytest
- name: Check installed type information
run: |
pipenv run pytest
mkdir -p "$RUNNER_TEMP/mope-consumer"
cp tests/typing.py "$RUNNER_TEMP/mope-consumer/consumer.py"
uv run --no-sync ty check --project "$RUNNER_TEMP/mope-consumer" --python "$PWD/.venv"
48 changes: 26 additions & 22 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,33 @@
# This workflows will upload a Python Package using Twine when a release is created
# For more information see: https://help.github.com/en/actions/language-and-framework-guides/using-python-with-github-actions#publishing-to-package-registries

name: publish package

on:
release:
types: [created]
types: [published]

permissions:
contents: read

jobs:
deploy:
validate:
uses: ./.github/workflows/build.yml

publish:
needs: validate
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/python-mope/
permissions:
id-token: write
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
- name: Download tested distributions
uses: actions/download-artifact@v8
with:
name: distributions
path: dist
- name: Install uv
uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3
with:
python-version: '3.8'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pipenv
pipenv install --dev
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: ${{ secrets.PYPI_USERNAME }}
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist bdist_wheel
twine upload dist/*
version: "0.13.8"
- name: Publish to PyPI
run: uv publish --trusted-publishing always dist/*
13 changes: 3 additions & 10 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,15 +183,8 @@ target/
profile_default/
ipython_config.py

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# Ruff
.ruff_cache/

# PEP 582; used by e.g. github.com/David-OConnor/pyflow
__pypackages__/
Expand Down Expand Up @@ -253,4 +246,4 @@ tags


.idea/*
pythonenv3.*/
pythonenv3.*/
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.15.2
19 changes: 0 additions & 19 deletions Pipfile

This file was deleted.

44 changes: 39 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
![build](https://github.com/rhymiz/python-mope/workflows/build/badge.svg)
[![downloads](https://pepy.tech/badge/python-mope)](https://pepy.tech/project/python-mope)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Ruff](https://img.shields.io/badge/lint%20and%20format-Ruff-D7FF64.svg)](https://docs.astral.sh/ruff/)

# Python Mopé
Client library for Mopé by Hakrinbank
Expand All @@ -11,7 +11,7 @@ Client library for Mopé by Hakrinbank


### Requirements
- Python >= 3.8,<4
- Python 3.11 or newer
- Mopé API Token

### Getting Started
Expand All @@ -22,10 +22,44 @@ Example usage:
```python
from mope import Mope

mope = Mope(token='test_123')
mope.shop.get_payment_request(payment_id='123')
mope = Mope(token="test_123")
mope.shop.get_payment_request(payment_id="123")
```

### Development

Install [uv](https://docs.astral.sh/uv/getting-started/installation/), then run:

```sh
uv sync --locked
uv run --locked ruff check .
uv run --locked ruff format --check .
uv run --locked ty check
uv run --locked pytest
uv build --no-sources
```

Development uses Python 3.15.2 from `.python-version`; uv installs it when needed.
The library supports Python 3.11+, and CI tests the built wheel on Python 3.11,
3.12, 3.13, 3.14, and 3.15. Ruff and ty target Python 3.11 compatibility.
Run `uv run ruff format .` to format code. Commit `uv.lock` after changing
dependencies; use `uv lock --upgrade` to refresh their locked versions.

The package includes inline types and a `py.typed` marker. API responses are
validated before creating models: invalid field types raise `TypeError`, invalid
status values raise `ValueError`, and missing required fields raise `KeyError`.
Values are not coerced. Payment metadata remains a list of dictionaries with
string `key` and `value` fields, as defined by the
[Mopé API schema](https://api.mope.sr/integration/paths/GetPaymentRequest.yaml).

### Publishing

To release, update `mope/__version__.py`, run `uv lock`, and commit the changes.
Publish a GitHub release whose tag is the package version or `v` followed by that
version. The workflow checks the tag, runs lint, formatting and type checks,
builds the source distribution and wheel, and tests the installed wheel across
all supported Python versions before uploading those same artifacts to PyPI.

### Resources
#### shop

Expand All @@ -38,7 +72,7 @@ mope.shop.get_payment_request(payment_id='123')
|amount | int | yes |
|description | string | yes |
|order_id | string | yes |
|currency | enum (USD, SRD, EU) | yes |
|currency | enum (USD, SRD, EUR) | yes |
|redirect_url| string | yes |


Expand Down
2 changes: 1 addition & 1 deletion mope/__version__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__author__ = "lemuel@vokality.com"
__version__ = "0.2.0"
__version__ = "0.3.0"
Loading
Loading