Skip to content

Commit

Permalink
ci: update gh workflow to use uv🔧
Browse files Browse the repository at this point in the history
  • Loading branch information
KarelZe committed Dec 2, 2024
1 parent 9126976 commit 457178b
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 60 deletions.
25 changes: 12 additions & 13 deletions .github/workflows/action_python.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Python package

on:
push:
paths:
- 'src/**'
push:
# paths:
# - 'src/**'

jobs:
build:
Expand All @@ -25,19 +25,18 @@ jobs:
shell: bash
env:
WANDB_API_KEY: ${{secrets.WANDB_API_KEY}}
- name: Install poetry
run: pipx install poetry
- name: Set up Python and install dependencies
uses: actions/setup-python@v5
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: '3.10'
cache: 'poetry'
- name: install poetry
run: poetry install
enable-cache: true
- name: Set up Python
run: uv python install
- name: Install the project
run: uv sync --all-extras --dev
- name: Test with pytest
run: |
poetry run pytest --cov=src tests/ --doctest-modules --junitxml=cover/xunit-result.xml --cov-report xml:cover/coverage.xml
poetry run coverage json -o cover/coverage.json
uv run pytest --cov=src tests/ --doctest-modules --junitxml=cover/xunit-result.xml --cov-report xml:cover/coverage.xml
uv run coverage json -o cover/coverage.json
- name: "Extract numbers from cov report"
run: |
export TOTAL=$(python -c "import json;print(json.load(open('cover/coverage.json'))['totals']['percent_covered_display'])")
Expand Down
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ target/
# Pycharm
.idea

# VS Code
.vscode/

# Spyder
.spyproject/

Expand Down
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.testing.autoTestDiscoverOnSaveEnabled": true,
"[python]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
"source.organizeImports": "explicit"
}
},
"notebook.formatOnSave.enabled": true,
"notebook.codeActionsOnSave": {
"notebook.source.fixAll": "explicit",
"notebook.source.organizeImports": "explicit"
}
}
46 changes: 45 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,5 +129,49 @@ dev-dependencies = [
"pytest>=7.4.3",
"pytest-cov>=4.1.0",
"ruff>=0.8.1",
"tox>=4.11.3",
"tox>=4.23",
"tox-uv",
]

[tool.tox]
env_list = ["format", "lint", "pre-commit"]
min_version = "4.23"

[tool.tox.env_run_base]
runner = "uv-venv-lock-runner"
allowlist_externals = ["/bin/sh"]
skip_install = true
with_dev = true

[tool.tox.env.clean]
description = "cleanup tasks (remove build artifacts and cache)"
commands = [
["coverage", "erase"],
["sh", "-c", "rm -rf .mypy_cache .pytest_cache .ruff_cache dist mlruns reports"]
]

[tool.tox.env.format]
description = "code formatting using ruff"
commands = [
["ruff", "format", { replace = "posargs", default = ["src", "tests", "notebooks"], extend = true }]
]

[tool.tox.env.lint]
description = "linting and syntax checks"
commands = [
["ruff", "check", { replace = "posargs", default = ["src", "tests", "notebooks"], extend = true} ],
["ruff", "format", "--check", { replace = "posargs", default = ["src", "tests", "notebooks"], extend = true} ],
["mypy", { replace = "posargs", default = ["src"], extend = true} ]
]

[tool.tox.env.pre-commit]
description = "pre-commit hooks"
commands = [["pre-commit", "run", "--all-files", "--show-diff-on-failure"]]

[tool.tox.env.test]
description = "tests"
commands = [["pytest"]]

[tool.tox.env.build]
description = "build the project"
commands = [["uv", "build"]]
41 changes: 0 additions & 41 deletions tox.ini

This file was deleted.

47 changes: 45 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 457178b

Please sign in to comment.