diff --git a/.github/actions/set-version/action.yml b/.github/actions/set-version/action.yml index 872a16c3..aeb05bf3 100644 --- a/.github/actions/set-version/action.yml +++ b/.github/actions/set-version/action.yml @@ -1,5 +1,16 @@ name: 'Set Version' -description: 'Compute and set version for httpr builds' +description: | + Compute and set version for httpr builds. + + Version logic: + - Tag release (refs/tags/v*): Extract version from tag (v1.2.3 -> 1.2.3) + - Dev release (workflow_dispatch): Base version + .devN (1.2.3.dev42) + + Updates both pyproject.toml (full version) and Cargo.toml (base version only, + since Cargo semver doesn't support .dev suffixes). + + The version in source files (0.0.0.dev0 / 0.0.0) is a placeholder and should + not be edited manually. inputs: run-number: description: 'GitHub run number for dev versions' diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index f0dafd99..a1a8a880 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -4,6 +4,8 @@ on: push: branches: - main + paths-ignore: + - "*.jpg" # Prevents the benchmark image update from triggering CI tags: - "*" pull_request: @@ -424,7 +426,14 @@ jobs: uv run uvicorn benchmark.server:app --host 0.0.0.0 --port 8000 & sleep 10 - name: Run benchmark - run: uv run python benchmark/benchmark.py + run: | + # Extract version from tag (v0.3.0 -> 0.3.0) or use 'dev' for manual runs + if [[ "${{ github.ref }}" == refs/tags/v* ]]; then + HTTPR_VERSION=${GITHUB_REF#refs/tags/v} + else + HTTPR_VERSION="dev" + fi + uv run python benchmark/benchmark.py --httpr-version "$HTTPR_VERSION" - name: Generate and commit benchmark image if: startsWith(github.ref, 'refs/tags/') run: | diff --git a/.github/workflows/set_version.py b/.github/workflows/set_version.py index 03961fb4..b2fcfe3a 100644 --- a/.github/workflows/set_version.py +++ b/.github/workflows/set_version.py @@ -1,4 +1,20 @@ #!/usr/bin/env python3 +""" +Version management script for httpr CI builds. + +This script is called by the GitHub Actions workflow (.github/actions/set-version/) +to set the package version dynamically based on git tags: + + - Tag release (e.g., v1.2.3): Version is extracted from the tag -> "1.2.3" + - Dev release (workflow_dispatch): Base version + run number -> "1.2.3.dev42" + +Both pyproject.toml and Cargo.toml are updated. Cargo.toml gets the base version +without any .dev suffix since Cargo's semver doesn't support that format. + +Usage: + python set_version.py 1.2.3 # Set version to 1.2.3 + python set_version.py --get-base # Print base version from pyproject.toml +""" import argparse import os diff --git a/Cargo.toml b/Cargo.toml index 4fbc94c8..9284f86e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,8 @@ [package] name = "httpr" -version = "0.2.3" +# Version is set dynamically by CI from git tags (e.g., v1.2.3 -> 1.2.3). +# Do not edit manually. See .github/actions/set-version/ for details. +version = "0.0.0" edition = "2021" description = "Fast HTTP client for python" authors = ["thomasht86"] diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index ccf280a8..e74601f0 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -69,9 +69,17 @@ def aiohttp_session_factory(): ("aiohttp", aiohttp_session_factory), ] +# Optional override for httpr version (set via --httpr-version CLI arg) +_httpr_version_override: str | None = None + def add_package_version(packages): - return [(f"{name} {version(name)}", classname) for name, classname in packages] + def get_version(name): + if name == "httpr" and _httpr_version_override: + return _httpr_version_override + return version(name) + + return [(f"{name} {get_version(name)}", classname) for name, classname in packages] def get_test(session_class, requests_number): @@ -264,8 +272,17 @@ def run_multithread_benchmarks(): default=False, help="If provided, run the multithreading tests only", ) + parser.add_argument( + "--httpr-version", + type=str, + default=None, + help="Override httpr version in benchmark output (e.g., 0.3.0)", + ) args = parser.parse_args() + if args.httpr_version: + _httpr_version_override = args.httpr_version + if args.run_multithread: run_multithread_benchmarks() else: diff --git a/pyproject.toml b/pyproject.toml index 68d26404..850f44a6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -9,7 +9,9 @@ readme = "README.md" requires-python = ">=3.10" keywords = [ "python", "request",] classifiers = [ "Programming Language :: Rust", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3 :: Only", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.13", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Internet :: WWW/HTTP", "Topic :: Software Development :: Libraries :: Python Modules",] -version = "0.2.3" +# Version is set dynamically by CI from git tags (e.g., v1.2.3 -> 1.2.3). +# Do not edit manually. See .github/actions/set-version/ for details. +version = "0.0.0.dev0" dependencies = [] [[project.authors]] name = "thomasht86"