From a1319e08a48fdc4ac4af258f60cddbd5708c855a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bern=C3=A1t=20G=C3=A1bor?= Date: Tue, 17 Sep 2024 16:05:25 -0700 Subject: [PATCH] Improve the CI (#90) --- .github/workflows/check.yaml | 54 +++++++++++++++++ .github/workflows/check.yml | 104 --------------------------------- .github/workflows/release.yaml | 48 +++++++++++++++ .github/workflows/release.yml | 29 --------- README.md | 2 +- pyproject.toml | 3 +- tox.ini | 54 ++++++++--------- 7 files changed, 130 insertions(+), 164 deletions(-) create mode 100644 .github/workflows/check.yaml delete mode 100644 .github/workflows/check.yml create mode 100644 .github/workflows/release.yaml delete mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml new file mode 100644 index 0000000..0fb2d44 --- /dev/null +++ b/.github/workflows/check.yaml @@ -0,0 +1,54 @@ +name: check +on: + workflow_dispatch: + push: + branches: ["main"] + tags-ignore: ["**"] + pull_request: + schedule: + - cron: "0 8 * * *" + +concurrency: + group: check-${{ github.ref }} + cancel-in-progress: true + +jobs: + test: + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + env: + - "3.13" + - "3.12" + - "3.11" + - "3.10" + - "3.9" + - "3.8" + - type + - dev + - pkg_meta + steps: + - name: Install OS dependencies + run: sudo apt-get install graphviz -y + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Install tox + run: uv tool install --python-preference only-managed --python 3.13 tox --with tox-uv + - name: Install Python + if: startsWith(matrix.env, '3.') && matrix.env != '3.13' + run: uv python install --python-preference only-managed ${{ matrix.env }} + - name: Setup test suite + run: tox run -vv --notest --skip-missing-interpreters false -e ${{ matrix.env }} + - name: Run test suite + run: tox run --skip-pkg-install -e ${{ matrix.env }} + env: + PYTEST_ADDOPTS: "-vv --durations=20" + DIFF_AGAINST: HEAD diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml deleted file mode 100644 index 55359f7..0000000 --- a/.github/workflows/check.yml +++ /dev/null @@ -1,104 +0,0 @@ -name: check -on: - workflow_dispatch: - push: - branches: ["main"] - tags-ignore: ["**"] - pull_request: - schedule: - - cron: "0 8 * * *" - -concurrency: - group: check-${{ github.ref }} - cancel-in-progress: true - -jobs: - test: - name: test ${{ matrix.py }} on ${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false - matrix: - py: - - "3.13" - - "3.12" - - "3.11" - - "3.10" - - "3.9" - - "3.8" - os: - - ubuntu-latest - - windows-latest - - macos-latest - include: - - { os: ubuntu-latest, py: "pypy3.10" } - - { os: ubuntu-latest, py: "pypy3.8" } - steps: - - name: setup python for tox - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - uses: actions/checkout@v4 - - name: Set up Python ${{ matrix.py }} on ${{ matrix.os }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.py }} - allow-prereleases: true - - name: Create and activate a virtual environment (Windows) - if: ${{ runner.os == 'Windows' }} - run: | - irm https://astral.sh/uv/install.ps1 | iex - uv venv .venv - "VIRTUAL_ENV=.venv" | Out-File -FilePath $env:GITHUB_ENV -Append - "$PWD/.venv/Scripts" | Out-File -FilePath $env:GITHUB_PATH -Append - - name: Create and activate a virtual environment (Unix) - if: ${{ runner.os != 'Windows' }} - run: | - curl -LsSf https://astral.sh/uv/install.sh | sh - uv venv .venv - echo "VIRTUAL_ENV=.venv" >> $GITHUB_ENV - echo "$PWD/.venv/bin" >> $GITHUB_PATH - - name: Install self - run: uv pip install tox-uv@. - - name: setup python for test ${{ matrix.py }} - uses: actions/setup-python@v5 - with: - python-version: ${{ matrix.py }} - allow-prereleases: true - - name: Pick environment to run - run: | - import codecs; import os; import sys - env = "TOXENV=py{}{}\n".format(*sys.version_info[0:2]) - print("Picked:\n{}for{}".format(env, sys.version)) - with codecs.open(os.environ["GITHUB_ENV"], "a", "utf-8") as file_handler: - file_handler.write(env) - shell: python - - name: setup test suite - run: tox run -vv --notest --skip-missing-interpreters false - - name: run test suite - run: tox run --skip-pkg-install - - check: - name: tox env ${{ matrix.tox_env }} - runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - tox_env: - - type - - dev - - readme - steps: - - uses: actions/checkout@v4 - - name: setup Python 3.12 - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - name: Install uv - run: python -m pip install uv - - name: Uninstall pip - run: python -m pip uninstall pip -y - - name: Install self - run: uv pip install --system tox-uv@. - - name: run check for ${{ matrix.tox_env }} - run: python -m tox -e ${{ matrix.tox_env }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..5cd01e0 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,48 @@ +name: Release to PyPI +on: + push: + tags: ["*"] + +env: + dists-artifact-name: python-package-distributions + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install the latest version of uv + uses: astral-sh/setup-uv@v3 + with: + enable-cache: true + cache-dependency-glob: "pyproject.toml" + github-token: ${{ secrets.GITHUB_TOKEN }} + - name: Build package + run: uv build --python 3.13 --python-preference only-managed --sdist --wheel . --out-dir dist + - name: Store the distribution packages + uses: actions/upload-artifact@v4 + with: + name: ${{ env.dists-artifact-name }} + path: dist/* + + release: + needs: + - build + runs-on: ubuntu-latest + environment: + name: release + url: https://pypi.org/project/tox-uv/${{ github.ref_name }} + permissions: + id-token: write + steps: + - name: Download all the dists + uses: actions/download-artifact@v4 + with: + name: ${{ env.dists-artifact-name }} + path: dist/ + - name: Publish to PyPI + uses: pypa/gh-action-pypi-publish@v1.10.1 + with: + attestations: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml deleted file mode 100644 index 937b3f0..0000000 --- a/.github/workflows/release.yml +++ /dev/null @@ -1,29 +0,0 @@ -name: Release to PyPI -on: - push: - tags: ["*"] - -jobs: - release: - runs-on: ubuntu-latest - environment: - name: release - url: https://pypi.org/p/tox-uv - permissions: - id-token: write - steps: - - name: Setup python to build package - uses: actions/setup-python@v5 - with: - python-version: "3.12" - - name: Install uv - run: python -m pip install uv - - name: Install build - run: uv pip install --system build[virtualenv] - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - name: Build package - run: pyproject-build -s -w . -o dist - - name: Publish to PyPI - uses: pypa/gh-action-pypi-publish@v1.10.1 diff --git a/README.md b/README.md index 4412962..976bf72 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PyPI version](https://badge.fury.io/py/tox-uv.svg)](https://badge.fury.io/py/tox-uv) [![PyPI Supported Python Versions](https://img.shields.io/pypi/pyversions/tox-uv.svg)](https://pypi.python.org/pypi/tox-uv/) -[![check](https://github.com/tox-dev/tox-uv/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/tox-uv/actions/workflows/check.yml) +[![check](https://github.com/tox-dev/tox-uv/actions/workflows/check.yaml/badge.svg)](https://github.com/tox-dev/tox-uv/actions/workflows/check.yaml) [![Downloads](https://static.pepy.tech/badge/tox-uv/month)](https://pepy.tech/project/tox-uv) **tox-uv** is a tox plugin which replaces virtualenv and pip with uv in your tox environments. diff --git a/pyproject.toml b/pyproject.toml index 2d1aeb5..c7be88e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,9 +47,10 @@ dependencies = [ "typing-extensions>=4.12.2; python_version<'3.10'", "uv<1,>=0.4.7", ] -optional-dependencies.test = [ +optional-dependencies.testing = [ "covdefaults>=2.3", "devpi-process>=1", + "diff-cover>=9.2", "pytest>=8.3.2", "pytest-cov>=5", "pytest-mock>=3.14", diff --git a/tox.ini b/tox.ini index f2549cb..ccba69f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,7 +1,7 @@ [tox] requires = tox>=4.2 - tox-uv>=1.11.2 + tox-uv>=1.11.3 env_list = fix 3.13 @@ -11,33 +11,34 @@ env_list = 3.9 3.8 type - readme + pkg_meta skip_missing_interpreters = true [testenv] -description = run the unit tests with pytest under {basepython} +description = run the unit tests with pytest under {base_python} package = wheel wheel_build_env = .pkg extras = - test + testing +pass_env = + DIFF_AGAINST + PYTEST_* set_env = - COVERAGE_FILE = {toxworkdir}{/}.coverage.{envname} + COVERAGE_FILE = {work_dir}/.coverage.{env_name} commands = - pytest {tty:--color=yes} {posargs: \ - --cov {envsitepackagesdir}{/}tox_uv --cov {toxinidir}{/}tests --cov-context=test \ - --no-cov-on-fail --cov-config {toxinidir}{/}pyproject.toml \ - --cov-report term-missing:skip-covered --junitxml {toxworkdir}{/}junit.{envname}.xml \ - --cov-report html:{envtmpdir}{/}htmlcov --durations=5 \ + python -m pytest {tty:--color=yes} {posargs: \ + --cov {env_site_packages_dir}{/}tox_uv --cov {tox_root}{/}tests \ + --cov-config=pyproject.toml --no-cov-on-fail --cov-report term-missing:skip-covered --cov-context=test \ + --cov-report html:{env_tmp_dir}{/}htmlcov --cov-report xml:{work_dir}{/}coverage.{env_name}.xml \ + --junitxml {work_dir}{/}junit.{env_name}.xml \ tests} + diff-cover --compare-branch {env:DIFF_AGAINST:origin/main} {work_dir}{/}coverage.{env_name}.xml --fail-under 100 [testenv:fix] -description = run static analysis and style check using flake8 +description = format the code base to adhere to our styles, and complain about what we cannot do automatically skip_install = true deps = - pre-commit-uv>=4.1 -pass_env = - HOMEPATH - PROGRAMDATA + pre-commit-uv>=4.1.1 commands = pre-commit run --all-files --show-diff-on-failure @@ -45,30 +46,25 @@ commands = description = run type check on code base deps = mypy==1.11.2 -set_env = - {tty:MYPY_FORCE_COLOR = 1} commands = - mypy src {posargs} - mypy tests {posargs} + mypy src + mypy tests -[testenv:readme] -description = check that the package metadata is correct +[testenv:pkg_meta] +description = check that the long description is valid skip_install = true deps = - build[virtualenv]>=1.2.2 + check-wheel-contents>=0.6 twine>=5.1.1 -set_env = - {tty:FORCE_COLOR = 1} -change_dir = {toxinidir} + uv>=0.4.10 commands = - python -m build --sdist --wheel -o {envtmpdir} . - twine check {envtmpdir}{/}* + uv build --sdist --wheel --out-dir {env_tmp_dir} . + twine check {env_tmp_dir}{/}* + check-wheel-contents --no-config {env_tmp_dir} [testenv:dev] description = generate a DEV environment package = editable -extras = - test commands = uv pip tree python -c 'import sys; print(sys.executable)'