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

Switch to uv #85

Merged
merged 8 commits into from
Dec 9, 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
59 changes: 33 additions & 26 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
- '**'
pull_request: {}

env:
COLUMNS: 120

jobs:
test:
runs-on: ubuntu-latest
Expand All @@ -18,38 +21,30 @@ jobs:
python-version: ['3.9', '3.10', '3.11', '3.12']

env:
PYTHON: ${{ matrix.python-version }}
UV_PYTHON: ${{ matrix.python-version }}

steps:
- uses: actions/checkout@v4

- name: set up python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v3
with:
python-version: ${{ matrix.python-version }}
enable-cache: true

- name: install rust stable
uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@stable

- id: cache-rust
name: cache rust
uses: Swatinem/rust-cache@v2
with:
key: v1

- run: pip install -r tests/requirements.txt

- run: pip install -e .

- run: pip freeze
- run: uv sync --frozen

- run: make test

- run: ls -lha
- run: coverage xml
- run: uv run coverage xml

- name: install go
uses: actions/setup-go@v1
- uses: actions/setup-go@v1
with:
go-version: 1.16.x

Expand All @@ -67,36 +62,42 @@ jobs:
rm tests/invalid/integer-positive-hex.*
go build ./cmd/toml-test
cd ../
source .venv/bin/activate
./toml-test/toml-test ./tests/toml_test.py

- uses: codecov/codecov-action@v3
with:
file: ./coverage.xml
env_vars: PYTHON
env_vars: UV_PYTHON

lint:
runs-on: ubuntu-latest

env:
UV_PYTHON: 3.12

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v3
with:
python-version: '3.11'
enable-cache: true

- run: pip install -r tests/requirements-linting.txt
- run: uv sync --frozen --group lint --no-dev --no-install-project

- name: install rust
uses: dtolnay/rust-toolchain@stable
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt, clippy

- name: cache rust
uses: Swatinem/rust-cache@v2
- uses: Swatinem/rust-cache@v2

- uses: pre-commit/action@v3.0.0
with:
extra_args: --all-files --verbose
env:
SKIP: no-commit-to-branch

- run: pip freeze
- run: make lint
- run: make mypy
- run: make typecheck

# https://github.com/marketplace/actions/alls-green#why used for branch protection checks
check:
Expand Down Expand Up @@ -163,6 +164,12 @@ jobs:
python-version: '3.11'
architecture: ${{ matrix.python-architecture || 'x64' }}

- name: check GITHUB_REF matches package version
uses: samuelcolvin/check-python-version@v4.1
if: ${{ startsWith(github.ref, 'refs/tags/') && matrix.os == 'ubuntu' }}
with:
version_file_path: Cargo.toml

- run: pip install -U twine

- name: build sdist
Expand Down
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/target
**/*.rs.bk
/rtoml.so
__pycache__/
*.py[cod]
*.egg-info/
Expand All @@ -14,7 +13,7 @@ __pycache__/
/htmlcov/
/.idea/
/.vscode/
/rtoml/*.so
/python/rtoml/*.so
.coverage
.auto-format
/toml-test/
Expand Down
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.0.1
hooks:
- id: no-commit-to-branch
- id: check-yaml
- id: check-toml
- id: end-of-file-fixer
Expand All @@ -12,6 +13,12 @@ repos:

- repo: local
hooks:
- id: format
name: Format
entry: make format
types: [python, rust]
language: system
pass_filenames: false
- id: lint-python
name: Lint Python
entry: make lint-python
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
68 changes: 27 additions & 41 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,34 +1,40 @@
.DEFAULT_GOAL := all

install:
pip install -U pip wheel pre-commit
pip install -r tests/requirements.txt
pip install -e .
pre-commit install
.PHONY: .uv # Check that uv is installed
.uv:
@uv --version || echo 'Please install uv: https://docs.astral.sh/uv/getting-started/installation/'

.PHONY: install-all
install-all: install
pip install -r tests/requirements-linting.txt
.PHONY: .pre-commit # Check that pre-commit is installed
.pre-commit:
@pre-commit -V || echo 'Please install pre-commit: https://pre-commit.com/'

.PHONY: install # Install the package, dependencies, and pre-commit for local development
install: .uv .pre-commit
uv sync --frozen --group lint
pre-commit install --install-hooks

.PHONY: sync # Update local packages and uv.lock
sync: .uv
uv sync --all-extras --all-packages --group lint --group docs

.PHONY: build-dev
build-dev:
maturin develop
uv run maturin develop --uv

.PHONY: build-prod
build-prod:
maturin develop --release
uv run maturin develop --release --uv

.PHONY: format
format:
ruff check --fix-only rtoml tests
ruff format rtoml tests
uv run ruff format
uv run ruff check --fix --fix-only
cargo fmt


.PHONY: lint-python
lint-python:
ruff check rtoml tests
ruff format --check rtoml tests
uv run ruff format --check
uv run ruff check

.PHONY: lint-rust
lint-rust:
Expand All @@ -41,37 +47,17 @@ lint-rust:
lint: lint-python lint-rust

.PHONY: mypy
mypy:
mypy rtoml
typecheck:
uv run mypy python

.PHONY: test
test:
coverage run -m pytest
uv run coverage run -m pytest

.PHONY: testcov
testcov: build test
testcov: build-dev test
@echo "building coverage html"
@coverage html
@uv run coverage html

.PHONY: all
all: lint mypy testcov

.PHONY: clean
clean:
rm -rf `find . -name __pycache__`
rm -f `find . -type f -name '*.py[co]' `
rm -f `find . -type f -name '*~' `
rm -f `find . -type f -name '.*~' `
rm -rf dist
rm -rf build
rm -rf target
rm -rf .cache
rm -rf .pytest_cache
rm -rf .mypy_cache
rm -rf htmlcov
rm -rf *.egg-info
rm -f .coverage
rm -f .coverage.*
rm -rf build
rm -f rtoml/*.so
python setup.py clean
all: lint typecheck testcov
5 changes: 4 additions & 1 deletion example.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

assert loaded_obj == obj

assert rtoml.dumps(obj) == """\
assert (
rtoml.dumps(obj)
== """\
title = "TOML Example"

[owner]
Expand All @@ -47,3 +49,4 @@
server = "192.168.1.1"
ports = [8001, 8001, 8002]
"""
)
23 changes: 19 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,21 @@ Homepage = "https://github.com/samuelcolvin/rtoml"
Funding = "https://github.com/sponsors/samuelcolvin"
Source = "https://github.com/samuelcolvin/rtoml"

[dependency-groups]
dev = [
"coverage[toml]>=7.6.9",
"dirty-equals>=0.8.0",
"pytest>=8.3.4",
"pytest-pretty>=1.2.0",
"pytest-speed>=0.3.5",
]
lint = [
"mypy>=1.13.0",
"ruff>=0.8.2",
]

[tool.maturin]
python-source = "python"
bindings = "pyo3"
module-name = "rtoml._rtoml"
features = ["pyo3/extension-module", "pyo3/generate-import-lib"]
Expand All @@ -67,10 +81,11 @@ exclude_lines = [

[tool.ruff]
line-length = 120
extend-select = ["Q", "RUF100", "UP", "I"]
flake8-quotes = {inline-quotes = "single", multiline-quotes = "double"}
format.quote-style="single"
target-version = "py38"
lint.extend-select = ["Q", "RUF100", "UP", "I"]
lint.flake8-quotes = {inline-quotes = "single", multiline-quotes = "double"}
lint.isort = { known-first-party = ["rtoml", "tests"] }
format.quote-style = "single"
target-version = "py39"

[tool.mypy]
follow_imports = "normal"
Expand Down
6 changes: 3 additions & 3 deletions rtoml/__init__.py → python/rtoml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from io import TextIOBase
from pathlib import Path
from typing import Any, Dict, Optional, TextIO, Union
from typing import Any, Optional, TextIO, Union

from . import _rtoml

Expand All @@ -13,7 +13,7 @@
TomlSerializationError = _rtoml.TomlSerializationError


def load(toml: Union[str, Path, TextIO], *, none_value: Optional[str] = None) -> Dict[str, Any]:
def load(toml: Union[str, Path, TextIO], *, none_value: Optional[str] = None) -> dict[str, Any]:
"""
Parse TOML via a string or file and return a python dict.

Expand All @@ -30,7 +30,7 @@ def load(toml: Union[str, Path, TextIO], *, none_value: Optional[str] = None) ->
return loads(toml, none_value=none_value)


def loads(toml: str, *, none_value: Optional[str] = None) -> Dict[str, Any]:
def loads(toml: str, *, none_value: Optional[str] = None) -> dict[str, Any]:
"""
Parse a TOML string and return a python dict. (provided to match the interface of `json` and similar libraries)

Expand Down
File renamed without changes.
File renamed without changes.
1 change: 0 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
max_width = 120
imports_granularity = "Module"
2 changes: 0 additions & 2 deletions tests/requirements-linting.txt

This file was deleted.

6 changes: 0 additions & 6 deletions tests/requirements.txt

This file was deleted.

Loading
Loading