Skip to content

Commit

Permalink
Merge pull request #158 from trouchet/brunolnetto/uv
Browse files Browse the repository at this point in the history
Port poetry to uv
  • Loading branch information
brunolnetto authored Nov 13, 2024
2 parents b590346 + ada6ed6 commit e0ccef1
Show file tree
Hide file tree
Showing 27 changed files with 1,699 additions and 1,876 deletions.
45 changes: 21 additions & 24 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,45 +27,42 @@ jobs:
python-version: ${{ matrix.python-version }}

#----------------------------------------------
# install & configure poetry -----
# install & configure uv
#----------------------------------------------
- name: Install and configure Poetry
uses: snok/install-poetry@v1
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
virtualenvs-create: true
virtualenvs-in-project: true
# Install a specific version of uv.
version: "0.5.1"

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Set up Python
run: uv python install

- name: Install the project
run: uv sync --all-extras --dev

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --verbose --no-interaction --no-root
- name: Define a cache dependency glob
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install project
run: poetry install --verbose --no-interaction
- name: Run tests
# For example, using `pytest`
run: uv run pytest tests

#----------------------------------------------
# Test coverage
#----------------------------------------------
- name: Run tests and generate coverage
run: |
poetry run pytest --cov=eule tests/
uv run pytest --cov=eule tests/
# Uncomment when achieve sufficient coverage threshold
poetry run coverage report -m
uv run coverage report -m
#----------------------------------------------
# Update codecov coverage
#----------------------------------------------
Expand Down
92 changes: 50 additions & 42 deletions .github/workflows/upload-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,53 @@ jobs:
runs-on: ubuntu-latest
name: Test python API
steps:
- uses: actions/checkout@v4
- name: Install requirements
run: pip install -r requirements.txt
#----------------------------------------------
# install & configure poetry -----
#----------------------------------------------
- name: Install and configure Poetry
uses: snok/install-poetry@v1
with:
virtualenvs-create: true
virtualenvs-in-project: true

#----------------------------------------------
# load cached venv if cache exists
#----------------------------------------------
- name: Load cached venv
id: cached-poetry-dependencies
uses: actions/cache@v3
with:
path: .venv
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --verbose --no-interaction --no-root

#----------------------------------------------
# install your root project, if required
#----------------------------------------------
- name: Install project
run: poetry install --verbose --no-interaction

- name: Upload coverage reports to Codecov
run: |
# Replace `linux` below with the appropriate OS
# Options are `alpine`, `linux`, `macos`, `windows`
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
- uses: actions/checkout@v4
- name: Install requirements
run: pip install -r requirements.txt

#----------------------------------------------
# check-out repo and set-up python
#----------------------------------------------
- name: Check out repository
uses: actions/checkout@v3
- name: Set up python
id: setup-python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}

#----------------------------------------------
# install & configure uv
#----------------------------------------------
- name: Install uv
uses: astral-sh/setup-uv@v3
with:
# Install a specific version of uv.
version: "0.5.1"

- name: Set up Python
run: uv python install

- name: Install the project
run: uv sync --all-extras --dev

- name: Run tests
# For example, using `pytest`
run: uv run pytest tests

#----------------------------------------------
# install dependencies if cache does not exist
#----------------------------------------------
- name: Define a cache dependency glob
uses: astral-sh/setup-uv@v3
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Upload coverage reports to Codecov
run: |
# Replace `linux` below with the appropriate OS
# Options are `alpine`, `linux`, `macos`, `windows`
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t ${CODECOV_TOKEN}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.pypirc

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
Expand Down
27 changes: 27 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v2.3.0
hooks:
- id: check-yaml
- id: end-of-file-fixer
exclude: docs/auto_examples
- id: trailing-whitespace
exclude: docs/auto_examples
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: v0.3.7
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: local
hooks:
- id: pytest
name: Pytest
entry: uv run pytest
types: [python]
language: system
pass_filenames: false
24 changes: 10 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ endef

export PRINT_HELP_PYSCRIPT

BROWSER := python -c "$$BROWSER_PYSCRIPT"
BROWSER := python3 -c "$$BROWSER_PYSCRIPT"
DO_DOCS_HTML := $(MAKE) -C clean-docs && $(MAKE) -C docs html
SPHINXBUILD = python3 -msphinx

Expand Down Expand Up @@ -65,18 +65,19 @@ test: ## run tests quickly with the default Python
pytest

watch: ## run tests on watchdog mode
poetry shell
ptw .

uv: ## install uv
pip install uv

lint: clean ## perform inplace lint fixes
ruff --fix .
uv run ruff --fix .

cov: clean ## check code coverage quickly with the default Python
coverage run --source "$$PACKAGE_NAME" -m pytest
coverage report -m --omit="$$COVERAGE_IGNORE_PATHS"
uv run coverage run --source "$$PACKAGE_NAME" -m pytest
uv run coverage report -m --omit="$$COVERAGE_IGNORE_PATHS"

docs: clean ## generate Sphinx HTML documentation, including API docs
poetry shell
sphinx-apidoc -o "docs/" "$$PACKAGE_NAME" "tests" "examples" "conftest.py"
$(MAKE) -C docs html
$(BROWSER) 'docs/_build/html/index.html'
Expand All @@ -85,17 +86,12 @@ docs-watch: docs ## compile the docs watching for changes
watchmedo shell-command -p '*.rst' -c '$$DO_DOCS_HTML' -R -D .

env: ## Creates a virtual environment. Usage: make env
pip install virtualenv
virtualenv .venv
uv venv

install: clean ## Installs the python requirements. Usage: make install
pip install uv
uv pip install -r requirements.txt
uv pip install -r requirements_dev.txt

echo: ## echo current package version
echo "v$$(poetry version -s)"

what: ## List all commits made since last version bump
git log --oneline "$$(git rev-list -n 1 "v$$(poetry version -s)")..$$(git rev-parse HEAD)"

Expand All @@ -109,8 +105,8 @@ bump: ## bump version to user-provided {patch|minor|major} semantic
@$(MAKE) check-bump v=$(v)
poetry version $(v)
git add pyproject.toml
poetry lock
git add poetry.lock
uv lock
git add uv.lock
git commit -m "release/ tag v$$(poetry version -s)"
git tag "v$$(poetry version -s)"
git push
Expand Down
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#
import os
import sys

sys.path.insert(0, os.path.abspath('..'))


Expand Down
11 changes: 8 additions & 3 deletions eule/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@

from __future__ import annotations

from .core import euler_generator, euler, \
euler_keys, euler_boundaries, Euler

__author__ = """Bruno Peixoto"""
__email__ = '[email protected]'

__all__ = [
'euler_generator',
'euler',
'euler_keys',
'euler_boundaries',
'Euler'
]
Loading

0 comments on commit e0ccef1

Please sign in to comment.