perf(distance): use ** operator and drop * 1.0 idiom (#269) #783
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| push: | |
| branches: | |
| - main | |
| pull_request: | |
| workflow_dispatch: | |
| inputs: | |
| force: | |
| description: "Force a release of this version type (passes through to python-semantic-release)" | |
| required: false | |
| default: "" | |
| type: choice | |
| options: | |
| - "" | |
| - patch | |
| - minor | |
| - major | |
| - prerelease | |
| concurrency: | |
| group: ${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| env: | |
| POETRY_VIRTUALENVS_IN_PROJECT: "true" | |
| jobs: | |
| lint: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.10" | |
| - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 | |
| # Make sure commit messages follow the conventional commits convention: | |
| # https://www.conventionalcommits.org | |
| commitlint: | |
| name: Lint Commit Messages | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| - uses: wagoid/commitlint-github-action@b948419dd99f3fd78a6548d48f94e3df7f6bf3ed # v6.2.1 | |
| test: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: | |
| - "3.10" | |
| - "3.11" | |
| - "3.12" | |
| - "3.13" | |
| - "3.14" | |
| - "3.14t" | |
| os: | |
| - ubuntu-latest | |
| - macOS-latest | |
| - windows-latest | |
| extension: | |
| - "skip_cython" | |
| - "use_cython" | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Set up uv | |
| uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 | |
| with: | |
| enable-cache: true | |
| - name: Install poetry | |
| run: uv tool install poetry | |
| - name: Set up Python | |
| id: setup-python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| allow-prereleases: true | |
| cache: "poetry" | |
| - name: Cache poetry venv | |
| id: cache-venv | |
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | |
| with: | |
| path: | | |
| .venv | |
| src/bluetooth_data_tools/**/*.so | |
| key: venv-v2-${{ runner.os }}-py${{ steps.setup-python.outputs.python-version }}-${{ matrix.extension }}-${{ hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py', 'src/bluetooth_data_tools/**/*.py', 'src/bluetooth_data_tools/**/*.pyx', 'src/bluetooth_data_tools/**/*.pxd') }} | |
| - name: Install Dependencies | |
| if: steps.cache-venv.outputs.cache-hit != 'true' | |
| run: | | |
| if [ "${{ matrix.extension }}" = "skip_cython" ]; then | |
| SKIP_CYTHON=1 poetry install --only=main,dev | |
| else | |
| poetry install --only=main,dev | |
| fi | |
| shell: bash | |
| - name: Test with Pytest | |
| run: poetry run pytest --cov-report=xml -v -Wdefault --cov=bluetooth_data_tools --cov-report=term-missing:skip-covered tests | |
| shell: bash | |
| - name: Upload coverage to Codecov | |
| uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v6.0.0 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| benchmark: | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| python-version: | |
| - "3.13" | |
| os: | |
| - ubuntu-latest | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Set up uv | |
| uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 | |
| with: | |
| enable-cache: true | |
| - name: Install poetry | |
| run: uv tool install poetry | |
| - name: Set up Python | |
| id: setup-python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| cache: "poetry" | |
| - name: Cache poetry venv | |
| id: cache-venv | |
| uses: actions/cache@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5 | |
| with: | |
| path: | | |
| .venv | |
| src/bluetooth_data_tools/**/*.so | |
| key: venv-v2-${{ runner.os }}-benchmark-py${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('poetry.lock', 'pyproject.toml', 'build_ext.py', 'src/bluetooth_data_tools/**/*.py', 'src/bluetooth_data_tools/**/*.pyx', 'src/bluetooth_data_tools/**/*.pxd') }} | |
| - name: Install Dependencies | |
| if: steps.cache-venv.outputs.cache-hit != 'true' | |
| run: poetry install --only=main,dev,benchmark | |
| env: | |
| REQUIRE_CYTHON: 1 | |
| - name: Run benchmarks | |
| run: | | |
| poetry run pytest bench --benchmark-autosave | |
| echo '# Benchmark Results' >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| poetry run pytest-benchmark compare --columns=mean,ops >> $GITHUB_STEP_SUMMARY | |
| echo '```' >> $GITHUB_STEP_SUMMARY | |
| shell: bash | |
| codspeed_benchmark: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| - name: Set up uv | |
| uses: astral-sh/setup-uv@08807647e7069bb48b6ef5acd8ec9567f424441b # v8.1.0 | |
| with: | |
| enable-cache: true | |
| - name: Install poetry | |
| run: uv tool install poetry | |
| - name: Setup Python 3.13 | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: 3.13 | |
| cache: "poetry" | |
| - name: Install Dependencies | |
| run: | | |
| REQUIRE_CYTHON=1 poetry install --only=main,dev | |
| shell: bash | |
| - name: Run benchmarks | |
| uses: CodSpeedHQ/action@3194d9a39c4d46684cb44bf7207fc56626aad8fd # v4.15.1 | |
| with: | |
| token: ${{ secrets.CODSPEED_TOKEN }} | |
| run: poetry run pytest --no-cov -vvvvv --codspeed tests/benchmarks | |
| mode: instrumentation | |
| release: | |
| needs: | |
| - test | |
| - lint | |
| - commitlint | |
| runs-on: ubuntu-latest | |
| # Only enter the protected 'release' environment when actually releasing | |
| # from main; PR dry-runs would otherwise be blocked by the env's | |
| # main-only branch policy. | |
| environment: ${{ github.ref_name == 'main' && 'release' || '' }} | |
| concurrency: | |
| group: release-${{ github.head_ref || github.ref }} | |
| cancel-in-progress: false | |
| permissions: | |
| id-token: write | |
| contents: write | |
| outputs: | |
| released: ${{ steps.release.outputs.released }} | |
| newest_release_tag: ${{ steps.release.outputs.tag }} | |
| steps: | |
| # Mint a short-lived installation token for the release-bot GitHub | |
| # App, which is in the main ruleset's bypass_actors list so PSR's | |
| # version-bump commit/tag push isn't blocked by required checks. | |
| # Per PSR's docs, the same token must be passed to actions/checkout | |
| # (via `token`) so its persisted http.extraheader doesn't override | |
| # PSR's URL-embedded auth at push time and re-attribute the push | |
| # to github-actions[bot]. | |
| - name: Generate release App token | |
| if: github.ref_name == 'main' | |
| id: app-token | |
| uses: actions/create-github-app-token@fee1f7d63c2ff003460e3d139729b119787bc349 # v2.2.2 | |
| with: | |
| app-id: ${{ secrets.RELEASE_APP_ID }} | |
| private-key: ${{ secrets.RELEASE_APP_PRIVATE_KEY }} | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| fetch-depth: 0 | |
| ref: ${{ github.ref }} | |
| token: ${{ steps.app-token.outputs.token || github.token }} | |
| - name: Create local branch name | |
| run: git switch -C ${{ github.head_ref || github.ref_name }} | |
| # Do a dry run of PSR | |
| - name: Test release | |
| uses: python-semantic-release/python-semantic-release@350c48fcb3ffcdfd2e0a235206bc2ecea6b69df0 # v10.5.3 | |
| if: github.ref_name != 'main' | |
| with: | |
| no_operation_mode: true | |
| # On main branch: actual PSR + upload to PyPI & GitHub | |
| - name: Release | |
| uses: python-semantic-release/python-semantic-release@350c48fcb3ffcdfd2e0a235206bc2ecea6b69df0 # v10.5.3 | |
| id: release | |
| if: github.ref_name == 'main' | |
| with: | |
| github_token: ${{ steps.app-token.outputs.token }} | |
| force: ${{ inputs.force }} | |
| - name: Publish package distributions to PyPI | |
| uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 | |
| if: steps.release.outputs.released == 'true' | |
| - name: Publish package distributions to GitHub Releases | |
| uses: python-semantic-release/upload-to-gh-release@0a92b5d7ebfc15a84f9801ebd1bf706343d43711 # v9.8.9 | |
| if: steps.release.outputs.released == 'true' | |
| with: | |
| github_token: ${{ steps.app-token.outputs.token }} | |
| build_wheels: | |
| needs: [release] | |
| if: needs.release.outputs.released == 'true' | |
| name: Wheels for ${{ matrix.os }} (${{ matrix.musl == 'musllinux' && 'musllinux' || 'manylinux' }}) ${{ matrix.qemu }} ${{ matrix.pyver }} | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| matrix: | |
| os: | |
| [ | |
| windows-latest, | |
| ubuntu-24.04-arm, | |
| ubuntu-latest, | |
| macos-15-intel, | |
| macos-latest, | |
| ] | |
| qemu: [""] | |
| musl: [""] | |
| pyver: [""] | |
| include: | |
| - os: ubuntu-latest | |
| musl: "musllinux" | |
| - os: ubuntu-24.04-arm | |
| musl: "musllinux" | |
| # qemu is slow, make a single | |
| # runner per Python version | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "musllinux" | |
| pyver: cp310 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "musllinux" | |
| pyver: cp311 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "musllinux" | |
| pyver: cp312 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "musllinux" | |
| pyver: cp313 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "musllinux" | |
| pyver: cp314 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "musllinux" | |
| pyver: cp314t | |
| # qemu is slow, make a single | |
| # runner per Python version | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "" | |
| pyver: cp310 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "" | |
| pyver: cp311 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "" | |
| pyver: cp312 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "" | |
| pyver: cp313 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "" | |
| pyver: cp314 | |
| - os: ubuntu-latest | |
| qemu: armv7l | |
| musl: "" | |
| pyver: cp314t | |
| steps: | |
| - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 | |
| with: | |
| ref: ${{ needs.release.outputs.newest_release_tag }} | |
| fetch-depth: 0 | |
| # Used to host cibuildwheel | |
| - name: Set up Python | |
| uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6.2.0 | |
| with: | |
| python-version: "3.12" | |
| - name: Set up QEMU | |
| if: ${{ matrix.qemu }} | |
| uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0 | |
| with: | |
| platforms: all | |
| # This should be temporary | |
| # xref https://github.com/docker/setup-qemu-action/issues/188 | |
| # xref https://github.com/tonistiigi/binfmt/issues/215 | |
| image: tonistiigi/binfmt:qemu-v8.1.5 | |
| id: qemu | |
| - name: Prepare emulation | |
| if: ${{ matrix.qemu }} | |
| run: | | |
| if [[ -n "${{ matrix.qemu }}" ]]; then | |
| # Build emulated architectures only if QEMU is set, | |
| # use default "auto" otherwise | |
| echo "CIBW_ARCHS_LINUX=${{ matrix.qemu }}" >> $GITHUB_ENV | |
| fi | |
| - name: Limit to a specific Python version on slow QEMU | |
| if: ${{ matrix.pyver }} | |
| run: | | |
| if [[ -n "${{ matrix.pyver }}" ]]; then | |
| echo "CIBW_BUILD=${{ matrix.pyver }}*" >> $GITHUB_ENV | |
| fi | |
| - name: Build wheels | |
| uses: pypa/cibuildwheel@8d2b08b68458a16aeb24b64e68a09ab1c8e82084 # v3.4.1 | |
| env: | |
| CIBW_SKIP: cp36-* cp37-* cp38-* cp39-* pp* ${{ matrix.musl == 'musllinux' && '*manylinux*' || '*musllinux*' }} | |
| REQUIRE_CYTHON: 1 | |
| - uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: wheels-${{ matrix.os }}-${{ matrix.musl }}-${{ matrix.pyver }}-${{ matrix.qemu }} | |
| path: ./wheelhouse/*.whl | |
| upload_pypi: | |
| needs: [build_wheels] | |
| runs-on: ubuntu-latest | |
| environment: release | |
| permissions: | |
| id-token: write # IMPORTANT: this permission is mandatory for trusted publishing | |
| steps: | |
| - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| # unpacks default artifact into dist/ | |
| # if `name: artifact` is omitted, the action will create extra parent dir | |
| path: dist | |
| pattern: wheels-* | |
| merge-multiple: true | |
| - uses: pypa/gh-action-pypi-publish@cef221092ed1bacb1cc03d23a2d87d1d172e277b # v1.14.0 | |
| # To test: repository_url: https://test.pypi.org/legacy/ |