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
13 changes: 12 additions & 1 deletion .github/actions/set-version/action.yml
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
11 changes: 10 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ on:
push:
branches:
- main
paths-ignore:
- "*.jpg" # Prevents the benchmark image update from triggering CI
tags:
- "*"
pull_request:
Expand Down Expand Up @@ -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: |
Expand Down
16 changes: 16 additions & 0 deletions .github/workflows/set_version.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"]
Expand Down
19 changes: 18 additions & 1 deletion benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down