Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Migrate dev setup to uv #46

Merged
merged 5 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 27 additions & 35 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Release
name: CI

on:
push:
Expand All @@ -14,34 +14,33 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

# this could be replaced with pre-commit.ci
- run: pipx run pre-commit run --all-files
- uses: actions/checkout@v3
- uses: astral-sh/setup-uv@v3
with:
version: "0.4.x"
- run: |
uv run ruff check
uv run ruff format

Test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

python-version:
- "3.8"
- "3.9"
- "3.10"
- "3.11"
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
- uses: actions/checkout@v3
- run: echo "${{ matrix.python-version }}" > .python-version
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -e .[test,dev]

- name: Run tests
run: pytest --color=yes
python-version-file: ".python-version"
- uses: astral-sh/setup-uv@v3
with:
version: "0.4.x"
- run: uv run pytest --color=yes

Release:
if: startsWith(github.ref, 'refs/tags/')
Expand All @@ -50,24 +49,17 @@ jobs:
steps:
- uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
- uses: astral-sh/setup-uv@v3
with:
python-version: "3.x"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install build twine
version: "0.4.x"

- name: Build
run: |
python -m build
twine check dist/*
- run: |
uv build
uvx twine check dist/*
ls -lh dist

- name: Publish to PyPI
run: twine upload dist/*
run: uvx twine upload dist/*
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_API_KEY }}
23 changes: 0 additions & 23 deletions .pre-commit-config.yaml

This file was deleted.

46 changes: 5 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,60 +73,24 @@ umap_vs_ozette
<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">



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

## Development

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.

```sh
hatch shell
```

Alternatively, you can also use [`conda`](https://docs.conda.io/en/latest/).
We use [`uv`](https://astral.sh/uv) for development.

```sh
conda env create -n cev python=3.11
conda activate cev
```

Next, install `cev` with all development assets.

```sh
pip install -e ".[notebooks,dev]"
```

Finally, you can now run the notebooks with:

```sh
jupyterlab
uv run jupyterlab
```

### Commands Cheatsheet

If using `hatch` CLI, the following commands are available in the default environment:

| Command | Action |
| :--------------------- | :------------------------------------------------------------------ |
| `hatch run fix` | Format project with `black .` and apply linting with `ruff --fix .` |
| `hatch run fmt` | Format project with `black .` and apply linting with `ruff --fix .` |
| `hatch run check` | Check formatting and linting with `black --check .` and `ruff .`. |
| `hatch run test` | Run unittests with `pytest` in base environment. |
| `hatch run test:test` | Run unittests with `pytest` in all supported environments. |

Alternatively, you can devlop **cev** by manually creating a virtual environment and managing
dependencies with `pip`.

Our CI linting/formatting checks are configured with [`pre-commit`](https://pre-commit.com/).
We recommend installing the git hook scripts to allow `pre-commit` to run automatically on `git commit`.

```sh
pre-commit install # run this once to install the git hooks
```
| `uv run ruff format` | Format the source code. |
| `uv run ruff check` | Check the source code for formatting issues. |
| `uv run pytest` | Run unit tests with `pytest` in base environment. |

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

## Release

Expand Down
5 changes: 3 additions & 2 deletions notebooks/abundance-analysis.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
"outputs": [],
"source": [
"import pathlib\n",
"import sys\n",
"\n",
"import pandas as pd\n",
"from cev.widgets import Embedding, EmbeddingComparisonWidget, compare\n",
"\n",
"from cev.widgets import Embedding, EmbeddingComparisonWidget\n",
"\n",
"\n",
"def get_embedding(folder: str, sample: str):\n",
Expand Down
1 change: 1 addition & 0 deletions notebooks/getting-started.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"outputs": [],
"source": [
"import pandas as pd\n",
"\n",
"from cev.widgets import Embedding, EmbeddingComparisonWidget"
]
},
Expand Down
29 changes: 15 additions & 14 deletions notebooks/lui-2021.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@
"outputs": [],
"source": [
"import pathlib\n",
"import sys\n",
"\n",
"import pandas as pd\n",
"from cev.widgets import Embedding, EmbeddingComparisonWidget, compare"
"\n",
"from cev.widgets import Embedding, EmbeddingComparisonWidget"
]
},
{
Expand Down Expand Up @@ -126,18 +127,18 @@
"for column in marker_annotations:\n",
" marker_annotations[column] = marker_annotations[column].str.slice(-1)\n",
"\n",
"df_ozette_umap_ozette_labels[\n",
" [f\"{m}_faust_annotation\" for m in markers]\n",
"] = marker_annotations\n",
"df_ozette_umap_symphony_labels[\n",
" [f\"{m}_faust_annotation\" for m in markers]\n",
"] = marker_annotations\n",
"df_symphony_umap_ozette_labels[\n",
" [f\"{m}_faust_annotation\" for m in markers]\n",
"] = marker_annotations\n",
"df_symphony_umap_symphony_labels[\n",
" [f\"{m}_faust_annotation\" for m in markers]\n",
"] = marker_annotations"
"df_ozette_umap_ozette_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
" marker_annotations\n",
")\n",
"df_ozette_umap_symphony_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
" marker_annotations\n",
")\n",
"df_symphony_umap_ozette_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
" marker_annotations\n",
")\n",
"df_symphony_umap_symphony_labels[[f\"{m}_faust_annotation\" for m in markers]] = (\n",
" marker_annotations\n",
")"
]
},
{
Expand Down
36 changes: 10 additions & 26 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,7 @@ dependencies = [
]
dynamic = ["version"]

# https://peps.python.org/pep-0621/#dependencies-optional-dependencies
[project.optional-dependencies]
dev = [
"black[jupyter]==23.1.0",
"jupyterlab",
"pytest",
"ruff==0.0.246",
]
notebooks = [
"pyarrow",
"fastparquet",
Expand All @@ -59,31 +52,15 @@ sources = ["src"]
[tool.hatch.version]
source = "vcs"

[tool.hatch.envs.default]
python = "3.10"
features = ["dev", "notebooks"]

[tool.hatch.envs.default.scripts]
fmt = [
"black .",
"ruff --fix .",
]
check = [
"black --check --diff .",
"ruff .",
]
test = "pytest --color=yes"

[[tool.hatch.envs.test.matrix]]
python = ["38", "39", "310", "311"]

[tool.ruff]
line-length = 88
target-version = "py38"

[tool.ruff.lint]
extend-select = [
"E", # style errors
"F", # flake
# "D", # pydocstyle
# "D", # pydocstyle
"I001", # isort
"UP", # pyupgrade
"RUF", # ruff-specific rules
Expand All @@ -98,3 +75,10 @@ filterwarnings = [
"ignore:Jupyter is migrating its paths:DeprecationWarning",
"ignore:Deprecated in traitlets 4.1, use the instance .metadata:DeprecationWarning",
]

[tool.uv]
dev-dependencies = [
"jupyterlab>=4.2.5",
"pytest>=8.3.3",
"ruff>=0.7.0",
]
2 changes: 1 addition & 1 deletion src/cev/_embedding_comparison_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@


def _create_titles(
titles: tuple[str, str]
titles: tuple[str, str],
) -> tuple[ipywidgets.Widget, ipywidgets.Widget]:
left_title, right_title = titles
spacer = ipywidgets.HTML(
Expand Down
6 changes: 2 additions & 4 deletions src/cev/_widget_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,15 +399,13 @@ def robust_labels(labels: npt.ArrayLike, robust: npt.NDArray[np.bool_] | None =


@typing.overload
def create_colormaps(cats: typing.Iterable[str]) -> dict:
...
def create_colormaps(cats: typing.Iterable[str]) -> dict: ...


@typing.overload
def create_colormaps(
cats: typing.Iterable[str], *other: typing.Iterable[str]
) -> tuple[dict, ...]:
...
) -> tuple[dict, ...]: ...


def create_colormaps(
Expand Down
1 change: 1 addition & 0 deletions tests/test_widget_utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pandas as pd

from cev._widget_utils import trim_label_series


Expand Down
Loading
Loading