Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate the project to using uv #226

Merged
merged 5 commits into from
Sep 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 46 additions & 30 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ jobs:
with:
python-version: "3.10"

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: install nox
run: |
python -m pip install nox
Expand All @@ -36,6 +39,9 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: install nox
run: |
python -m pip install nox
Expand All @@ -57,36 +63,40 @@ jobs:
# retention-days: 1
# if-no-files-found: error

# upload-coverage:
# needs: [test]
# runs-on: ubuntu-latest

# steps:
# - name: Checkout repo
# uses: actions/checkout@v4

# - name: Setup python 3.10
# uses: actions/setup-python@v5
# with:
# python-version: "3.10"

# - name: Download coverage
# uses: actions/download-artifact@v3
# with:
# name: coverage

# - name: Combine coverage
# run: |
# pip install -r ./genshin-dev/pytest-requirements.txt
# coverage combine
# coverage xml -i

# - name: Upload coverage to codeclimate
# uses: paambaati/[email protected]
# env:
# CC_TEST_REPORTER_ID: cd8c7d84ae5f98d86882d666dce0946fe5aae1e63f442995bd9c6e17869e6513
# with:
# coverageLocations: .coverage.xml:coverage.py
upload-coverage:
needs: [test]
runs-on: ubuntu-latest
if: false # Temporarily disabled

steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Setup python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Download coverage
uses: actions/download-artifact@v3
with:
name: coverage

- name: Combine coverage
run: |
pip install -r ./genshin-dev/pytest-requirements.txt
coverage combine
coverage xml -i

- name: Upload coverage to codeclimate
uses: paambaati/[email protected]
env:
CC_TEST_REPORTER_ID: cd8c7d84ae5f98d86882d666dce0946fe5aae1e63f442995bd9c6e17869e6513
with:
coverageLocations: .coverage.xml:coverage.py

type-check:
runs-on: ubuntu-latest
Expand All @@ -99,6 +109,9 @@ jobs:
with:
python-version: "3.10"

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: install nox
run: |
python -m pip install nox
Expand All @@ -117,6 +130,9 @@ jobs:
with:
python-version: "3.10"

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: install nox
run: |
python -m pip install nox
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,13 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install dependencies
run: |
python -m pip install nox mkdocs-material
python -m pip install nox

- name: Generate API Documentation
run: |
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,11 @@ jobs:
uses: actions/setup-python@v2
with:
python-version: 3.9

- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Install pypa/build
- name: Build and publish
run: |
python -m pip install build --user
- name: Build a binary wheel and a source tarball
run: |
python -m build --sdist --wheel --outdir dist/ .
- name: Publish distribution to PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}
uv build -p 3.9
uv publish --token ${{ secrets.PYPI_API_TOKEN }}
22 changes: 0 additions & 22 deletions genshin-dev/README.md

This file was deleted.

1 change: 0 additions & 1 deletion genshin-dev/docs-requirements.txt

This file was deleted.

1 change: 0 additions & 1 deletion genshin-dev/lint-requirements.txt

This file was deleted.

7 changes: 0 additions & 7 deletions genshin-dev/pytest-requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions genshin-dev/reformat-requirements.txt

This file was deleted.

47 changes: 0 additions & 47 deletions genshin-dev/setup.py

This file was deleted.

4 changes: 0 additions & 4 deletions genshin-dev/typecheck-requirements.txt

This file was deleted.

2 changes: 1 addition & 1 deletion genshin/models/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import abc
import datetime
import typing
from typing import Annotated

import pydantic
from typing import Annotated

from genshin.constants import CN_TIMEZONE

Expand Down
2 changes: 1 addition & 1 deletion genshin/models/starrail/chronicle/characters.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Starrail chronicle character."""

import enum
from typing import Any, Optional
from collections.abc import Mapping, Sequence
from typing import Any, Optional

import pydantic

Expand Down
2 changes: 1 addition & 1 deletion genshin/models/zzz/chronicle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""ZZZ chronicle models."""

from .challenge import *
from .month_info import *
from .notes import *
from .stats import *
from .month_info import *
5 changes: 3 additions & 2 deletions genshin/models/zzz/chronicle/month_info.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from enum import Enum
import typing
from genshin.models.model import APIModel, Aliased, DateTimeField
from enum import Enum

from genshin.models.model import Aliased, APIModel, DateTimeField

__all__ = (
"PolychromeIncomeType",
Expand Down
54 changes: 25 additions & 29 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
PACKAGE = "genshin"
GENERAL_TARGETS = ["./noxfile.py", "./genshin", "./tests"]
PYRIGHT_ENV = {"PYRIGHT_PYTHON_FORCE_VERSION": "latest"}
UV_RUN_EXTRA = ("uv", "run", "--isolated", "--no-dev", "--extra")

LOGGER = logging.getLogger("nox")

Expand All @@ -27,62 +28,50 @@ def verbose_args() -> typing.Sequence[str]:
return ["--verbose"] if isverbose() else []


def install_requirements(session: nox.Session, *requirements: str, literal: bool = False) -> None:
"""Install requirements."""
if not literal and all(requirement.isalpha() for requirement in requirements):
files = ["requirements.txt"] + [f"./genshin-dev/{requirement}-requirements.txt" for requirement in requirements]
requirements = ("pip", *tuple(arg for file in files for arg in ("-r", file)))

session.install("--upgrade", *requirements, silent=not isverbose())


@nox.session()
def docs(session: nox.Session) -> None:
"""Generate docs for this project using Pdoc."""
install_requirements(session, "docs")

output_directory = pathlib.Path("./docs/pdoc/")
session.log("Building docs into %s", output_directory)

session.run("pdoc3", "--html", PACKAGE, "-o", str(output_directory), "--force")
session.run(*UV_RUN_EXTRA, "docs", "pdoc3", "--html", PACKAGE, "-o", str(output_directory), "--force")
session.log("Docs generated: %s", output_directory / "index.html")


@nox.session()
def lint(session: nox.Session) -> None:
"""Run this project's modules against the pre-defined flake8 linters."""
install_requirements(session, "lint")
session.run("ruff", "check", *GENERAL_TARGETS, *verbose_args())
session.run(*UV_RUN_EXTRA, "lint", "ruff", "check", *GENERAL_TARGETS, *verbose_args())


@nox.session()
def reformat(session: nox.Session) -> None:
"""Reformat this project's modules to fit the standard style."""
install_requirements(session, "reformat")
session.run("python", "-m", "black", *GENERAL_TARGETS, *verbose_args())
session.run(*UV_RUN_EXTRA, "reformat", "black", *GENERAL_TARGETS, *verbose_args())
# sort __all__ and format imports
session.run(
"python",
"-m",
*UV_RUN_EXTRA,
"reformat",
"ruff",
"check",
"--preview",
"--select",
"RUF022,I",
"--fix",
*GENERAL_TARGETS,
*verbose_args(),
)
# fix all fixable linting errors
session.run("ruff", "check", "--fix", *GENERAL_TARGETS, *verbose_args())
session.run(*UV_RUN_EXTRA, "reformat", "ruff", "check", "--fix", *GENERAL_TARGETS, *verbose_args())


@nox.session(name="test")
def test(session: nox.Session) -> None:
"""Run this project's tests using pytest."""
install_requirements(session, "pytest")

session.run(
*UV_RUN_EXTRA,
"pytest",
"--extra",
"all",
"pytest",
"--asyncio-mode=auto",
"-r",
Expand All @@ -103,18 +92,25 @@ def test(session: nox.Session) -> None:
@nox.session(name="type-check")
def type_check(session: nox.Session) -> None:
"""Statically analyse and veirfy this project using pyright and mypy."""
install_requirements(session, "typecheck")
session.run("pyright", PACKAGE, *verbose_args(), env=PYRIGHT_ENV)
session.run("mypy", PACKAGE, *verbose_args())
session.run(*UV_RUN_EXTRA, "typecheck", "--extra", "all", "pyright", PACKAGE, *verbose_args(), env=PYRIGHT_ENV)
session.run(*UV_RUN_EXTRA, "typecheck", "--extra", "all", "mypy", PACKAGE, *verbose_args())


@nox.session(name="verify-types")
def verify_types(session: nox.Session) -> None:
"""Verify the "type completeness" of types exported by the library using pyright."""
install_requirements(session, ".", "--force-reinstall", "--no-deps")
install_requirements(session, "typecheck")

session.run("pyright", "--verifytypes", PACKAGE, "--ignoreexternal", *verbose_args(), env=PYRIGHT_ENV)
session.run(
*UV_RUN_EXTRA,
"typecheck",
"--extra",
"all",
"pyright",
"--verifytypes",
PACKAGE,
"--ignoreexternal",
*verbose_args(),
env=PYRIGHT_ENV,
)


@nox.session(python=False)
Expand Down
Loading
Loading