Skip to content

Commit edba1a6

Browse files
committed
modernize configuration and packaging
1 parent b947661 commit edba1a6

File tree

18 files changed

+371
-203
lines changed

18 files changed

+371
-203
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* @svix/Engineering

.github/dependabot.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "uv"
4+
directory: "/"
5+
schedule:
6+
interval: "weekly"
7+
day: "tuesday"
8+
time: "10:00"
9+
timezone: "America/Los_Angeles"

.github/workflows/lint.yml

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,26 @@
11
name: lint
22
on: [pull_request]
33
jobs:
4-
build:
4+
lint:
55
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
69
steps:
7-
- uses: actions/checkout@v2
8-
- uses: actions/setup-python@v2
9-
name: Install Python
10+
- uses: actions/checkout@v5
11+
- name: Install the latest version of uv
12+
uses: astral-sh/setup-uv@v7
1013
with:
11-
python-version: '3.11'
12-
- name: Install deps
13-
run: |
14-
python -m pip install --upgrade pip pyinstaller wheel
15-
python -m pip install -r requirements.txt .
16-
python -m pip install -r requirements-dev.txt .
14+
python-version: ${{ matrix.python }}
15+
enable-cache: true
16+
- name: Sync lockfile
17+
run: uv sync
1718
- name: Run linting
18-
run: |
19-
sh ./scripts/lint.sh
19+
run: uv run sh ./scripts/lint.sh
20+
prek:
21+
name: Validate prek
22+
runs-on: ubuntu-24.04
23+
steps:
24+
- uses: actions/checkout@v6
25+
- uses: astral-sh/setup-uv@v7
26+
- uses: j178/prek-action@v1

.github/workflows/test.yml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1-
name: test
1+
name: lint
22
on: [pull_request]
33
jobs:
4-
build:
4+
test:
55
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
69
steps:
7-
- uses: actions/checkout@v2
8-
- uses: actions/setup-python@v2
9-
name: Install Python
10+
- uses: actions/checkout@v5
11+
- name: Install the latest version of uv
12+
uses: astral-sh/setup-uv@v7
1013
with:
11-
python-version: '3.11'
14+
python-version: ${{ matrix.python }}
15+
enable-cache: true
1216
- name: Install deps
13-
run: |
14-
python -m pip install --upgrade pip pyinstaller wheel
15-
python -m pip install -r requirements.txt .
16-
python -m pip install -r requirements-dev.txt .
17-
- name: Run tests
18-
run: |-
19-
pytest
20-
17+
run: uv sync
18+
- name: Run linting
19+
run: uv run pytest

.pre-commit-config.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
repos:
2+
- repo: builtin
3+
hooks:
4+
- id: end-of-file-fixer
5+
- id: trailing-whitespace
6+
- id: check-case-conflict
7+
- id: check-merge-conflict
8+
- id: check-symlinks
9+
- id: check-toml
10+
- id: check-yaml
11+
args: ["--allow-multiple-documents"]
12+
- id: check-json
13+
- repo: https://github.com/google/yamlfmt
14+
rev: v0.20.0
15+
hooks:
16+
- id: yamlfmt
17+
- repo: https://github.com/rhysd/actionlint
18+
rev: v1.7.7
19+
hooks:
20+
- id: actionlint
21+
- repo: https://github.com/crate-ci/typos
22+
rev: v1.42.1
23+
hooks:
24+
- id: typos
25+
exclude: "tests/test_kuids.txt"

ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## Next
44
* Changed `KsuidMs` implementation to use the fractional part to have 4ms of precision instead of (1/256)s of precision, aligning its interpretation with [rust-ksuid](https://github.com/svix/rust-ksuid), and with its own docstrings
55
* Bump minimum Python version to 3.10
6+
* Switch to `uv`, `ruff`, and `ty` for development instead of `pip-tools`, `black`, `flake8`, `isort`, and `mypy`
67

78
## Version 0.6.2
89
* Fix `__str__` implementation for non standard sized ksuids (see #27 for details)

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
21+
THE SOFTWARE.

README.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
[![Join our slack](https://img.shields.io/badge/Slack-join%20the%20community-blue?logo=slack&style=social)](https://www.svix.com/slack/)
1515

1616
This library is inspired by [Segment's KSUID](https://segment.com/blog/a-brief-history-of-the-uuid/) implementation:
17-
https://github.com/segmentio/ksuid
17+
<https://github.com/segmentio/ksuid>
1818

19-
For the Rust version, please check out https://github.com/svix/rust-ksuid
19+
For the Rust version, please check out <https://github.com/svix/rust-ksuid>
2020

2121
## What is a ksuid?
2222

23-
A ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately
24-
sorted based on the time they were created.
23+
A ksuid is a K sorted UID. In other words, a KSUID also stores a date component, so that ksuids can be approximately
24+
sorted based on the time they were created.
2525

2626
Read more [here](https://segment.com/blog/a-brief-history-of-the-uuid/).
2727

@@ -180,3 +180,12 @@ Out[8]: False
180180
### License
181181

182182
ksuid source code is available under an MIT [License](./LICENSE).
183+
184+
### Development
185+
186+
This application uses [`uv`](https://docs.astral.sh/uv/) for virtualenv management by default.
187+
188+
- To lint, use `uv run scripts/lint.sh`
189+
- To run tests, use `uv run pytest`
190+
191+
This repository also has pre-commit hooks set up using [`prek`](https://prek.j178.dev/). They will be checked in CI, but if you'd like to run them locally you can use the `prek` tool.

ksuid/ksuid.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,20 @@ class Ksuid:
4646
_uid: bytes
4747

4848
@classmethod
49-
def from_base62(cls: t.Type[SelfT], data: str) -> SelfT:
49+
def from_base62(cls: type[SelfT], data: str) -> SelfT:
5050
"""initializes Ksuid from base62 encoding"""
5151
return cls.from_bytes(int.to_bytes(int(base62.decode(data)), cls.BYTES_LENGTH, "big"))
5252

5353
@classmethod
54-
def from_bytes(cls: t.Type[SelfT], value: bytes) -> SelfT:
54+
def from_bytes(cls: type[SelfT], value: bytes) -> SelfT:
5555
"""initializes Ksuid from bytes"""
5656

5757
if len(value) != cls.TIMESTAMP_LENGTH_IN_BYTES + cls.PAYLOAD_LENGTH_IN_BYTES:
5858
raise ByteArrayLengthException(f"Incorrect value length {len(value)}")
5959

6060
return cls(_raw=value)
6161

62-
def __init__(
63-
self, datetime: t.Optional[datetime] = None, payload: t.Optional[bytes] = None, _raw: t.Optional[bytes] = None
64-
):
62+
def __init__(self, datetime: datetime | None = None, payload: bytes | None = None, _raw: bytes | None = None):
6563
if _raw is not None:
6664
self._uid = _raw
6765
return

pyproject.toml

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,57 @@
1-
[tool.black]
1+
[project]
2+
name = "svix-ksuid"
3+
version = "0.6.2"
4+
description = "A pure-Python KSUID implementation"
5+
authors = [
6+
{ name = "Svix", email = "development@svix.com" }
7+
]
8+
readme = "README.md"
9+
requires-python = ">=3.10"
10+
license = "MIT"
11+
license-files = ["LICENSE"]
12+
dependencies = [
13+
"python-baseconv"
14+
]
15+
keywords = [
16+
"svix",
17+
"ksuid",
18+
]
19+
20+
[project.urls]
21+
Repository = "https://github.com/svix/python-ksuid/"
22+
Issues = "https://github.com/svix/python-ksuid/issues"
23+
Changelog = "https://github.com/svix/python-ksuid/blob/main/ChangeLog.md"
24+
25+
[build-system]
26+
requires = ["hatchling >= 1.26"]
27+
build-backend = "hatchling.build"
28+
29+
[tool.hatch.build]
30+
exclude = [".github/*", "scripts/*", "tests/*", 'uv.lock', "mypy.ini", "/.*"]
31+
32+
[tool.hatch.build.targets.wheel]
33+
packages = ["ksuid"]
34+
35+
[dependency-groups]
36+
dev = [
37+
"pytest>=9.0",
38+
"ty>=0.0.23",
39+
"ruff>=0.15.6",
40+
]
41+
42+
[tool.ruff]
43+
# we're not on VT220's any more
244
line-length = 120
45+
target-version = "py310"
346

4-
[tool.isort]
5-
multi_line_output = 3
6-
include_trailing_comma = true
7-
force_grid_wrap = 0
8-
use_parentheses = true
9-
ensure_newline_before_comments = true
10-
line_length = 120
47+
[tool.ruff.lint]
48+
select = [
49+
# pycodestyle
50+
"E",
51+
# Pyflakes
52+
"F",
53+
# pyupgrade
54+
"UP",
55+
# isort
56+
"I",
57+
]

0 commit comments

Comments
 (0)