diff --git a/.coveragerc b/.coveragerc index f2a4dc9..3739a28 100644 --- a/.coveragerc +++ b/.coveragerc @@ -15,7 +15,7 @@ exclude_lines = if __name__ == .__main__.: omit = - src/numkit/tests/* - # omit the versioneer-installed _version.py - src/numkit/_version.py + numkit/tests/* + # omit the versioningit-generated _version.py + numkit/_version.py diff --git a/.github/actions/wait-for-pypi-version/action.yaml b/.github/actions/wait-for-pypi-version/action.yaml new file mode 100644 index 0000000..8a0b5d4 --- /dev/null +++ b/.github/actions/wait-for-pypi-version/action.yaml @@ -0,0 +1,93 @@ +name: 'Wait for PyPI version' +description: 'Wait for a specific package version to become available on PyPI or TestPyPI' +inputs: + repository: + description: 'PyPI repository type: "pypi" or "testpypi"' + required: true + package: + description: 'Package name' + required: true + version: + description: 'Package version to wait for' + required: true + max_attempts: + description: 'Maximum number of retry attempts' + required: false + default: '30' + wait_seconds: + description: 'Seconds to wait between attempts' + required: false + default: '10' + +runs: + using: composite + steps: + - name: Install requests + shell: bash + run: | + python -m pip install --upgrade pip + pip install requests + + - name: Wait for version to be available + shell: python + env: + REPOSITORY: ${{ inputs.repository }} + PACKAGE: ${{ inputs.package }} + VERSION: ${{ inputs.version }} + MAX_ATTEMPTS: ${{ inputs.max_attempts }} + WAIT_SECONDS: ${{ inputs.wait_seconds }} + run: | + import os + import sys + import time + + import requests + + repository = os.environ["REPOSITORY"].strip().lower() + package = os.environ["PACKAGE"] + version = os.environ["VERSION"] + max_attempts = int(os.environ.get("MAX_ATTEMPTS", "30")) + wait_seconds = int(os.environ.get("WAIT_SECONDS", "10")) + + if repository == "testpypi": + api_url = f"https://test.pypi.org/pypi/{package}/json" + repo_name = "TestPyPI" + elif repository == "pypi": + api_url = f"https://pypi.org/pypi/{package}/json" + repo_name = "PyPI" + else: + print( + f"ERROR: repository must be 'pypi' or 'testpypi', got {repository!r}", + file=sys.stderr, + ) + sys.exit(1) + + for attempt in range(max_attempts): + try: + r = requests.get(api_url, timeout=10) + r.raise_for_status() + data = r.json() + versions = data.get("releases", {}) + keys = list(versions.keys()) + print("Available versions:", keys[-10:]) # Show last 10 versions + if version in versions: + print(f"✓ Version {version} is available on {repo_name}") + print(f"Version {version} is now available on {repo_name}") + sys.exit(0) + print(f"✗ Version {version} is NOT available on {repo_name}") + except Exception as e: + print(f"Error checking version: {e}") + + current = attempt + 1 + print( + f"Attempt {current}/{max_attempts}: Version {version} not yet available " + f"on {repo_name}, waiting {wait_seconds} seconds..." + ) + time.sleep(wait_seconds) + + print( + f"ERROR: Version {version} did not become available on {repo_name} " + f"after {max_attempts} attempts", + file=sys.stderr, + ) + sys.exit(1) diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml index d88e54d..c23a18b 100644 --- a/.github/workflows/deploy.yaml +++ b/.github/workflows/deploy.yaml @@ -1,4 +1,4 @@ -name: Build and upload to PyPi +name: Build and upload to PyPI on: push: @@ -8,46 +8,222 @@ on: types: - published +concurrency: + group: "${{ github.ref }}-${{ github.head_ref }}-${{ github.workflow }}" + cancel-in-progress: false + +defaults: + run: + shell: bash -l {0} + jobs: - test_pypi_push: + build: + name: Build package + runs-on: ubuntu-latest + outputs: + version: ${{ steps.extract-version.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@v7 + with: + fetch-depth: 0 + fetch-tags: true + + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: "3.14" + + - name: Install build dependencies + run: | + python -m pip install --upgrade pip + pip install build twine + + - name: Build package (wheel and sdist) + run: python -m build + + - name: Check package + run: twine check dist/* + + - name: Extract package version + id: extract-version + run: | + WHEEL_FILE=$(ls dist/*.whl) + VERSION=$(basename "$WHEEL_FILE" | sed -n 's/numkit-\([^-]*\)-.*/\1/p') + if [ -z "$VERSION" ]; then + python -m pip install --upgrade pip + pip install "$WHEEL_FILE" --quiet + VERSION=$(python -c "import numkit; print(numkit.__version__)") + pip uninstall -y numkit --quiet + fi + echo "version=$VERSION" >> "$GITHUB_OUTPUT" + echo "Extracted version: $VERSION" + + - name: Upload dist files + uses: actions/upload-artifact@v7 + with: + name: dist-files + path: dist/ + retention-days: 1 + + test-pytest: + name: Run tests + runs-on: ubuntu-latest + needs: build + steps: + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: "3.14" + + - name: Download dist files + uses: actions/download-artifact@v8 + with: + name: dist-files + path: dist/ + + - name: Install wheel with test extras + run: | + python -m pip install --upgrade pip + WHEEL_FILE=$(ls dist/*.whl) + pip install "${WHEEL_FILE}[testing]" + + - name: Test import + run: | + python -c "import numkit; print(f'Package {numkit.__version__} imported successfully')" + + - name: Run tests + run: | + pytest --verbose --pyargs numkit + + deploy-testpypi: + name: Deploy to TestPyPI + runs-on: ubuntu-latest + needs: [build, test-pytest] + if: | + github.repository == 'Becksteinlab/numkit' && + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) environment: name: TestPyPi url: https://test.pypi.org/p/numkit permissions: - id-token: write - if: | - github.repository == 'Becksteinlab/numkit' && - (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) - name: "TestPyPi: Build, upload, and test pure Python wheels" - runs-on: ubuntu-latest - + id-token: write # IMPORTANT: mandatory for trusted publishing steps: - - uses: actions/checkout@v7 + - name: Download dist files + uses: actions/download-artifact@v8 + with: + name: dist-files + path: dist/ - - name: testpypi_deploy - uses: MDAnalysis/pypi-deployment@main - if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/') + - name: Publish to TestPyPI + uses: pypa/gh-action-pypi-publish@v1.14.3 with: - test_submission: true - package_name: 'numkit' + repository-url: https://test.pypi.org/legacy/ + skip-existing: true + verbose: true - pypi_push: + deploy-pypi: + name: Deploy to PyPI + runs-on: ubuntu-latest + needs: [build, test-pytest] + if: | + github.repository == 'Becksteinlab/numkit' && + (github.event_name == 'release' && github.event.action == 'published') environment: name: PyPi url: https://pypi.org/p/numkit permissions: - id-token: write + id-token: write # IMPORTANT: mandatory for trusted publishing + steps: + - name: Download dist files + uses: actions/download-artifact@v8 + with: + name: dist-files + path: dist/ + + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@v1.14.3 + + test-deployed-testpypi: + name: Test deployed package (TestPyPI) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + needs: [build, deploy-testpypi] if: | github.repository == 'Becksteinlab/numkit' && - (github.event_name == 'release' && github.event.action == 'published') - name: "PyPi: Build, upload, and test pure Python wheels" - runs-on: ubuntu-latest + (github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')) + steps: + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: "3.14" + + - name: Checkout repository for actions + uses: actions/checkout@v7 + + - name: Wait for version to be available on TestPyPI + uses: ./.github/actions/wait-for-pypi-version + with: + repository: testpypi + package: numkit + version: ${{ needs.build.outputs.version }} + - name: Install from TestPyPI + run: | + python -m pip install --upgrade pip + pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ "numkit[testing]==${{ needs.build.outputs.version }}" + + - name: Test import + run: | + cd ~ + python -c "import numkit; print(f'Package {numkit.__version__} imported successfully from TestPyPI')" + + - name: Run tests + run: | + cd ~ + pytest -v --pyargs numkit + + test-deployed-pypi: + name: Test deployed package (PyPI) + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + needs: [build, deploy-pypi] + if: | + github.repository == 'Becksteinlab/numkit' && + (github.event_name == 'release' && github.event.action == 'published') steps: - - uses: actions/checkout@v7 + - name: Set up Python + uses: actions/setup-python@v7 + with: + python-version: "3.14" + + - name: Checkout repository for actions + uses: actions/checkout@v7 - - name: pypi_deploy - uses: MDAnalysis/pypi-deployment@main - if: github.event_name == 'release' && github.event.action == 'published' + - name: Wait for version to be available on PyPI + uses: ./.github/actions/wait-for-pypi-version with: - package_name: 'numkit' + repository: pypi + package: numkit + version: ${{ needs.build.outputs.version }} + + - name: Install from PyPI + run: | + python -m pip install --upgrade pip + pip install "numkit[testing]==${{ needs.build.outputs.version }}" + + - name: Test import + run: | + cd ~ + python -c "import numkit; print(f'Package {numkit.__version__} imported successfully from PyPI')" + + - name: Run tests + run: | + cd ~ + pytest -v --pyargs numkit diff --git a/.gitignore b/.gitignore index 222da53..9c77093 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,5 @@ __pycache__ build/ -# aut-generated by versioningit +# auto-generated by versioningit numkit/_version.py diff --git a/CHANGES b/CHANGES index 040a6e8..4832b89 100644 --- a/CHANGES +++ b/CHANGES @@ -21,8 +21,7 @@ orbeckst * dropped support for Python 2.7 (ye served us well, RIP), and dropped support for Python 3.7 & 3.8 * internal: switched to pyproject.toml and replaced versioneer with - versioningit: the tags that indicate releases were changed from - release-major.minor.patch to PEP440 compliant major.minor.release + versioningit (release tags remain release-major.minor.patch) 2023-03-13 1.2.3 orbeckst diff --git a/docs/source/conf.py b/docs/source/conf.py index 30aa1ce..ebb1b6f 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -53,7 +53,7 @@ # The default replacements for |version| and |release|, also used in various # other places throughout the built documents. # -# Dynamically calculate the version (uses versioneer) +# Dynamically calculate the version (from versioningit-generated _version.py) packageversion = __import__("numkit").__version__ # The short X.Y version. diff --git a/pyproject.toml b/pyproject.toml index e089128..67da0ec 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,5 +1,5 @@ [build-system] -requires = ["setuptools>=42", "wheel", "versioningit"] +requires = ["setuptools>=77", "wheel", "versioningit"] build-backend = "setuptools.build_meta" [project] @@ -7,7 +7,8 @@ name = "numkit" description = "numerical first aid kit" dynamic = ["version"] readme = "README.rst" -license = { text = "BSD" } +license = "BSD-3-Clause" +license-files = ["LICENSE"] authors = [ { name = "Oliver Beckstein", email = "orbeckst@gmail.com" } ] @@ -15,7 +16,6 @@ classifiers = [ "Development Status :: 6 - Mature", "Environment :: Console", "Intended Audience :: Science/Research", - "License :: OSI Approved :: BSD License", "Operating System :: POSIX", "Operating System :: MacOS :: MacOS X", "Operating System :: Microsoft :: Windows",