Skip to content

Commit 74791a0

Browse files
authored
chore: Migrate dev setup from hatch to uv (#46)
1 parent 917526a commit 74791a0

File tree

11 files changed

+2491
-146
lines changed

11 files changed

+2491
-146
lines changed

.github/workflows/ci.yml

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release
1+
name: CI
22

33
on:
44
push:
@@ -14,34 +14,33 @@ jobs:
1414
Lint:
1515
runs-on: ubuntu-latest
1616
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v3
19-
20-
# this could be replaced with pre-commit.ci
21-
- run: pipx run pre-commit run --all-files
17+
- uses: actions/checkout@v3
18+
- uses: astral-sh/setup-uv@v3
19+
with:
20+
version: "0.4.x"
21+
- run: |
22+
uv run ruff check
23+
uv run ruff format
2224
2325
Test:
2426
runs-on: ubuntu-latest
2527
strategy:
2628
matrix:
27-
python-version: ["3.8", "3.9", "3.10", "3.11"]
28-
29+
python-version:
30+
- "3.8"
31+
- "3.9"
32+
- "3.10"
33+
- "3.11"
2934
steps:
30-
- name: Checkout
31-
uses: actions/checkout@v3
32-
33-
- name: Set up Python ${{ matrix.python-version }}
34-
uses: actions/setup-python@v4
35+
- uses: actions/checkout@v3
36+
- run: echo "${{ matrix.python-version }}" > .python-version
37+
- uses: actions/setup-python@v5
3538
with:
36-
python-version: ${{ matrix.python-version }}
37-
38-
- name: Install dependencies
39-
run: |
40-
python -m pip install --upgrade pip
41-
pip install -e .[test,dev]
42-
43-
- name: Run tests
44-
run: pytest --color=yes
39+
python-version-file: ".python-version"
40+
- uses: astral-sh/setup-uv@v3
41+
with:
42+
version: "0.4.x"
43+
- run: uv run pytest --color=yes
4544

4645
Release:
4746
if: startsWith(github.ref, 'refs/tags/')
@@ -50,24 +49,17 @@ jobs:
5049
steps:
5150
- uses: actions/checkout@v3
5251

53-
- name: Setup Python
54-
uses: actions/setup-python@v4
52+
- uses: astral-sh/setup-uv@v3
5553
with:
56-
python-version: "3.x"
57-
58-
- name: Install dependencies
59-
run: |
60-
python -m pip install --upgrade pip
61-
pip install build twine
54+
version: "0.4.x"
6255

63-
- name: Build
64-
run: |
65-
python -m build
66-
twine check dist/*
56+
- run: |
57+
uv build
58+
uvx twine check dist/*
6759
ls -lh dist
6860
6961
- name: Publish to PyPI
70-
run: twine upload dist/*
62+
run: uvx twine upload dist/*
7163
env:
7264
TWINE_USERNAME: __token__
7365
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}

.pre-commit-config.yaml

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

README.md

Lines changed: 5 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -73,60 +73,24 @@ umap_vs_ozette
7373
<img width="1269" alt="User interface of cev's comparison widget" src="https://github.com/OzetteTech/comparative-embedding-visualization/assets/84813279/db28944b-fa36-475c-b3b9-efd07272e1b9">
7474

7575

76-
7776
See [notebooks/getting-started.ipynb](notebooks/getting-started.ipynb) for the complete example.
7877

7978
## Development
8079

81-
First, create a virtual environment with all the required dependencies. We highly recommend to use [`hatch`](https://github.com/pypa/hatch), which installs and sync all dependencies from `pyproject.toml` automatically.
82-
83-
```sh
84-
hatch shell
85-
```
86-
87-
Alternatively, you can also use [`conda`](https://docs.conda.io/en/latest/).
80+
We use [`uv`](https://astral.sh/uv) for development.
8881

8982
```sh
90-
conda env create -n cev python=3.11
91-
conda activate cev
92-
```
93-
94-
Next, install `cev` with all development assets.
95-
96-
```sh
97-
pip install -e ".[notebooks,dev]"
98-
```
99-
100-
Finally, you can now run the notebooks with:
101-
102-
```sh
103-
jupyterlab
83+
uv run jupyterlab
10484
```
10585

10686
### Commands Cheatsheet
10787

108-
If using `hatch` CLI, the following commands are available in the default environment:
109-
11088
| Command | Action |
11189
| :--------------------- | :------------------------------------------------------------------ |
112-
| `hatch run fix` | Format project with `black .` and apply linting with `ruff --fix .` |
113-
| `hatch run fmt` | Format project with `black .` and apply linting with `ruff --fix .` |
114-
| `hatch run check` | Check formatting and linting with `black --check .` and `ruff .`. |
115-
| `hatch run test` | Run unittests with `pytest` in base environment. |
116-
| `hatch run test:test` | Run unittests with `pytest` in all supported environments. |
117-
118-
Alternatively, you can devlop **cev** by manually creating a virtual environment and managing
119-
dependencies with `pip`.
120-
121-
Our CI linting/formatting checks are configured with [`pre-commit`](https://pre-commit.com/).
122-
We recommend installing the git hook scripts to allow `pre-commit` to run automatically on `git commit`.
123-
124-
```sh
125-
pre-commit install # run this once to install the git hooks
126-
```
90+
| `uv run ruff format` | Format the source code. |
91+
| `uv run ruff check` | Check the source code for formatting issues. |
92+
| `uv run pytest` | Run unit tests with `pytest` in base environment. |
12793

128-
This will ensure that code pushed to CI meets our linting and formatting criteria. Code that does
129-
not comply will fail in CI.
13094

13195
## Release
13296

notebooks/abundance-analysis.ipynb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,10 @@
3333
"outputs": [],
3434
"source": [
3535
"import pathlib\n",
36-
"import sys\n",
36+
"\n",
3737
"import pandas as pd\n",
38-
"from cev.widgets import Embedding, EmbeddingComparisonWidget, compare\n",
38+
"\n",
39+
"from cev.widgets import Embedding, EmbeddingComparisonWidget\n",
3940
"\n",
4041
"\n",
4142
"def get_embedding(folder: str, sample: str):\n",

notebooks/getting-started.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"outputs": [],
2323
"source": [
2424
"import pandas as pd\n",
25+
"\n",
2526
"from cev.widgets import Embedding, EmbeddingComparisonWidget"
2627
]
2728
},

notebooks/lui-2021.ipynb

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
"outputs": [],
3232
"source": [
3333
"import pathlib\n",
34-
"import sys\n",
34+
"\n",
3535
"import pandas as pd\n",
36-
"from cev.widgets import Embedding, EmbeddingComparisonWidget, compare"
36+
"\n",
37+
"from cev.widgets import Embedding, EmbeddingComparisonWidget"
3738
]
3839
},
3940
{
@@ -126,18 +127,18 @@
126127
"for column in marker_annotations:\n",
127128
" marker_annotations[column] = marker_annotations[column].str.slice(-1)\n",
128129
"\n",
129-
"df_ozette_umap_ozette_labels[\n",
130-
" [f\"{m}_faust_annotation\" for m in markers]\n",
131-
"] = marker_annotations\n",
132-
"df_ozette_umap_symphony_labels[\n",
133-
" [f\"{m}_faust_annotation\" for m in markers]\n",
134-
"] = marker_annotations\n",
135-
"df_symphony_umap_ozette_labels[\n",
136-
" [f\"{m}_faust_annotation\" for m in markers]\n",
137-
"] = marker_annotations\n",
138-
"df_symphony_umap_symphony_labels[\n",
139-
" [f\"{m}_faust_annotation\" for m in markers]\n",
140-
"] = marker_annotations"
130+
"df_ozette_umap_ozette_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
131+
" marker_annotations\n",
132+
")\n",
133+
"df_ozette_umap_symphony_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
134+
" marker_annotations\n",
135+
")\n",
136+
"df_symphony_umap_ozette_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
137+
" marker_annotations\n",
138+
")\n",
139+
"df_symphony_umap_symphony_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
140+
" marker_annotations\n",
141+
")"
141142
]
142143
},
143144
{

pyproject.toml

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,7 @@ dependencies = [
3333
]
3434
dynamic = ["version"]
3535

36-
# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
3736
[project.optional-dependencies]
38-
dev = [
39-
"black[jupyter]==23.1.0",
40-
"jupyterlab",
41-
"pytest",
42-
"ruff==0.0.246",
43-
]
4437
notebooks = [
4538
"pyarrow",
4639
"fastparquet",
@@ -59,31 +52,15 @@ sources = ["src"]
5952
[tool.hatch.version]
6053
source = "vcs"
6154

62-
[tool.hatch.envs.default]
63-
python = "3.10"
64-
features = ["dev", "notebooks"]
65-
66-
[tool.hatch.envs.default.scripts]
67-
fmt = [
68-
"black .",
69-
"ruff --fix .",
70-
]
71-
check = [
72-
"black --check --diff .",
73-
"ruff .",
74-
]
75-
test = "pytest --color=yes"
76-
77-
[[tool.hatch.envs.test.matrix]]
78-
python = ["38", "39", "310", "311"]
79-
8055
[tool.ruff]
8156
line-length = 88
8257
target-version = "py38"
58+
59+
[tool.ruff.lint]
8360
extend-select = [
8461
"E", # style errors
8562
"F", # flake
86-
# "D", # pydocstyle
63+
# "D", # pydocstyle
8764
"I001", # isort
8865
"UP", # pyupgrade
8966
"RUF", # ruff-specific rules
@@ -98,3 +75,10 @@ filterwarnings = [
9875
"ignore:Jupyter is migrating its paths:DeprecationWarning",
9976
"ignore:Deprecated in traitlets 4.1, use the instance .metadata:DeprecationWarning",
10077
]
78+
79+
[tool.uv]
80+
dev-dependencies = [
81+
"jupyterlab>=4.2.5",
82+
"pytest>=8.3.3",
83+
"ruff>=0.7.0",
84+
]

src/cev/_embedding_comparison_widget.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525

2626
def _create_titles(
27-
titles: tuple[str, str]
27+
titles: tuple[str, str],
2828
) -> tuple[ipywidgets.Widget, ipywidgets.Widget]:
2929
left_title, right_title = titles
3030
spacer = ipywidgets.HTML(

src/cev/_widget_utils.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,15 +399,13 @@ def robust_labels(labels: npt.ArrayLike, robust: npt.NDArray[np.bool_] | None =
399399

400400

401401
@typing.overload
402-
def create_colormaps(cats: typing.Iterable[str]) -> dict:
403-
...
402+
def create_colormaps(cats: typing.Iterable[str]) -> dict: ...
404403

405404

406405
@typing.overload
407406
def create_colormaps(
408407
cats: typing.Iterable[str], *other: typing.Iterable[str]
409-
) -> tuple[dict, ...]:
410-
...
408+
) -> tuple[dict, ...]: ...
411409

412410

413411
def create_colormaps(

tests/test_widget_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import pandas as pd
2+
23
from cev._widget_utils import trim_label_series
34

45

0 commit comments

Comments
 (0)