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
3 changes: 0 additions & 3 deletions .flake8

This file was deleted.

8 changes: 4 additions & 4 deletions .github/workflows/build_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,24 +20,24 @@ jobs:
uses: actions/checkout@v4

- name: Log in to the Container registry
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d
uses: docker/login-action@v4
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@dbef88086f6cef02e264edb7dbf63250c17cef6c
uses: docker/metadata-action@v6
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=auto
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@0d103c3126aa41d772a8362f6aa67afac040f80c
uses: docker/setup-buildx-action@v4

- name: Build and push Docker image
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56
uses: docker/build-push-action@v7
with:
context: .
push: true
Expand Down
39 changes: 5 additions & 34 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
@@ -1,39 +1,10 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Prek checks

name: Python

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

permissions:
contents: read
on: [push, pull_request]

jobs:
build:
prek:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.8.5"
- name: Install dependencies
run: |
poetry install
- name: Run Python tests
run: |
poetry run pytest --cov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
- uses: actions/checkout@v6
- uses: j178/prek-action@v2
84 changes: 35 additions & 49 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,79 +4,65 @@ on:
inputs:
release-type:
type: choice
description: 'Release type (one of): patch, minor, major, prepatch, preminor, premajor, prerelease'
description: 'Release type (one of): patch, minor, major'
default: 'patch'
options:
- 'patch'
- 'minor'
- 'major'
required: true

permissions:
contents: write
packages: write

jobs:
release:
runs-on: ubuntu-latest
steps:
# Checkout project repository
- uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install poetry
uses: abatilo/actions-poetry@v2
with:
poetry-version: "1.8.5"
- uses: actions/checkout@v6
- name: Install the latest version of uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Install dependencies
run: |
poetry install
- name: Run Python lint checks
run: |
poetry run pre-commit run --all-files
run: uv sync
- name: Run Python tests
run: |
poetry run pytest --cov
run: uv run pytest --cov
- name: Git configuration
run: |
git config --global user.email "bot@example.com"
git config --global user.name "GitHub Actions"
- name: Bump release version
run: |
poetry version ${{ github.event.inputs.release-type }}
echo "NEW_VERSION=$(poetry version --short)" >> $GITHUB_ENV
env:
RELEASE_TYPE: ${{ github.event.inputs.release-type }}
- name: Build package
uv version --bump ${{ github.event.inputs.release-type }}
echo "NEW_VERSION=$(uv version --short)" >> $GITHUB_ENV
- name: Update lock file and build package
run: |
poetry lock
poetry build
- name: Commit pyproject.toml and poetry.lock
uv lock
uv build
- name: Commit pyproject.toml and uv.lock
run: |
git add pyproject.toml poetry.lock
git add pyproject.toml uv.lock
git commit -m "chore: release ${{ env.NEW_VERSION }}"
git tag ${{ env.NEW_VERSION }}
git push origin master
- name: Build docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
with:
context: .
push: false
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
# Push repository changes
- name: Publish package
run: |
poetry publish --build
git push origin master --follow-tags
- name: Publish package to PyPI
run: uv publish
env:
POETRY_PYPI_TOKEN_PYPI: ${{ secrets.PYPI_TOKEN }}
- name: Push docker image
uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
- name: Log in to the Container registry
uses: docker/login-action@v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v4
- name: Build and push Docker image
uses: docker/build-push-action@v7
with:
context: .
push: false
push: true
platforms: linux/amd64
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
tags: |
ghcr.io/${{ github.repository }}:${{ env.NEW_VERSION }}
ghcr.io/${{ github.repository }}:latest
17 changes: 17 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Install the latest version of uv
uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0
- name: Install dependencies
run: uv sync
- name: Run tests
run: uv run pytest --cov
- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v5
4 changes: 0 additions & 4 deletions .mypy.ini

This file was deleted.

49 changes: 8 additions & 41 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exclude: ^(api_protobuf/.*|docs/protobuf_docs\.md|dhaul_openapi/messages/.*)$
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
Expand All @@ -12,53 +12,20 @@ repos:
exclude: ^testdata/.*
- id: check-json
- id: detect-private-key
- id: fix-encoding-pragma
- id: check-merge-conflict
- id: check-added-large-files
- repo: https://github.com/psf/black
rev: 24.10.0
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.14
hooks:
- id: black
args: [--config=pyproject.toml]
- repo: https://github.com/PyCQA/isort
rev: 5.13.2
hooks:
- id: isort
- repo: https://github.com/pre-commit/mirrors-mypy
rev: "v1.13.0"
hooks:
- id: mypy
- repo: https://github.com/PyCQA/docformatter
rev: eb1df347edd128b30cd3368dddc3aa65edcfac38
# TODO: Switch back to upstream docformatter
# after https://github.com/PyCQA/docformatter/issues/289 is fixed
hooks:
- id: docformatter
args:
- --in-place
- --config=pyproject.toml
- repo: https://github.com/PyCQA/autoflake
rev: v2.3.1
hooks:
- id: autoflake
- repo: https://github.com/pycqa/flake8
rev: 7.1.1
hooks:
- id: flake8
entry: flake8
- repo: https://github.com/netromdk/vermin
rev: v1.6.0
hooks:
- id: vermin
# specify your target version here, OR in a Vermin config file as usual:
args: ["-t=3.9-", "--violations"]
# (if your target is specified in a Vermin config, you may omit the 'args' entry entirely)
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.35.1
rev: v1.38.0
hooks:
- id: yamllint
- repo: https://github.com/igorshubovych/markdownlint-cli
rev: v0.42.0
rev: v0.48.0
hooks:
- id: markdownlint-fix
- id: markdownlint
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.14
18 changes: 7 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
FROM python:3.12-slim-bookworm AS builder
FROM python:3.14-slim-bookworm AS builder
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
ENV UV_HTTP_TIMEOUT=100 \
UV_NO_CACHE=1
UV_NO_CACHE=1 \
UV_PROJECT_ENVIRONMENT=/venv
WORKDIR /app
RUN uv pip install --system poetry poetry-plugin-export
COPY pyproject.toml poetry.lock ./
RUN uv venv /venv && \
poetry config warnings.export false && \
poetry export -f requirements.txt -o requirements.txt && \
VIRTUAL_ENV=/venv uv pip install -r requirements.txt
COPY pyproject.toml uv.lock ./
RUN uv sync --no-dev --frozen --no-install-project
COPY . .
RUN poetry build && \
VIRTUAL_ENV=/venv uv pip install dist/*.whl
RUN uv sync --no-dev --frozen --no-editable

FROM python:3.12-slim-bookworm AS final
FROM python:3.14-slim-bookworm AS final
ENV PYTHONFAULTHANDLER=1 \
PYTHONHASHSEED=random \
PYTHONUNBUFFERED=1
Expand Down
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,44 +123,44 @@ To create a specification by inspecting HTTP traffic you will need to:

See the [examples](./example_outputs/). You will find a generated schema there and an html file with the generated documentation (via [redoc-cli](https://www.npmjs.com/package/redoc-cli)).

See the generated html file [here](https://raw.githack.com/alufers/mitmproxy2swagger/master/example_outputs/lisek-static.html).
See the [generated html file](https://raw.githack.com/alufers/mitmproxy2swagger/master/example_outputs/lisek-static.html).

## Development and contributing

This project uses:

- [poetry](https://python-poetry.org/) for dependency management
- [pre-commit](https://pre-commit.com/) for code formatting and linting
- [uv](https://docs.astral.sh/uv/) for dependency management
- [prek](https://github.com/j178/prek) for code formatting and linting
- [pytest](https://docs.pytest.org/en/stable/) for unit testing

To install the dependencies:

```bash
poetry install
uv sync
```

Run linters:

```bash
pre-commit run --all-files
uv run prek run --all-files
```

Install pre-commit hooks:
Install prek hooks:

```bash
pre-commit install
uv run prek install
```

Run tests:

```bash
poetry run pytest
uv run pytest
```

Run tests with coverage:

```bash
poetry run pytest --cov=mitmproxy2swagger
uv run pytest --cov=mitmproxy2swagger
```

## License
Expand Down
3 changes: 1 addition & 2 deletions mitmproxy2swagger/console_util.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
import sys

ANSI_RGB = "\033[38;2;{};{};{}m"
Expand Down Expand Up @@ -64,5 +63,5 @@ def print_progress_bar(progress=0.0):
progress_bar_contents += " "

progress_bar_contents += ANSI_RESET
sys.stdout.write("[{}] {:.1f}%".format(progress_bar_contents, progress * 100))
sys.stdout.write(f"[{progress_bar_contents}] {progress * 100:.1f}%")
sys.stdout.flush()
Loading
Loading