diff --git a/.github/scripts/ci_loop_versions.py b/.github/scripts/ci_loop_versions.py new file mode 100644 index 0000000..c65b14d --- /dev/null +++ b/.github/scripts/ci_loop_versions.py @@ -0,0 +1,37 @@ +import argparse +import json + +import requests +from packaging.specifiers import SpecifierSet +from packaging.version import Version + + +def get_versions(package: str, version_spec: str) -> list[str]: + specifier = SpecifierSet(version_spec) + + url = f"https://pypi.org/pypi/{package}/json" + resp = requests.get(url, timeout=30) + resp.raise_for_status() + data = resp.json() + + all_versions = data["releases"].keys() + + matched = sorted( + (Version(v) for v in all_versions if Version(v) in specifier), + reverse=True, + ) + return [str(v) for v in matched] + + +def main(): + parser = argparse.ArgumentParser(description="List matching PyPI versions as JSON") + parser.add_argument("package", help="package name, e.g. setuptools") + parser.add_argument("version", help='version spec, e.g. ">=77.0.1,<83"') + args = parser.parse_args() + + versions = get_versions(args.package, args.version) + print(json.dumps(versions)) + + +if __name__ == "__main__": + main() diff --git a/.github/workflows/compatibility.yml b/.github/workflows/compatibility.yml new file mode 100644 index 0000000..20f4fc1 --- /dev/null +++ b/.github/workflows/compatibility.yml @@ -0,0 +1,69 @@ +name: Test Compatibility + +on: + push: + paths: + - pyproject.toml + workflow_dispatch: + +permissions: + contents: read + +jobs: + prepare: + runs-on: ubuntu-latest + outputs: + versions: ${{ steps.parser.outputs.versions || '[]' }} + steps: + - uses: actions/checkout@v6 + with: + fetch-depth: 2 + + - name: Check license line changed + id: check + run: | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then + echo "changed=true" >> "$GITHUB_OUTPUT" + elif git diff HEAD~1 HEAD -- pyproject.toml | grep -q '^[+-].*license = "Apache-2.0"'; then + echo "changed=true" >> "$GITHUB_OUTPUT" + else + echo "changed=false" >> "$GITHUB_OUTPUT" + fi + + - uses: actions/setup-python@v6 + if: steps.check.outputs.changed == 'true' + with: + python-version: "3.14" + + - name: Generate version matrix + if: steps.check.outputs.changed == 'true' + id: parser + run: | + versions=$(python ci_loop_versions.py setuptools ">=77.0.1,<83") + echo "versions=$versions" >> "$GITHUB_OUTPUT" + + check: + needs: prepare + if: needs.prepare.outputs.versions != '[]' + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + version: ${{ fromJSON(needs.prepare.outputs.versions) }} + + steps: + - uses: actions/checkout@v6 + - uses: actions/setup-python@v6 + with: + python-version: "3.14" + cache: pip + + - name: Install package with selected setuptools + run: | + python -m pip install --upgrade pip + python -m pip install . "setuptools==${{ matrix.version }}" + + - name: Show versions + run: | + python --version + python -m pip show setuptools diff --git a/pyproject.toml b/pyproject.toml index da5fdc7..2b171af 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -16,7 +16,7 @@ [build-system] -requires = ["setuptools>=61"] +requires = ["setuptools>=77.0.1,<83"] build-backend = "setuptools.build_meta" [project]