Skip to content
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
27 changes: 13 additions & 14 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ name: tests
on:
push:
branches: [main]
pull_request:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.12"]
python-version: ["3.11", "3.12"]

steps:
- uses: actions/checkout@v4
Expand All @@ -20,26 +21,24 @@ jobs:
with:
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1

- name: Install uv
uses: astral-sh/setup-uv@v5
with:
enable-cache: true
cache-dependency-glob: "uv.lock"

- name: Display Python version
run: python -c "import sys; print(sys.version)"

- name: Install dependencies
run: poetry install --no-interaction --no-root

- name: Install project
run: poetry install --no-interaction

- name: Run pytest
run: |
# source .venv/bin/activate
poetry run pytest tests/
run: uv sync

- name: Run tests
run: uv run pytest tests

- name: Run pyest-cov
run: |
poetry run pytest --cov upto/ --cov-report xml
uv run pytest --cov lupl/ --cov-report xml

- name: Upload coverage data to coveralls
uses: coverallsapp/github-action@v2.2.3
Expand Down
34 changes: 20 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
# UPTo
# lupl 👾😺

![tests](https://github.com/lu-pl/upto/actions/workflows/tests.yml/badge.svg)
[![coverage](https://coveralls.io/repos/github/lu-pl/upto/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/lu-pl/upto?branch=main&kill_cache=1)
[![PyPI version](https://badge.fury.io/py/upto.svg)](https://badge.fury.io/py/upto)
![tests](https://github.com/lu-pl/lupl/actions/workflows/tests.yml/badge.svg)
[![Coverage Status](https://coveralls.io/repos/github/lu-pl/lupl/badge.svg?branch=lupl/rename)](https://coveralls.io/github/lu-pl/lupl?branch=lupl/rename)
[![PyPI version](https://badge.fury.io/py/lupl.svg)](https://badge.fury.io/py/lupl)
[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)

UPTo - A personal collection of potentially generally Useful Python Tools.
A collection of potentially generally useful Python utilities.

## Installation

## ComposeRouter
`lupl` is PEP-621-compliant package and available on PyPI.

## Usage

### ComposeRouter
The ComposeRouter class allows to route attributes access for registered methods
through a functional pipeline constructed from components.
The pipeline is only triggered if a registered method is accessed via the ComposeRouter namespace.

```python
from upto import ComposeRouter
from lupl import ComposeRouter

class Foo:
route = ComposeRouter(lambda x: x + 1, lambda y: y * 2)
Expand All @@ -30,13 +36,13 @@ print(foo.method(2, 3)) # 6
print(foo.route.method(2, 3)) # 13
```

## Chunk Iterator
### Chunk Iterator

The `upto.ichunk` generator implements a simple chunk iterator that allows to lazily slice an Iterator into sub-iterators.
The `lupl.ichunk` generator implements a simple chunk iterator that allows to lazily slice an Iterator into sub-iterators.

```python
from collections.abc import Iterator
from upto import ichunk
from lupl import ichunk

iterator: Iterator[int] = iter(range(10))
chunks: Iterator[Iterator[int]] = ichunk(iterator, size=3)
Expand All @@ -45,13 +51,13 @@ materialized = [tuple(chunk) for chunk in chunks]
print(materialized) # [(0, 1, 2), (3, 4, 5), (6, 7, 8), (9,)]
```

## Pydantic Tools
### Pydantic Tools

### CurryModel
#### CurryModel
The CurryModel constructor allows to sequentially initialize (curry) a Pydantic model.

```python
from upto import CurryModel
from lupl import CurryModel

class MyModel(BaseModel):
x: str
Expand Down Expand Up @@ -84,7 +90,7 @@ model_instance_3 = curried_model_3(x="1", y=2)(z=("3", 4))
print(model_instance_3)
```

### init_model_from_kwargs
#### init_model_from_kwargs

The `init_model_from_kwargs` constructor allows to initialize (potentially nested) models from (flat) kwargs.

Expand Down
5 changes: 5 additions & 0 deletions lupl/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from lupl.compose_router import ComposeRouter
from lupl.ichunk import ichunk
from lupl.pydantic_tools.curry_model import CurryModel, validate_model_field
from lupl.pydantic_tools.model_constructors import init_model_from_kwargs
from lupl.pydantic_tools.mutual_constraint_validator import _MutualConstraintMixin
File renamed without changes.
File renamed without changes.
File renamed without changes.
10 changes: 9 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[project]
name = "upto"
name = "lupl"
version = "0.1.0"
description = ""
authors = [{ name = "Lukas Plank", email = "lupl@tuta.io" }]
Expand All @@ -25,3 +25,11 @@ build-backend = "hatchling.build"

[tool.ruff]
lint.ignore = ["F401"]

exclude = [
"#*#",
".#*",
".git",
".venv",
"__pycache__"
]
4 changes: 2 additions & 2 deletions tests/data/init_model_from_kwargs_parameters.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Model and kwargs data mappings for testing upto.init_model_from_kwargs"""
"""Model and kwargs data mappings for testing lupl.init_model_from_kwargs"""

from pydantic import BaseModel
from upto.pydantic_tools.model_constructors import init_model_from_kwargs
from lupl.pydantic_tools.model_constructors import init_model_from_kwargs


class SimpleModel(BaseModel):
Expand Down
7 changes: 3 additions & 4 deletions tests/test_compose_router.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Pytest entry point for upto.ComposeRouter tests."""
"""Pytest entry point for lupl.ComposeRouter tests."""

from lupl import ComposeRouter
import pytest

from toolz import compose
from upto import ComposeRouter


def test_simple_compose_router():
"""Simple base test case for upto.ComposeRouter.
"""Simple base test case for lupl.ComposeRouter.

Check if the composed route generates the same result
as the _components applied to the result of the method without routing.
Expand Down
4 changes: 2 additions & 2 deletions tests/test_ichunk.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""Basic tests for upto.ichunk."""
"""Basic tests for lupl.ichunk."""

from collections.abc import Iterator
from typing import NamedTuple

from lupl import ichunk
import pytest
from upto import ichunk


class IChunkTestParameter(NamedTuple):
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_pydantic_tools/test_curry_model.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Pytest entry point for upto.CurryModel tests."""
"""Pytest entry point for lupl.CurryModel tests."""

from pydantic import BaseModel, Field
from upto import CurryModel
from lupl import CurryModel


def test_simple_curry_model():
Expand Down
2 changes: 1 addition & 1 deletion tests/tests_pydantic_tools/test_init_model_from_kwargs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from tests.data.init_model_from_kwargs_parameters import (
init_model_from_kwargs_parameters,
)
from upto import init_model_from_kwargs
from lupl import init_model_from_kwargs


@pytest.mark.parametrize(("model", "kwargs"), init_model_from_kwargs_parameters)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
import pytest

from pydantic import BaseModel, ConfigDict
from upto import _MutualConstraintMixin
from upto.pydantic_tools.mutual_constraint_validator import (
from lupl import _MutualConstraintMixin
from lupl.pydantic_tools.mutual_constraint_validator import (
MutualDependencyException,
MutualExclusionException,
)
Expand Down
4 changes: 2 additions & 2 deletions tests/tests_pydantic_tools/test_validate_model_field.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Basic test for upto.validate_model_field."""
"""Basic test for lupl.validate_model_field."""

import pytest

from pydantic import BaseModel
from upto import validate_model_field
from lupl import validate_model_field


def test_validate_model_field_sad_path_missing_field():
Expand Down
5 changes: 0 additions & 5 deletions upto/__init__.py

This file was deleted.

Loading