Skip to content

Commit 6513532

Browse files
authored
setup: Migrate to uv and pyproject.toml (#33)
1 parent 54f40c7 commit 6513532

File tree

10 files changed

+2108
-130
lines changed

10 files changed

+2108
-130
lines changed

.github/workflows/default.yml

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
name: default
22

3-
on: [push, pull_request]
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
release:
9+
types: [created]
10+
branches:
11+
- 'main'
12+
workflow_dispatch:
413

514
jobs:
615

@@ -10,6 +19,10 @@ jobs:
1019
steps:
1120
- name: Checkout
1221
uses: actions/checkout@v4
22+
- name: Install uv
23+
uses: astral-sh/setup-uv@v4
24+
with:
25+
version: "latest"
1326
- name: Set up Python
1427
uses: actions/setup-python@v5
1528
with:
@@ -62,25 +75,24 @@ jobs:
6275
steps:
6376
- name: Checkout
6477
uses: actions/checkout@v4
78+
- name: Install uv
79+
uses: astral-sh/setup-uv@v4
80+
with:
81+
version: "latest"
6582
- name: Set up Python
6683
uses: actions/setup-python@v5
6784
with:
6885
python-version: ${{ matrix.python-version }}
69-
cache: pip
70-
cache-dependency-path: |
71-
setup.cfg
72-
requirements/test.txt
7386
- name: Install dependencies
7487
run: |
7588
sudo apt install -y libsnappy-dev
76-
python -m pip install -U pip setuptools wheel
77-
python -m pip install -U -e ".[build,test,zeromq,redis,thrift,snappy]"
89+
uv sync --extra zeromq --extra redis --extra thrift --extra snappy
7890
- name: Run unit tests
7991
env:
8092
REDIS_HOST: localhost
8193
REDIS_PORT: ${{ job.services.redis.ports[6379] }}
8294
run: |
83-
python -m pytest --cov tests
95+
uv run python -m pytest --cov tests
8496
- name: Upload coverage report
8597
uses: codecov/codecov-action@v3
8698

@@ -104,25 +116,24 @@ jobs:
104116
steps:
105117
- name: Checkout
106118
uses: actions/checkout@v4
119+
- name: Install uv
120+
uses: astral-sh/setup-uv@v4
121+
with:
122+
version: "latest"
107123
- name: Set up Python
108124
uses: actions/setup-python@v5
109125
with:
110126
python-version: ${{ matrix.python-version }}
111-
cache: pip
112-
cache-dependency-path: |
113-
setup.cfg
114-
requirements/test.txt
115127
- name: Install dependencies
116128
run: |
117129
sudo apt install -y libsnappy-dev
118-
python -m pip install -U pip setuptools wheel
119-
python -m pip install -U -e ".[build,test,zeromq,redis,thrift,snappy]"
130+
uv sync --extra zeromq --extra redis --extra thrift --extra snappy
120131
- name: Run integration tests
121132
env:
122133
REDIS_HOST: localhost
123134
REDIS_PORT: ${{ job.services.redis.ports[6379] }}
124135
run: |
125-
./scripts/run-integration-tests.sh
136+
uv run ./scripts/run-integration-tests.sh
126137
127138
build-distributions:
128139
needs: [pre-commit-check, test-unit, test-integration]
@@ -134,29 +145,28 @@ jobs:
134145
uses: actions/checkout@v4
135146
- name: Fetch remote tags
136147
run: git fetch origin 'refs/tags/*:refs/tags/*' -f
148+
- name: Install uv
149+
uses: astral-sh/setup-uv@v4
150+
with:
151+
version: "latest"
137152
- name: Set up Python
138153
uses: actions/setup-python@v5
139154
with:
140155
python-version: "3.11"
141-
cache: pip
142-
cache-dependency-path: |
143-
setup.cfg
144-
requirements/build.txt
145156
- name: Install dependencies
146157
run: |
147-
python -m pip install -U pip setuptools wheel
148-
python -m pip install -U -r requirements/build.txt
158+
uv sync
149159
- name: Build packages
150160
run: |
151-
python -c "import callosum; print(callosum.__version__)" | tee version.txt
152-
python -m build -s -w
161+
uv run python -c "import callosum; print(callosum.__version__)" | tee version.txt
162+
uv build
153163
- name: Upload the build version
154164
uses: actions/upload-artifact@v4
155165
with:
156166
name: version
157167
path: version.txt
158168
- name: Upload build artifacts
159-
uses: actions/upload-artifact@v3
169+
uses: actions/upload-artifact@v4
160170
with:
161171
name: distributions
162172
path: dist
@@ -179,7 +189,7 @@ jobs:
179189
name: version
180190
path: .
181191
- name: Download build artifacts
182-
uses: actions/download-artifact@v3
192+
uses: actions/download-artifact@v4
183193
with:
184194
name: distributions
185195
path: dist
@@ -192,7 +202,7 @@ jobs:
192202
python ./scripts/extract-release-changelog.py
193203
python ./scripts/determine-release-type.py
194204
- name: Publish to GitHub
195-
uses: softprops/action-gh-release@v1
205+
uses: softprops/action-gh-release@v2
196206
with:
197207
body_path: "CHANGELOG_RELEASE.md"
198208
prerelease: ${{ env.IS_PRERELEASE }}

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ repos:
88
- id: end-of-file-fixer
99
- id: trailing-whitespace
1010
- repo: https://github.com/astral-sh/ruff-pre-commit
11-
rev: v0.2.2
11+
rev: v0.11.13
1212
hooks:
1313
- id: ruff
1414
args: [--fix, --exit-non-zero-on-fix]
1515
- id: ruff-format
1616
- repo: https://github.com/pre-commit/mirrors-mypy
17-
rev: v1.8.0
17+
rev: v1.16.0
1818
hooks:
1919
- id: mypy
2020
additional_dependencies: [

README.md

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,118 @@ Please check out [the examples directory.](https://github.com/lablup/callosum/tr
6363
Development
6464
-----------
6565

66-
Create a virtual environment or an isolated Python environment using your favorite tool.
66+
This project uses [uv](https://docs.astral.sh/uv/) for dependency management and development workflow.
6767

68-
Inside it, run editable installation as follows:
68+
### Prerequisites
69+
70+
Install uv:
6971

7072
```console
71-
$ pip install -U pip setuptools
72-
$ pip install -U -r requirements/dev.txt
73+
$ curl -LsSf https://astral.sh/uv/install.sh | sh
74+
```
75+
76+
### Setup
77+
78+
Clone the repository and set up the development environment:
79+
80+
```console
81+
$ git clone https://github.com/lablup/callosum.git
82+
$ cd callosum
83+
$ uv sync --dev
84+
```
85+
86+
This will create a virtual environment and install the package in editable mode along with all development dependencies.
87+
88+
### Development Commands
89+
90+
Run tests:
91+
```console
92+
$ uv run pytest
93+
```
94+
95+
Run pre-commit hooks for linting:
96+
```console
97+
$ pre-commit run --all-files
7398
```
99+
100+
Build the package:
101+
```console
102+
$ uv build
103+
```
104+
105+
### News Fragment Types
106+
107+
Use these suffixes to put news fragments in the `changes/` directory for each PR, whereas the name should be the PR number (e.g., `1234.fix.dm`):
108+
109+
- `.breaking.md` - Breaking changes
110+
- `.feature.md` - New features
111+
- `.fix.md` - Bug fixes
112+
- `.deprecation.md` - Deprecation notices
113+
- `.doc.md` - Documentation changes
114+
- `.misc.md` - Miscellaneous changes
115+
116+
### Running Examples
117+
118+
You can run examples using uv with additional dependencies:
119+
120+
```console
121+
$ uv sync --extra zeromq --extra redis --extra thrift --extra snappy
122+
$ uv run python examples/simple-server.py
123+
```
124+
125+
Making a Release
126+
----------------
127+
128+
This project uses [towncrier](https://towncrier.readthedocs.io/) for changelog management and [setuptools-scm](https://setuptools-scm.readthedocs.io/) for automatic versioning based on git tags.
129+
130+
### Release Process
131+
132+
1. **Ensure all changes are documented**: Add change fragments to the `changes/` directory:
133+
```console
134+
# For a bug fix
135+
$ echo "Fix description of the bug fix ([#123](https://github.com/lablup/callosum/issues/123))" > changes/123.fix.md
136+
137+
# For a new feature
138+
$ echo "Description of the new feature ([#124](https://github.com/lablup/callosum/issues/124))" > changes/124.feature.md
139+
```
140+
141+
2. **Generate the changelog**: Create a draft changelog to review:
142+
```console
143+
$ uv run towncrier build --draft --version 1.0.4
144+
```
145+
146+
3. **Build and finalize the changelog**: When ready to release:
147+
```console
148+
$ uv run towncrier build --version 1.0.4
149+
```
150+
This updates `CHANGES.md` and removes the change fragments.
151+
152+
4. **Commit the changelog**:
153+
```console
154+
$ git add CHANGES.md changes/
155+
$ git commit -m "release: 1.0.4"
156+
```
157+
158+
5. **Create and push a annotated, signed git tag**:
159+
```console
160+
$ git tag -a -s 1.0.4
161+
$ git push origin main --tags
162+
```
163+
164+
6. **Automated release**: The GitHub Actions workflow will automatically:
165+
- Run all tests and checks
166+
- Build source and wheel distributions using `uv build`
167+
- Extract release notes from the changelog
168+
- Create a GitHub release with the built artifacts
169+
- Publish to PyPI using trusted publishing
170+
171+
### Release Workflow
172+
173+
The release is triggered automatically when a git tag is pushed. The workflow:
174+
175+
1. **Triggers on**: Git tag push (e.g., `git push origin --tags`)
176+
2. **Builds**: Uses `uv build` to create distributions
177+
3. **Publishes**:
178+
- GitHub release with changelog and artifacts
179+
- PyPI release using trusted publishing (no manual tokens needed)
180+
4. **Determines release type**: Automatically detects pre-releases (`rc`, `a` (alpha), `b` (beta), `dev` suffixes)

examples/simple-client-thrift.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ async def call() -> None:
5050
await peer.invoke("simple", adaptor.long_delay())
5151
except asyncio.TimeoutError:
5252
print(
53-
"long_delay(): timeout occurred as expected "
54-
"(with per-call timeout)"
53+
"long_delay(): timeout occurred as expected (with per-call timeout)"
5554
)
5655
else:
5756
print("long_delay(): timeout did not occur!")
@@ -61,8 +60,7 @@ async def call() -> None:
6160
await peer.invoke("simple", adaptor.long_delay())
6261
except asyncio.TimeoutError:
6362
print(
64-
"long_delay(): timeout occurred as expected "
65-
"(with default timeout)"
63+
"long_delay(): timeout occurred as expected (with default timeout)"
6664
)
6765
else:
6866
print("long_delay(): timeout did not occur!")

examples/simple-client.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@ async def test_timeout(peer):
5050
},
5151
)
5252
except asyncio.TimeoutError:
53-
print(
54-
"long_delay(): timeout occurred as expected " "(with per-call timeout)"
55-
)
53+
print("long_delay(): timeout occurred as expected (with per-call timeout)")
5654
except Exception as e:
5755
print("long_delay(): unexpected error", e)
5856
sys.exit(1)
@@ -68,7 +66,7 @@ async def test_timeout(peer):
6866
},
6967
)
7068
except asyncio.TimeoutError:
71-
print("long_delay(): timeout occurred as expected " "(with default timeout)")
69+
print("long_delay(): timeout occurred as expected (with default timeout)")
7270
except Exception as e:
7371
print("long_delay(): unexpected error", e)
7472
sys.exit(1)

0 commit comments

Comments
 (0)