Skip to content

Commit cef2f18

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

File tree

19 files changed

+386
-216
lines changed

19 files changed

+386
-216
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/ci.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: CI
2+
on: [pull_request]
3+
jobs:
4+
lint:
5+
runs-on: ubuntu-latest
6+
strategy:
7+
matrix:
8+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
9+
steps:
10+
- uses: actions/checkout@v5
11+
- name: Install the latest version of uv
12+
uses: astral-sh/setup-uv@v7
13+
with:
14+
python-version: ${{ matrix.python }}
15+
enable-cache: true
16+
- name: Sync lockfile
17+
run: uv sync
18+
- name: Run linting
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
27+
test:
28+
runs-on: ubuntu-latest
29+
strategy:
30+
matrix:
31+
python: ["3.10", "3.11", "3.12", "3.13", "3.14"]
32+
steps:
33+
- uses: actions/checkout@v5
34+
- name: Install the latest version of uv
35+
uses: astral-sh/setup-uv@v7
36+
with:
37+
python-version: ${{ matrix.python }}
38+
enable-cache: true
39+
- name: Install deps
40+
run: uv sync
41+
- name: Run linting
42+
run: uv run pytest
43+
build:
44+
runs-on: ubuntu-latest
45+
needs: [prek, lint, test]
46+
steps:
47+
- run: echo "This is a dummy job so that we can only require one job for branch protection"

.github/workflows/lint.yml

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

.github/workflows/test.yml

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

.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

0 commit comments

Comments
 (0)