Skip to content

Commit

Permalink
Use uv as installer (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaborbernat authored Sep 8, 2024
1 parent 49a89ef commit a420284
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 77 deletions.
84 changes: 47 additions & 37 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,39 +28,39 @@ jobs:
- "3.9"
- "3.8"
os:
- ubuntu-22.04
- windows-2022
- macos-12
- ubuntu-latest
- windows-latest
- macos-latest

steps:
- name: Setup python for tox
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: "3.12"
python-version: ${{ matrix.py }}
allow-prereleases: true
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: install hatch
run: uv pip install hatch --system
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Pick environment to run
run: |
import codecs; import os
py = "${{ matrix.py }}"
py = "test.{}".format(py if py.startswith("pypy") else f"py{py}")
print(f"Picked {py}")
with codecs.open(os.environ["GITHUB_ENV"], mode="a", encoding="utf-8") as file_handler:
file_handler.write("FORCE_COLOR=1\n")
file_handler.write(f"ENV={py}\n")
file_handler.write(f"FORCE_COLOR=1\nENV={py}\n")
shell: python
- name: Install Hatch
uses: pypa/hatch@install
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup python for test ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
allow-prereleases: true
- name: Setup test environment
run: |
hatch -v env create ${ENV}
hatch run ${ENV}:pip freeze
hatch run ${ENV}:uv pip tree
shell: bash
- name: Run test suite
run: hatch -v run ${ENV}:run
Expand All @@ -83,19 +83,24 @@ jobs:

coverage:
name: Combine coverage
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
needs: test
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Let us have colors
run: echo "FORCE_COLOR=true" >> "$GITHUB_ENV"
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Let us have colors
run: echo "FORCE_COLOR=true" >> "$GITHUB_ENV"
- name: Install Hatch
uses: pypa/hatch@install
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: install hatch
run: uv pip install hatch --system
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup coverage tool
run: |
hatch -v env create coverage
Expand All @@ -121,23 +126,28 @@ jobs:
fail-fast: false
matrix:
os:
- ubuntu-22.04
- windows-2022
- ubuntu-latest
- windows-latest
env:
- {"name": "default", "target": "show"}
- {"name": "type", "target": "run"}
- {"name": "docs", "target": "build"}
- {"name": "readme", "target": "run"}
- { "name": "default", "target": "show" }
- { "name": "type", "target": "run" }
- { "name": "docs", "target": "build" }
- { "name": "readme", "target": "run" }
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Python "3.12"
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install Hatch
uses: pypa/hatch@install
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v2
with:
enable-cache: true
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: install hatch
run: uv pip install hatch --system
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup ${{ matrix.env.name }}
run: |
hatch -v env create ${{ matrix.env.name }}
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

jobs:
release:
runs-on: ubuntu-22.04
runs-on: ubuntu-latest
environment:
name: release
url: https://pypi.org/p/platformdirs
Expand All @@ -16,12 +16,14 @@ jobs:
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: setup uv for tox
uses: yezz123/setup-uv@v4
- name: Install build
run: python -m pip install build
run: uv pip install build[uv] --system
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Build package
run: pyproject-build -s -w . -o dist
run: pyproject-build --installer uv --sdist --wheel . --outdir dist
- name: Publish to PyPI
uses: pypa/gh-action-pypi-publish@v1.10.1
27 changes: 15 additions & 12 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@ repos:
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.29.2
hooks:
- id: check-github-workflows
args: ["--verbose"]
- repo: https://github.com/codespell-project/codespell
rev: v2.3.0
hooks:
- id: codespell
additional_dependencies: [ "tomli>=2.0.1" ]
- repo: https://github.com/PyCQA/docformatter
rev: v1.7.5
additional_dependencies: ["tomli>=2.0.1"]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "2.2.3"
hooks:
- id: docformatter
additional_dependencies: [ "tomli>=2.0.1" ]
args: [ "--in-place", "--config", "./pyproject.toml" ]
- id: pyproject-fmt
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.6.3"
rev: "v0.6.4"
hooks:
- id: ruff-format
- id: ruff
args: [ "--fix", "--unsafe-fixes", "--exit-non-zero-on-fix" ]
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "2.2.1"
args: ["--fix", "--unsafe-fixes", "--exit-non-zero-on-fix"]
- repo: https://github.com/rbubley/mirrors-prettier
rev: "v3.3.3"
hooks:
- id: pyproject-fmt
additional_dependencies: ["tox>=4.14.2"]
- id: prettier
args: ["--print-width=120", "--prose-wrap=always"]
- repo: meta
hooks:
- id: check-hooks-apply
Expand Down
52 changes: 27 additions & 25 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
build-backend = "hatchling.build"
requires = [
"hatch-vcs>=0.4",
"hatchling>=1.18",
"hatchling>=1.25",
]

[project]
Expand Down Expand Up @@ -46,20 +46,20 @@ dynamic = [
"version",
]
optional-dependencies.docs = [
"furo>=2023.9.10",
"proselint>=0.13",
"sphinx>=7.2.6",
"sphinx-autodoc-typehints>=1.25.2",
"furo>=2024.8.6",
"proselint>=0.14",
"sphinx>=8.0.2",
"sphinx-autodoc-typehints>=2.4",
]
optional-dependencies.test = [
"appdirs==1.4.4",
"covdefaults>=2.3",
"pytest>=7.4.3",
"pytest-cov>=4.1",
"pytest-mock>=3.12",
"pytest>=8.3.2",
"pytest-cov>=5",
"pytest-mock>=3.14",
]
optional-dependencies.type = [
"mypy>=1.8",
"mypy>=1.11.2",
]
urls.Documentation = "https://platformdirs.readthedocs.io"
urls.Homepage = "https://github.com/platformdirs/platformdirs"
Expand All @@ -76,19 +76,21 @@ build.targets.sdist.include = [
version.source = "vcs"

[tool.hatch.envs.default]
installer = "uv"
description = "Development environment"
features = [
"test",
"docs",
"type",
]
scripts = { show = [
"python -m pip list --format=columns",
"uv pip tree",
'python -c "import sys; print(sys.executable)"',
] }

[tool.hatch.envs.test]
template = "test"
installer = "uv"
# dev-mode = false # cannot enable this until https://github.com/pypa/hatch/issues/1237
description = "Run the test suite"
matrix = [
Expand All @@ -105,7 +107,9 @@ matrix = [
features = [
"test",
]
env-vars = { COVERAGE_FILE = "report/.coverage.{matrix:python}", COVERAGE_PROCESS_START = "pyproject.toml", _COVERAGE_SRC = "src/platformdirs" }
env-vars.COVERAGE_FILE = "report/.coverage.{matrix:python}"
env-vars.COVERAGE_PROCESS_START = "pyproject.toml"
env-vars._COVERAGE_SRC = "src/platformdirs"
[tool.hatch.envs.test.scripts]
run = [
"""
Expand All @@ -118,11 +122,12 @@ run = [

[tool.hatch.envs.coverage]
template = "coverage"
installer = "uv"
description = "combine coverage files and generate diff"
dependencies = [
"covdefaults>=2.3",
"coverage[toml]>=7.3.2",
"diff-cover>=8.0.1",
"coverage[toml]>=7.6.1",
"diff-cover>=9.2",
]
env-vars = { COVERAGE_FILE = "report/.coverage" }
[tool.hatch.envs.coverage.scripts]
Expand All @@ -136,6 +141,7 @@ run = [

[tool.hatch.envs.type]
template = "type"
installer = "uv"
description = "Run the type checker"
python = "3.12"
dev-mode = false
Expand All @@ -150,18 +156,20 @@ scripts = { run = [

[tool.hatch.envs.fix]
template = "fix"
installer = "uv"
description = "Run the pre-commit tool to lint and autofix issues"
python = "3.12"
detached = true
dependencies = [
"pre-commit>=3.6",
"pre-commit-uv>=4.1",
]
scripts = { "run" = [
"pre-commit run --all-files --show-diff-on-failure",
] }

[tool.hatch.envs.docs]
template = "docs"
installer = "uv"
description = "Build documentation using Sphinx"
python = "3.12"
dev-mode = false
Expand All @@ -178,15 +186,16 @@ build = [

[tool.hatch.envs.readme]
template = "readme"
installer = "uv"
description = "check that the long description is valid"
python = "3.12"
dependencies = [
"build[virtualenv]>=1.0.3",
"twine>=4.0.2",
"check-wheel-contents>=0.6.0",
"build[uv]>=1.2.2",
"twine>=5.1.1",
"check-wheel-contents>=0.6",
]
scripts = { "run" = [
"python -m build -o dist",
"pyproject-build --installer uv -o dist",
"twine check dist/*.whl dist/*.tar.gz",
"check-wheel-contents dist",
] }
Expand Down Expand Up @@ -232,13 +241,6 @@ builtin = "clear,usage,en-GB_to_en-US"
count = true
quiet-level = 3

[tool.docformatter]
blank = true
recursive = true
pre-summary-newline = true
wrap-descriptions = 120
wrap-summaries = 120

[tool.pyproject-fmt]
max_supported_python = "3.13"

Expand Down

0 comments on commit a420284

Please sign in to comment.