Skip to content

Commit 72f8591

Browse files
committed
add UV; add proper devs groups; remove deps duplication in req.txt; some fixes around stubs
1 parent 44b4b15 commit 72f8591

7 files changed

Lines changed: 480 additions & 29 deletions

File tree

.github/workflows/codspeed.yml

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,26 @@ on:
1010
permissions:
1111
contents: read
1212

13+
env:
14+
UV_FROZEN: true
15+
UV_PYTHON: 3.13 # use the latest version of Python because it is faster
16+
1317
jobs:
1418
benchmarks:
1519
runs-on: ubuntu-latest
1620
steps:
1721
- uses: actions/checkout@v4
1822
- uses: actions/setup-python@v5
1923
with:
20-
python-version: "3.13" # use the latest version of Python because it is faster
24+
python-version: ${{ env.UV_PYTHON}}
25+
26+
- name: Install UV.
27+
uses: astral-sh/setup-uv@v6
28+
with:
29+
enable-cache: true
2130

2231
- name: Install python dependencies.
23-
run: pip install -r pytests/requirements.txt
32+
run: uv sync --group testing
2433

2534
- name: Install rust.
2635
id: rust-toolchain
@@ -32,23 +41,23 @@ jobs:
3241
uses: Swatinem/rust-cache@v2
3342

3443
- name: Compile.
35-
run: pip install -v -e .
44+
run: uv pip install -v -e .
3645
env:
3746
RUSTFLAGS: "-Cprofile-generate=${{ github.workspace }}/profdata"
3847

3948
- name: Gather PGO data.
40-
run: pytest . --benchmark-enable
49+
run: uv run pytest . --benchmark-enable
4150

4251
- name: Prepare merged PGO data.
4352
run: rustup run 1.76.0 bash -c '$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/x86_64-unknown-linux-gnu/bin/llvm-profdata merge -o ${{ github.workspace }}/merged.profdata ${{ github.workspace }}/profdata'
4453

4554
- name: Compile with profile.
46-
run: pip install -v -e .
55+
run: uv pip install -v -e .
4756
env:
4857
RUSTFLAGS: "-Cprofile-use=${{ github.workspace }}/merged.profdata"
4958

5059
- name: Run benchmarks.
5160
uses: CodSpeedHQ/action@v3
5261
with:
5362
token: ${{ secrets.CODSPEED_TOKEN }}
54-
run: pytest . --codspeed -n auto
63+
run: uv run --group=codspeed pytest . --codspeed -n auto

.github/workflows/release.yml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
- zzstoatzz:main
78
tags:
89
- 'v*.*.*'
910
workflow_dispatch:
@@ -124,8 +125,12 @@ jobs:
124125
run: |
125126
git config --global core.autocrlf false
126127
git config --global core.eol lf
127-
- uses: actions/checkout@v4
128-
- uses: actions/setup-python@v5
128+
129+
- name: Checkout repository.
130+
uses: actions/checkout@v4
131+
132+
- name: Install UV.
133+
uses: astral-sh/setup-uv@v6
129134
with:
130135
python-version: ${{ matrix.interpreter }}
131136

@@ -151,11 +156,10 @@ jobs:
151156

152157
- name: Gather PGO data.
153158
run: |
154-
pip install -U pip
155-
pip install -r pytests/requirements.txt
159+
uv sync --group testing
160+
uv pip install libipld --no-index --no-deps --find-links pgo-wheel --force-reinstall
156161
157-
pip install libipld --no-index --no-deps --find-links pgo-wheel --force-reinstall
158-
pytest . --benchmark-enable
162+
uv run pytest . --benchmark-enable
159163
160164
# we can't use github.workspace here because of Windows with backslashes
161165
rustup run 1.76.0 bash -c 'echo LLVM_PROFDATA=$RUSTUP_HOME/toolchains/$RUSTUP_TOOLCHAIN/lib/rustlib/${{ env.RUST_HOST }}/bin/llvm-profdata >> "$GITHUB_ENV"'

.github/workflows/test.yml

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on: [ pull_request ]
55
permissions:
66
contents: read
77

8+
env:
9+
UV_PYTHON: 3.8 # minimum supported version
10+
811
jobs:
912
unit_tests:
1013
runs-on: ubuntu-latest
@@ -13,16 +16,16 @@ jobs:
1316
- name: Checkout repository.
1417
uses: actions/checkout@v4
1518

16-
- name: Set up Python.
17-
uses: actions/setup-python@v5
18-
with:
19-
# minimum supported version
20-
python-version: 3.8
19+
- name: Install UV.
20+
uses: astral-sh/setup-uv@v6
2121

2222
- name: Install dependencies.
23-
run: |
24-
pip install -r pytests/requirements.txt
25-
pip install -v -e .
23+
run: uv sync --group testing
24+
25+
- name: Compile.
26+
run: uv pip install -v -e .
27+
env:
28+
RUST_BACKTRACE: 1
2629

2730
- name: Run Tests.
2831
run: pytest

pyproject.toml

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,22 @@ classifiers = [
3838
"Author" = "https://github.com/MarshalX"
3939

4040
[dependency-groups]
41-
dev = ["maturin", "pytest", "pytest-benchmark"]
41+
dev = ["maturin>=1.2,<2.0"]
42+
testing = [
43+
{ include-group = "dev" },
44+
"pytest==8.3.5",
45+
"pytest-benchmark==4.0.0",
46+
"pytest-xdist==3.6.1",
47+
]
48+
codspeed = [
49+
# only run on CI with the latest Python version
50+
'pytest-codspeed==3.2.0; python_version == "3.13" and implementation_name == "cpython"',
51+
]
52+
53+
all = [
54+
{ include-group = "dev" },
55+
{ include-group = "testing" },
56+
]
4257

4358
[tool.pytest.ini_options]
4459
addopts = [

pytests/requirements.txt

Lines changed: 0 additions & 4 deletions
This file was deleted.

python/libipld/_libipld.pyi

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from __future__ import annotations
22
from typing import Any
33

4+
45
def decode_cid(data: str | bytes) -> dict[str, Any]:
56
"""Decode a CID from either its string representation or raw bytes.
67
@@ -17,6 +18,7 @@ def decode_cid(data: str | bytes) -> dict[str, Any]:
1718
- digest: bytes (hash digest)
1819
"""
1920

21+
2022
def encode_cid(data: str | bytes) -> str:
2123
"""Encode a CID to its string representation.
2224
@@ -27,6 +29,7 @@ def encode_cid(data: str | bytes) -> str:
2729
A CID string (e.g. 'bafy...')
2830
"""
2931

32+
3033
def decode_car(data: bytes) -> tuple[dict[str, Any], dict[bytes, dict[str, Any]]]:
3134
"""Decode a CAR file.
3235
@@ -39,6 +42,7 @@ def decode_car(data: bytes) -> tuple[dict[str, Any], dict[bytes, dict[str, Any]]
3942
- blocks: dict mapping CID bytes to block data
4043
"""
4144

45+
4246
def decode_dag_cbor(data: bytes) -> Any:
4347
"""Decode DAG-CBOR data to Python objects.
4448
@@ -49,6 +53,7 @@ def decode_dag_cbor(data: bytes) -> Any:
4953
A Python object
5054
"""
5155

56+
5257
def decode_dag_cbor_multi(data: bytes) -> list[Any]:
5358
"""Decode multiple DAG-CBOR objects from bytes.
5459
@@ -59,6 +64,7 @@ def decode_dag_cbor_multi(data: bytes) -> list[Any]:
5964
A list of Python objects
6065
"""
6166

67+
6268
def encode_dag_cbor(data: Any) -> bytes:
6369
"""Encode Python objects to DAG-CBOR.
6470
@@ -69,24 +75,26 @@ def encode_dag_cbor(data: Any) -> bytes:
6975
Raw DAG-CBOR bytes
7076
"""
7177

78+
7279
def decode_multibase(data: str) -> tuple[str, bytes]:
7380
"""Decode multibase-encoded data.
7481
7582
Args:
76-
data: Multibase-encoded string (e.g. 'u' for base58btc)
83+
data: Multibase-encoded string (e.g. 'ueWVzIG1hbmkgIQ')
7784
7885
Returns:
7986
A tuple containing:
8087
- base: str (the base code, e.g. 'u')
8188
- data: bytes (the decoded data)
8289
"""
8390

84-
def encode_multibase(code: str, data: Any) -> str:
91+
92+
def encode_multibase(code: str, data: bytes | str) -> str:
8593
"""Encode data using multibase.
8694
8795
Args:
88-
code: str (base code, e.g. 'u' for base58btc)
89-
data: Any Python object that can be converted to bytes
96+
code: Base code (e.g. 'u' for base58btc)
97+
data: Data to encode (bytes or string that can be converted to bytes)
9098
9199
Returns:
92100
Multibase-encoded string

0 commit comments

Comments
 (0)