From 9c8ddfdc8a7e4b345d3c3eed70cc7e519f27b6f0 Mon Sep 17 00:00:00 2001 From: claudi Date: Tue, 7 Apr 2026 11:55:38 +0200 Subject: [PATCH] Add Forgejo upload script and update documentation for package registry --- .gitignore | 1 + .pypirc.example | 7 ++ README.md | 20 +++++ pyproject.toml | 1 + upload_wheel_to_forgejo_pypi.ps1 | 131 +++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 .pypirc.example create mode 100644 upload_wheel_to_forgejo_pypi.ps1 diff --git a/.gitignore b/.gitignore index dd2cb32..1134237 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ dist/ *.egg-info/ .eggs/ pip-wheel-metadata/ +.pypirc # Test and coverage output .pytest_cache/ diff --git a/.pypirc.example b/.pypirc.example new file mode 100644 index 0000000..568588d --- /dev/null +++ b/.pypirc.example @@ -0,0 +1,7 @@ +[distutils] +index-servers = forgejo + +[forgejo] +repository = https://git.him-tools.de/api/packages/HIM-public/pypi +username = __token__ +password = YOUR_FORGEJO_ACCESS_TOKEN \ No newline at end of file diff --git a/README.md b/README.md index 888347e..7f0e1be 100644 --- a/README.md +++ b/README.md @@ -69,6 +69,26 @@ Set the version and build the wheel in one step: & .\.venv\Scripts\python.exe .\scripts\build_wheel.py --version 0.1.1 ``` +Upload the wheel to the Forgejo package registry: + +```powershell +.\upload_wheel_to_forgejo_pypi.ps1 +``` + +Force a rebuild before upload: + +```powershell +.\upload_wheel_to_forgejo_pypi.ps1 -Build +``` + +Build a specific version and upload it: + +```powershell +.\upload_wheel_to_forgejo_pypi.ps1 -Build -Version 0.1.1 +``` + +Create `.pypirc` in the project root from `.pypirc.example` and fill in your Forgejo token before uploading. + Create a client with your eBay credentials: ```python diff --git a/pyproject.toml b/pyproject.toml index 2d582d8..12b1bc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,6 +21,7 @@ dev = [ "datamodel-code-generator>=0.28,<0.31", "pytest>=8,<9", "pytest-httpx>=0.35,<0.36", + "twine>=6,<7", ] [tool.setuptools.packages.find] diff --git a/upload_wheel_to_forgejo_pypi.ps1 b/upload_wheel_to_forgejo_pypi.ps1 new file mode 100644 index 0000000..c179e2c --- /dev/null +++ b/upload_wheel_to_forgejo_pypi.ps1 @@ -0,0 +1,131 @@ +param( + [switch]$Build = $false, + [string]$Version, + [switch]$Help = $false +) + +Set-StrictMode -Version Latest +$ErrorActionPreference = "Stop" + +function Show-Help { + Write-Host @" +Upload wheel to the Forgejo PyPI registry for ebay-rest-client + +USAGE: + .\upload_wheel_to_forgejo_pypi.ps1 [-Build] [-Version ] + +OPTIONS: + -Build Force a rebuild before uploading + -Version Set the package version before building + -Help Display this help message + +SETUP: + 1. Copy .pypirc.example to .pypirc in the project root + 2. Add your Forgejo access token to .pypirc + 3. Run this script again + +EXAMPLES: + .\upload_wheel_to_forgejo_pypi.ps1 + .\upload_wheel_to_forgejo_pypi.ps1 -Build + .\upload_wheel_to_forgejo_pypi.ps1 -Build -Version 0.1.1 +"@ +} + +if ($Help) { + Show-Help + exit 0 +} + +$projectRoot = Split-Path -Parent $MyInvocation.MyCommand.Path +$python = Join-Path $projectRoot ".venv\Scripts\python.exe" +$pypiRcPath = Join-Path $projectRoot ".pypirc" +$buildScript = Join-Path $projectRoot "scripts\build_wheel.py" +$distPath = Join-Path $projectRoot "dist" + +Write-Host "" +Write-Host "========================================================================" +Write-Host "eBay REST Client - Upload to Forgejo PyPI" +Write-Host "========================================================================" +Write-Host "" + +if (!(Test-Path $python)) { + Write-Host "[!] Virtual environment Python not found at .venv\\Scripts\\python.exe" -ForegroundColor Red + exit 1 +} + +if (!(Test-Path $pypiRcPath)) { + Write-Host "[!] .pypirc not found in project root." -ForegroundColor Red + Write-Host "" + Write-Host "Setup instructions:" + Write-Host " 1. Copy .pypirc.example to .pypirc" + Write-Host " 2. Edit .pypirc and add your Forgejo access token" + Write-Host " 3. Run this script again" + Write-Host "" + Write-Host "For help: .\upload_wheel_to_forgejo_pypi.ps1 -Help" + exit 1 +} + +if (!(Test-Path $buildScript)) { + Write-Host "[!] Build script not found at scripts\\build_wheel.py" -ForegroundColor Red + exit 1 +} + +$null = & $python -c "import importlib.util, sys; sys.exit(0 if importlib.util.find_spec('twine') else 1)" +if ($LASTEXITCODE -ne 0) { + Write-Host "Installing twine..." + & $python -m pip install twine + if ($LASTEXITCODE -ne 0) { + Write-Host "[!] Failed to install twine." -ForegroundColor Red + exit 1 + } +} + +$wheelFiles = @(Get-ChildItem -Path $distPath -Filter "*.whl" -ErrorAction SilentlyContinue) + +if ($Build -or $wheelFiles.Count -eq 0) { + if ($Build) { + Write-Host "Building wheel (forced)..." + } else { + Write-Host "Building wheel..." + } + + $buildArgs = @($buildScript) + if ($Version) { + $buildArgs += "--version" + $buildArgs += $Version + } + + & $python @buildArgs + if ($LASTEXITCODE -ne 0) { + Write-Host "[!] Wheel build failed." -ForegroundColor Red + exit $LASTEXITCODE + } + + $wheelFiles = @(Get-ChildItem -Path $distPath -Filter "*.whl" -ErrorAction Stop) +} + +if ($wheelFiles.Count -eq 0) { + Write-Host "[!] No wheel files found in dist." -ForegroundColor Red + exit 1 +} + +Write-Host "" +Write-Host "========================================================================" +Write-Host "Uploading to Forgejo PyPI..." +Write-Host "========================================================================" +Write-Host "" + +& $python -m twine upload --config-file $pypiRcPath -r forgejo $wheelFiles.FullName +$uploadResult = $LASTEXITCODE + +Write-Host "" +Write-Host "========================================================================" +if ($uploadResult -eq 0) { + Write-Host "Upload successful!" -ForegroundColor Green +} else { + Write-Host "Upload failed" -ForegroundColor Red +} +Write-Host "========================================================================" +Write-Host "" + +exit $uploadResult \ No newline at end of file