Skip to content

Commit

Permalink
Add Github actions (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee committed Mar 26, 2023
1 parent 7205923 commit 4bb9e11
Show file tree
Hide file tree
Showing 11 changed files with 198 additions and 41 deletions.
158 changes: 158 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
name: CI

on:
push:
branches:
- main
tags:
- "*"
pull_request:

permissions:
contents: read

env:
RUSTFLAGS: "--cfg uuid_unstable"

jobs:
lint:
name: Check code quality
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.10"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Check code
run: |
black --check .
isort --check --project=uuid_utils .
mypy .
ruff .
linux:
name: "Linux: ${{ matrix.target }}"
runs-on: ubuntu-latest
strategy:
matrix:
target: [x86_64, i686]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: "true"
manylinux: auto
- name: Install and test
if: matrix.target == 'x86_64'
run: |
pip install uuid_utils --no-index --find-links dist --force-reinstall
pytest -v .
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

windows:
name: "Windows: ${{ matrix.target }}"
runs-on: windows-latest
strategy:
matrix:
target: [x64, x86]
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
architecture: ${{ matrix.target }}
- name: Install dependencies
run: pip install -r requirements.txt
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.target }}
args: --release --out dist --find-interpreter
sccache: "true"
- name: Install and test uuid_utils
run: |
pip install uuid_utils --no-index --find-links dist --force-reinstall
pytest -v .
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

macos:
name: "MacOS"
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: "3.11"
- name: Install dependencies
run: pip install -r requirements.txt
- uses: dtolnay/rust-toolchain@stable
- name: Build wheels - x86_64
uses: PyO3/maturin-action@v1
with:
target: x86_64
args: --release --out dist --find-interpreter
sccache: "true"
- name: Build wheels - universal2
uses: PyO3/maturin-action@v1
with:
args: --release --out dist --find-interpreter --universal2
- name: Install and test uuid_utils
run: |
pip install uuid_utils --no-index --find-links dist --force-reinstall
pytest -v .
- name: Upload wheels
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

sdist:
name: Source Distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v3
with:
name: wheels
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [lint, linux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v3
with:
name: wheels
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
with:
command: upload
args: --skip-existing *
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,7 @@ docs/_build/
.vscode/

# Pyenv
.python-version
.python-version

.ruff_cache
.mypy_cache
5 changes: 1 addition & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@ version = "0.1.0"
edition = "2021"

[lib]
name = "_uuid_utils"
name = "uuid_utils"
crate-type = ["cdylib"]

[package.metadata.maturin]
name = "uuid_utils._uuid_utils"

[dependencies]
pyo3 = { version = "0.18.1", features = ["extension-module"] }
uuid = { version = "1.3.0", features = ["v1", "v3", "v4", "v5", "v6", "v7", "v8", "fast-rng"]}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Python UUID Utils

Python UUID implementation using Rust's UUID library.
This will make `uuid4` function around 10 times faster.
This will make `uuid4` function around 10x faster.

This package can be a drop-in replacement to the standard library UUID
which implements existing UUID versions like V4 in Rust
Expand Down
24 changes: 21 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ build-backend = "maturin"

[project]
name = "uuid_utils"
description = "Drop-in replacement for Python UUID in Rust"
authors = [
{ name = "Amin Alaee", email = "me@aminalaee.dev" },
]
keywords = ["rust", "uuid"]
requires-python = ">=3.7"
classifiers = [
"Development Status :: 3 - Alpha",
Expand All @@ -18,9 +23,22 @@ classifiers = [
"Programming Language :: Rust",
]

dynamic = [
'version'
]
dynamic = ["version"]

[project.urls]
Documentation = "https://github.com/aminalaee/uuid-utils"
Issues = "https://github.com/aminalaee/uuid-utils/issues"
Source = "https://github.com/aminalaee/uuid-utils"

[tool.maturin]
features = ["pyo3/extension-module"]

[tool.mypy]
disallow_untyped_defs = true
ignore_missing_imports = true
show_error_codes = true
no_implicit_optional = true

[tool.isort]
profile = "black"
combine_as_imports = true
5 changes: 5 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
black==23.1.0
isort==5.11.5
mypy==1.1.1
pytest==7.2.2
ruff==0.0.259
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ fn uuid8(bytes: &PyBytes) -> PyResult<UUID> {
}

#[pymodule]
fn _uuid_utils(_py: Python, m: &PyModule) -> PyResult<()> {
fn uuid_utils(_py: Python, m: &PyModule) -> PyResult<()> {
m.add_class::<UUID>()?;

m.add_function(wrap_pyfunction!(uuid1, m)?)?;
Expand Down
5 changes: 3 additions & 2 deletions tests/test_uuid.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from uuid import getnode
import uuid_utils

import pytest

import uuid_utils


def test_uuid_str() -> None:
uuid = uuid_utils.UUID("a8098c1a-f86e-11da-bd1a-00112444be1e")
Expand Down Expand Up @@ -51,7 +52,7 @@ def test_uuid_setattr() -> None:
uuid = uuid_utils.UUID(int=223359875637754765292326297443183672862)

with pytest.raises(TypeError):
uuid.int = 123
uuid.int = 123 # type: ignore


def test_uuid1() -> None:
Expand Down
6 changes: 4 additions & 2 deletions uuid_utils/__init__.pyi → uuid_utils.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import sys
from _typeshed import Unused
from enum import Enum

from _typeshed import Unused
from typing_extensions import TypeAlias

# Because UUID has properties called int and bytes we need to rename these temporarily.
Expand Down Expand Up @@ -93,7 +94,8 @@ def uuid5(namespace: UUID, name: str) -> UUID:

def uuid6(node: _Int, timestamp: _Int | None = None) -> UUID:
"""Generate a version 6 UUID using the given timestamp and a host ID.
This is similar to version 1 UUIDs, except that it is lexicographically sortable by timestamp.
This is similar to version 1 UUIDs,
except that it is lexicographically sortable by timestamp.
"""
...

Expand Down
27 changes: 0 additions & 27 deletions uuid_utils/__init__.py

This file was deleted.

Empty file removed uuid_utils/py.typed
Empty file.

0 comments on commit 4bb9e11

Please sign in to comment.