Skip to content

Commit

Permalink
Migrate to using uv + hatchling
Browse files Browse the repository at this point in the history
  • Loading branch information
davfsa committed Mar 3, 2025
1 parent d3b1acb commit 56ff0b7
Show file tree
Hide file tree
Showing 23 changed files with 3,291 additions and 126 deletions.
23 changes: 0 additions & 23 deletions .github/dependabot.yml

This file was deleted.

10 changes: 8 additions & 2 deletions .github/renovate.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"],
"dependencyDashboard": false
"extends": [
"config:recommended"
],
"dependencyDashboard": false,
"lockFileMaintenance": {
"enabled": true
},
"prHourlyLimit": 5
}
25 changes: 13 additions & 12 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,24 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
- name: Install the latest version of uv
uses: astral-sh/setup-uv@v5
with:
python-version: ${{ matrix.python-version }}

- name: Test Installation
shell: bash
run: |
pip install -r dev-requirements/build.txt
pip install .
pip uninstall -y hikari
uv pip install .
uv pip uninstall -y hikari
pip install .[speedups]
pip uninstall -y hikari
uv pip install .[speedups]
uv pip uninstall -y hikari
- name: Run tests
shell: bash
run: |
pip install -r dev-requirements.txt
uv pip install nox
nox -s pytest
nox -s pytest-all-features -- --cov-append
Expand Down Expand Up @@ -118,15 +116,18 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4

- name: Setup python
uses: actions/setup-python@v5
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.9

- name: Install nox
run: |
uv pip install nox
- name: Check stubs
if: always()
run: |
pip install -r dev-requirements.txt
nox -s generate-stubs
if [ "$(git status --short)" ]; then
echo "Stubs were not updated accordingly to the changes. Please run 'nox -s generate-stubs' and commit the changes to fix this."
Expand Down
7 changes: 4 additions & 3 deletions .github/workflows/fragments-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ jobs:
# needs a non-shallow clone.
fetch-depth: 0

- name: Setup python
uses: actions/setup-python@v5
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.9

- name: Check if changelog fragment was added
run: |
pip install -r dev-requirements/towncrier.txt
# FIXME: Temporary - https://github.com/astral-sh/uv/issues/8590
uv export --only-group=towncrier | uv pip install --requirements=-
if ! towncrier check --compare-with origin/${{ github.base_ref }}; then
exit 1
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/prepare-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
workflow_dispatch:
inputs:
version:
description: 'The version to prepare the release for'
description: "The version to prepare the release for"
required: true

jobs:
Expand All @@ -31,8 +31,8 @@ jobs:
git config --global user.name "hikari-bot"
git config --global user.email "90276125+hikari-bot[bot]@users.noreply.github.com"
- name: Setup python
uses: actions/setup-python@v5
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.9

Expand Down
21 changes: 4 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,15 @@ jobs:
git config --global user.name "hikari-bot"
git config --global user.email "90276125+hikari-bot[bot]@users.noreply.github.com"
- name: Setup python
uses: actions/setup-python@v5
- name: Setup uv
uses: astral-sh/setup-uv@v5
with:
python-version: 3.9

- name: Temporarily disable "include administrators" branch protection
uses: benjefferies/[email protected]
with:
access_token: ${{ steps.generate_token.outputs.token }}
enforce_admins: false

- name: Release
env:
VERSION: ${{ github.event.release.tag_name }}
DEPLOY_WEBHOOK_URL: ${{ secrets.DEPLOY_WEBHOOK_URL }}
TWINE_USERNAME: ${{ secrets.TWINE_USERNAME }}
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
UV_PUBLISH_USERNAME: ${{ secrets.TWINE_USERNAME }}
UV_PUBLISH_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
run: bash scripts/ci/release.sh

- name: Re-enable "include administrators" branch protection
uses: benjefferies/[email protected]
if: always()
with:
access_token: ${{ steps.generate_token.outputs.token }}
enforce_admins: true
1 change: 0 additions & 1 deletion dev-requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion pipelines/audit.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
@nox.session()
def audit(session: nox.Session) -> None:
"""Perform dependency scanning."""
session.install(*nox.dev_requirements("audit"))
session.install(*nox.dev_groups("audit"))
session.run(
"pip-audit",
"-r",
Expand Down
2 changes: 1 addition & 1 deletion pipelines/codespell.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
@nox.session()
def codespell(session: nox.Session) -> None:
"""Run codespell to check for spelling mistakes."""
session.install(*nox.dev_requirements("codespell"))
session.install(*nox.dev_groups("codespell"))
session.run(
"codespell",
"--builtin",
Expand Down
2 changes: 1 addition & 1 deletion pipelines/flake8.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def flake8_html(session: nox.Session) -> None:


def _flake8(session: nox.Session, extra_args: typing.Sequence[str] = ()) -> None:
session.install("-r", "requirements.txt", *nox.dev_requirements("flake8"))
session.install(".", *nox.dev_groups("flake8"))
session.run(
"flake8",
"--statistics",
Expand Down
4 changes: 2 additions & 2 deletions pipelines/format.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
@nox.session()
def reformat_code(session: nox.Session) -> None:
"""Remove trailing whitespace in source and then run ruff code formatter."""
session.install(*nox.dev_requirements("ruff"))
session.install(*nox.dev_groups("ruff"))

remove_trailing_whitespaces(session)

Expand All @@ -52,7 +52,7 @@ def reformat_code(session: nox.Session) -> None:
@nox.session()
def check_reformat_code(session: nox.Session) -> None:
"""TEMPORARY: Check if code is properly formatted."""
session.install(*nox.dev_requirements("ruff"))
session.install(*nox.dev_groups("ruff"))

# At the time of writing, sorting imports is not done when running formatting
# and needs to be done with ruff check
Expand Down
4 changes: 2 additions & 2 deletions pipelines/mkdocs.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def mkdocs(session: nox.Session):
"""Generate docs using mkdocs."""
_setup_environ(session)

session.install("-e", ".", *nox.dev_requirements("mkdocs"))
session.install(".", *nox.dev_groups("mkdocs"))

session.run("mkdocs", "build", "-d", config.DOCUMENTATION_OUTPUT_PATH)

Expand All @@ -52,7 +52,7 @@ def mkdocs_serve(session: nox.Session):
"""Start an HTTP server that serves the generated docs in real time."""
_setup_environ(session)

session.install("-e", ".", *nox.dev_requirements("mkdocs"))
session.install(".", *nox.dev_groups("mkdocs"))

if "--no-reload" in session.posargs:
session.run("mkdocs", "serve", "--no-livereload")
Expand Down
12 changes: 2 additions & 10 deletions pipelines/mypy.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,7 @@
@nox.session()
def mypy(session: nox.Session) -> None:
"""Perform static type analysis on Python source code using mypy."""
session.install(
"-r",
"requirements.txt",
"-r",
"speedup-requirements.txt",
"-r",
"server-requirements.txt",
*nox.dev_requirements("mypy", "ruff"),
)
session.install(".[speedups, server]", *nox.dev_groups("mypy", "ruff"))

_generate_stubs(session)

Expand All @@ -55,7 +47,7 @@ def mypy(session: nox.Session) -> None:
@nox.session()
def generate_stubs(session: nox.Session) -> None:
"""Generate the stubs for the package."""
session.install(*nox.dev_requirements("mypy", "ruff"))
session.install(*nox.dev_groups("mypy", "ruff"))
_generate_stubs(session)


Expand Down
9 changes: 3 additions & 6 deletions pipelines/nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@

from __future__ import annotations

import os as _os
import typing as _typing

from nox import options as _options
from nox import session as _session
from nox.sessions import Session

from pipelines import config as _pipelines_config

# Default sessions should be defined here
_options.sessions = ["reformat-code", "codespell", "pytest", "flake8", "slotscheck", "mypy", "verify-types"]
_options.default_venv_backend = "uv|venv"
Expand All @@ -48,10 +45,10 @@ def decorator(func: _NoxCallbackSig) -> _NoxCallbackSig:
return decorator


def dev_requirements(*dependencies: str) -> _typing.Sequence[str]:
def dev_groups(*groups: str) -> _typing.Sequence[str]:
args = []

for dep in dependencies:
args.extend(("-r", _os.path.join(_pipelines_config.DEV_REQUIREMENTS_DIRECTORY, f"{dep}.txt")))
for group in groups:
args.extend(("--group", group))

return args
12 changes: 2 additions & 10 deletions pipelines/pyright.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,12 @@ def pyright(session: nox.Session) -> None:
as hikari does not have 100% compatibility with pyright just yet. This
exists to make it easier to test and eventually reach that 100% compatibility.
"""
session.install(
"-r",
"requirements.txt",
"-r",
"speedup-requirements.txt",
"-r",
"server-requirements.txt",
*nox.dev_requirements("pyright"),
)
session.install(".[speedups, server]", *nox.dev_groups("pyright"))
session.run("pyright")


@nox.session()
def verify_types(session: nox.Session) -> None:
"""Verify the "type completeness" of types exported by the library using Pyright."""
session.install(".", *nox.dev_requirements("pyright"))
session.install(".", *nox.dev_groups("pyright"))
session.run("pyright", "--verifytypes", config.MAIN_PACKAGE, "--ignoreexternal")
8 changes: 2 additions & 6 deletions pipelines/pytest.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,13 @@ def pytest_all_features(session: nox.Session) -> None:
Coverage can be disabled with the `--skip-coverage` flag.
"""

_pytest(
session,
extra_install=("-r", "server-requirements.txt", "-r", "speedup-requirements.txt"),
python_flags=("-OO",),
)
_pytest(session, extra_install=(".[speedups, server]",), python_flags=("-OO",))


def _pytest(
session: nox.Session, *, extra_install: typing.Sequence[str] = (), python_flags: typing.Sequence[str] = ()
) -> None:
session.install("-r", "requirements.txt", *extra_install, *nox.dev_requirements("pytest"))
session.install(".", *extra_install, *nox.dev_groups("pytest"))

if "--skip-coverage" in session.posargs:
session.posargs.remove("--skip-coverage")
Expand Down
2 changes: 1 addition & 1 deletion pipelines/slotscheck.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,5 @@
@nox.session()
def slotscheck(session: nox.Session) -> None:
"""Check for common slotting mistakes."""
session.install(".", *nox.dev_requirements("slotscheck"))
session.install(".", *nox.dev_groups("slotscheck"))
session.run("slotscheck", "-m", config.MAIN_PACKAGE)
2 changes: 1 addition & 1 deletion pipelines/twemoji.nox.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@
@nox.session()
def twemoji_test(session: nox.Session):
"""Brute-force test all possible Twemoji mappings for Discord unicode emojis."""
session.install("-e", ".")
session.install(".")
session.run("python", "scripts/ci/test_twemoji_mapping.py", session.create_tmp())
18 changes: 9 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
[build-system]
requires = ["wheel", "setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
requires = ["hatchling>=1.14"]
build-backend = "hatchling.build"

[tool.setuptools.packages.find]
where = ["."]
include = ["hikari*"]

[tool.setuptools.dynamic]
version = { attr = "hikari._about.__version__" }
[tool.hatch.version]
path = "hikari/_about.py"
pattern = '__version__: typing\.Final\[str\] = \"(?P<version>[^\"]+)\"'

[project]
dynamic = ["version"]
Expand Down Expand Up @@ -119,7 +116,7 @@ mkdocs = [
# Minify
"mkdocs-minify-plugin==0.8.0",
# Towncrier draft changelogs
"mkdocs-towncrier==0.1.3",
"mkdocs-towncrier==0.1.4",
# Image viewer ext
# "mkdocs-glightbox==0.3.7",
]
Expand All @@ -139,6 +136,9 @@ ruff = ["ruff==0.9.9"]
slotscheck = ["slotscheck==0.19.1"]
towncrier = ["towncrier==24.8.0"]

[tool.uv]
required-version = "~=0.5"

[tool.ruff]
line-length = 120
target-version = "py39"
Expand Down
3 changes: 2 additions & 1 deletion scripts/ci/prepare-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ sed "/^__docs__.*/, \${s||__docs__: typing.Final[str] = \"https://docs.hikari-py
echo "===== UPDATING CHANGELOG ====="
echo "-- Installing dependencies --"
# Installing our own package is necessary to have towncrier detect the version
pip install -r dev-requirements/towncrier.txt -e .
# FIXME: Change to allow also just using pip
uv pip install --group towncrier .

echo "-- Running towncrier --"
towncrier --yes
Expand Down
Loading

0 comments on commit 56ff0b7

Please sign in to comment.