From 27dc90621531a88df833c232f680c11a38e74c79 Mon Sep 17 00:00:00 2001 From: Florian Rupprecht Date: Thu, 21 Dec 2023 16:49:03 +0100 Subject: [PATCH] Update template --- .github/dependabot.yaml | 13 ++++++ .github/workflows/docs.yaml | 37 ++++++++-------- .github/workflows/test.yaml | 79 ++++++++++++++++------------------ .gitignore | 2 + .pre-commit-config.yaml | 55 ++++++++++++------------ pyproject.toml | 84 +++++++++++++++++++++++++++++-------- 6 files changed, 164 insertions(+), 106 deletions(-) create mode 100644 .github/dependabot.yaml diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..7dbc681 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,13 @@ +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: +- package-ecosystem: pip + directory: / + schedule: + interval: monthly +- package-ecosystem: github-actions + directory: / + schedule: + interval: monthly diff --git a/.github/workflows/docs.yaml b/.github/workflows/docs.yaml index ce973c7..b86e5d5 100644 --- a/.github/workflows/docs.yaml +++ b/.github/workflows/docs.yaml @@ -5,29 +5,30 @@ permissions: on: workflow_run: - workflows: ["Python Tests"] + workflows: [Python Tests] types: - - completed + - completed branches: - - main + - main jobs: build-and-publish-docs: if: ${{ github.event.workflow_run.conclusion == 'success' }} runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install poetry - poetry install -E docs - - name: Build docs - run: | - poetry run pdoc src/llama_runner -o docs_build -t docs/pdoc-theme --docformat google - touch docs_build/.nojekyll - - uses: JamesIves/github-pages-deploy-action@v4 - with: - folder: docs_build + - uses: actions/checkout@v4 + - uses: actions/setup-python@v5 + with: + python-version-file: pyproject.toml + - name: Install dependencies + run: | + python -m pip install poetry + poetry install -E docs + - name: Build docs + run: | + APP_MODULE_NAME=$(ls src -U | head -1) # Get the first module name in the src directory + poetry run pdoc src/"$APP_MODULE_NAME" -o docs_build -t docs/pdoc-theme --docformat google + touch docs_build/.nojekyll + - uses: JamesIves/github-pages-deploy-action@v4 + with: + folder: docs_build diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 83fa06d..c3b7d9a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -3,59 +3,52 @@ name: Python Tests on: push: branches: - - main + - main pull_request: jobs: unit: - permissions: - contents: read - pull-requests: write runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - name: Install dependencies - run: | - python -m pip install poetry - poetry install - - name: Run tests - run: poetry run pytest --junitxml=pytest.xml --cov-report=term-missing:skip-covered --cov-report=xml:coverage.xml --cov=src tests | tee pytest-coverage.txt - - name: Pytest coverage comment - if: github.event_name == 'pull_request' - uses: MishaKav/pytest-coverage-comment@main - with: - pytest-coverage-path: ./pytest-coverage.txt - junitxml-path: ./pytest.xml - - name: Upload coverage to Codecov - uses: codecov/codecov-action@v3 - with: - token: ${{ secrets.CODECOV_TOKEN }} + - uses: actions/checkout@v4 + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@v5 + with: + python-version-file: pyproject.toml + cache: poetry + - name: Install dependencies + run: | + poetry install + - name: Run tests + id: run-tests + run: > + poetry run pytest \ + --junitxml=pytest.xml \ + --cov-report=term-missing:skip-covered \ + --cov-report=xml:coverage.xml \ + --cov=src tests \ + --log-level=DEBUG \ + --verbose + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 - black: + ruff: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: psf/black@stable + - uses: actions/checkout@v4 + - uses: chartboost/ruff-action@v1 mypy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - uses: actions/setup-python@v4 - with: - python-version: "3.11" - - run: | - pip install poetry - poetry install - poetry run mypy . - - isort: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - uses: isort/isort-action@v1 - with: - configuration: --profile black + - uses: actions/checkout@v4 + - name: Install poetry + run: pipx install poetry + - uses: actions/setup-python@v5 + with: + python-version: '3.11' + cache: poetry + - run: | + poetry install + poetry run mypy . diff --git a/.gitignore b/.gitignore index 2dc53ca..ac28870 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +.ruff_cache + # Byte-compiled / optimized / DLL files __pycache__/ *.py[cod] diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c0a3429..1710526 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,38 +1,31 @@ fail_fast: false - repos: - - repo: https://github.com/ambv/black - rev: 23.3.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.8 hooks: - - id: black - args: [--diff, --check] - + - id: ruff + - id: ruff-format - repo: https://github.com/pre-commit/mirrors-mypy - rev: v1.3.0 + rev: v1.7.1 hooks: - id: mypy - args: [--ignore-missing-imports] - - - repo: https://github.com/pycqa/isort - rev: 5.12.0 - hooks: - - id: isort - name: isort (python) - args: [--profile black] - - - repo: https://github.com/pre-commit/pygrep-hooks - rev: v1.10.0 + args: + - --ignore-missing-imports + - repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks + rev: v2.11.0 hooks: - - id: python-check-blanket-noqa - - id: python-check-blanket-type-ignore - - id: python-check-mock-methods - - id: python-no-eval - - id: python-no-log-warn - - id: python-use-type-annotations - - id: text-unicode-replacement-char - + - id: pretty-format-yaml + args: + - --autofix + - --indent=2 + - id: pretty-format-toml + exclude: ^poetry.lock$ + args: + - --autofix + - --indent=2 + - --no-sort - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-case-conflict - id: end-of-file-fixer @@ -48,3 +41,11 @@ repos: - id: check-merge-conflict - id: check-yaml - id: check-json + - id: check-toml + - repo: local + hooks: + - id: yaml-file-extension + name: Prefer .yaml over .yml. + entry: YAML files must have .yaml extension. + language: fail + files: \.yml$ diff --git a/pyproject.toml b/pyproject.toml index b02aa81..2287f3c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,39 +2,87 @@ name = "llama_runner" version = "0.1.0" description = "A beautiful description." -authors = ["Reinder Vos de Wael "] +authors = [ "Reinder Vos de Wael " ] license = "LGPL-2.1" readme = "README.md" -packages = [{include = "llama_runner", from = "src"}] -[tool.poetry.dependencies] -python = "^3.10" -fire = "^0.5.0" -llama = {git = "https://github.com/facebookresearch/llama.git"} + [[tool.poetry.packages]] + include = "llama_runner" + from = "src" + + [tool.poetry.dependencies] + python = "^3.10" + fire = "^0.5.0" + + [tool.poetry.dependencies.llama] + git = "https://github.com/facebookresearch/llama.git" [tool.poetry.group.dev.dependencies] pytest = "^7.3.2" mypy = "^1.4.0" -black = "^23.3.0" -isort = "^5.12.0" pre-commit = "^3.3.3" pytest-cov = "^4.1.0" - [tool.poetry.group.docs.dependencies] pdoc = "^14.0.0" -[tool.poetry.extras] -docs = ["pdoc"] - -[build-system] -requires = ["poetry-core>=1.2.0"] -build-backend = "poetry.core.masonry.api" + [tool.poetry.extras] + docs = [ "pdoc" ] [tool.pytest.ini_options] -pythonpath = [ - "src" -] +pythonpath = [ "src" ] [tool.mypy] ignore_missing_imports = true + +[tool.ruff] +exclude = [ + ".bzr", + ".direnv", + ".eggs", + ".git", + ".git-rewrite", + ".hg", + ".mypy_cache", + ".nox", + ".pants.d", + ".pytype", + ".ruff_cache", + ".svn", + ".tox", + ".venv", + "__pypackages__", + "_build", + "buck-out", + "build", + "dist", + "node_modules", + "venv" +] +line-length = 88 +indent-width = 4 +src = [ "src" ] +target-version = "py311" + + [tool.ruff.lint] + select = [ "ANN", "D", "E", "F", "I" ] + ignore = [ "ANN101", "ANN102" ] + fixable = [ "ALL" ] + unfixable = [ ] + dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" + + [tool.ruff.format] + quote-style = "double" + indent-style = "space" + skip-magic-trailing-comma = false + line-ending = "auto" + + [tool.ruff.pydocstyle] + convention = "google" + + [tool.ruff.per-file-ignores] + "tests/**/*.py" = [ ] + +[build-system] +requires = [ "poetry-core>=1.2.0" ] +build-backend = "poetry.core.masonry.api"