Skip to content

Commit

Permalink
chore: Migrate dev from hatch to uv (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
manzt committed Oct 18, 2024
1 parent 532558a commit 4491d73
Show file tree
Hide file tree
Showing 13 changed files with 1,844 additions and 181 deletions.
50 changes: 17 additions & 33 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,53 +13,37 @@ jobs:
Lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.x"
- run: |
python -m pip install --upgrade hatch
hatch run lint
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
with:
version: "0.4.x"
- run: |
uv run ruff check .
Test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: |
python -m pip install --upgrade pip
pip install -e .[dev]
pytest
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
with:
version: "0.4.x"
- run: uv run pytest
env:
UV_PYTHON: ${{ matrix.python-version }}

Release:
needs: [Lint, Test]
runs-on: ubuntu-latest
if: startsWith(github.ref, 'refs/tags')
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Python
uses: actions/setup-python@v4
- uses: actions/checkout@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
- name: Build
run: python -m build

version: "0.4.x"
- run: uv build
- name: Publish distribution 📦 to PyPI
uses: pypa/gh-action-pypi-publish@release/v1
with:
Expand Down
26 changes: 6 additions & 20 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,18 @@ jobs:
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

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

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

- name: Build
run: hatch run docs:build
- run: uv run docs/build.py

- name: Setup Pages
uses: actions/configure-pages@v3

- name: Upload artifact
uses: actions/upload-pages-artifact@v1
- uses: actions/configure-pages@v3
- uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: './docs/_build/html'

- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v1

17 changes: 4 additions & 13 deletions .github/workflows/docs_s3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,12 @@ jobs:
deploy_s3:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

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

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

- name: Build
run: hatch run docs:build
- run: uv run docs/build.py

- name: Publish docs to S3
uses: jakejarvis/s3-sync-action@master
Expand Down
46 changes: 12 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,44 +70,22 @@ and understanding are greatly appreciated.

## Development

**higlass-python** uses
[the recommended](https://packaging.python.org/en/latest/flow/#) `hatchling`
build-system, which is convenient to use via the
[`hatch` CLI](https://hatch.pypa.io/latest/). We recommend installing `hatch`
globally (e.g., via `pipx`) and running the various commands defined within
`pyproject.toml`. `hatch` will take care of creating and synchronizing a virtual
environment with all dependencies defined in `pyproject.toml`.
**higlass-python** uses uses [uv](https://astral.sh/uv) for development.

### Commands Cheatsheet

All commands are run from the root of the project, from a terminal:

| Command | Action |
| :--------------------- | :------------------------------------------------------------------ |
| `hatch run fix` | Format project with `black .` and apply linting with `ruff --fix .` |
| `hatch run lint` | Lint project with `ruff .`. |
| `hatch run test` | Run unit tests with `pytest` in latest Python version. |
| `hatch run test:test` | Run unit tests with `pytest` in all target Python versions. |
| `hatch run docs:build` | Build the documentation in `docs/_build/html`. |
| `hatch run docs:serve` | Start an dev-server for live editing RST files in `docs/`. |

> **Note**: `hatch build` and `hatch publish` are available to build and publish
> the project to PyPI, but all releases are handled automatically via CI.
Alternatively, you can develop **higlass-python** by manually creating a virtual
environment and managing installation and dependencies with `pip`. For example,
create a virtual environment with `conda`:

```bash
conda create -n higlass python=3.11
conda activate higlass
```

and install **higlass-python** in _editable_ mode with all optional
dependencies:
| Command | Action |
|---------|--------|
| `uv run ruff check --fix && uv run ruff format` | Lint and apply formatting |
| `uv run check` | Check linting rules |
| `uv run ruff format --check` | Check formatting |
| `uv run pytest` | Run unit tests |
| `uv run docs/build.py` | Build the documentation in `docs/_build/html` |

```bash
pip install -e ".[dev,fuse,docs]"
```
This table now includes only the UV-related commands, with each command in the
left column and its corresponding action in the right column. The formatting is
clean and easy to read.

Our CI checks formatting (`black .`), linting (`ruff .`), and tests (`pytest`).
Our CI enforces formatting, linting, and tests.
20 changes: 0 additions & 20 deletions docs/Makefile

This file was deleted.

14 changes: 6 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@

Documentation for all HiGlass software ([viewer][hgv], [app][hga], [server][hgs], [docker][hgd])

Simple edits can be made in GitHub. For anything more extensive, preview it locally:
Simple edits can be made in GitHub. For anything more extensive, build and preview it locally:

```
git clone https://github.com/higlass/higlass.git
cd higlass/docs
git checkout develop
pip install -r requirements.txt
./serve.sh
uv run build.py
uv run python -m http.server 8000 --directory _build/html
```

Docs are built and pushed to S3 by Travis.
See [.travis.yml](https://github.com/higlass/higlass/blob/develop/.travis.yml) for details.
Then open your browser to `http://localhost:8000`.

Docs are built and deployed via GitHub Actions via a [workflow](.github/workflows/docs.yml).

[hga]: https://github.com/higlass/higlass-app
[hgd]: https://github.com/higlass/higlass-docker
Expand Down
34 changes: 34 additions & 0 deletions docs/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "higlass-python",
# "markupsafe==2.0.1",
# "setuptools",
# "sphinx-js",
# "Sphinx",
# ]
#
# [tool.uv.sources]
# higlass-python = { path = "../" }
# ///
import pathlib

from sphinx.application import Sphinx

SELF_DIR = pathlib.Path(__file__).parent


def main():
app = Sphinx(
srcdir=SELF_DIR,
confdir=SELF_DIR,
outdir=SELF_DIR / "_build" / "html",
doctreedir=SELF_DIR / "_build" / "doctrees",
buildername="html",
)

app.build()


if __name__ == "__main__":
main()
3 changes: 0 additions & 3 deletions docs/build.sh

This file was deleted.

12 changes: 0 additions & 12 deletions docs/environment.yml

This file was deleted.

3 changes: 0 additions & 3 deletions docs/requirements.txt

This file was deleted.

3 changes: 0 additions & 3 deletions docs/serve.sh

This file was deleted.

40 changes: 8 additions & 32 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,19 @@ dependencies = [
urls = { homepage = "https://github.com/higlass/higlass-python" }

[project.optional-dependencies]
dev = [
"black[jupyter]",
"pytest",
"ruff==0.0.285",
"jupyterlab",
"anywidget[dev]>=0.6.3",
]
docs = [
"Sphinx",
"sphinx-autobuild",
"sphinx-js",
"markupsafe==2.0.1",
]
fuse = [
"fusepy",
"simple-httpfs"
]

[tool.uv]
dev-dependencies = [
"anywidget[dev]",
"jupyterlab",
"pytest",
"ruff==0.0.285"
]

[tool.hatch.build.targets.sdist]
include = ["src"]

Expand All @@ -64,25 +59,6 @@ sources = ["src"]
[tool.hatch.version]
source = "vcs"

[tool.hatch.envs.default]
features = ["dev", "fuse"]

[tool.hatch.envs.default.scripts]
fix = "black . && ruff --fix ."
lint = "black --check . && ruff ."
test = "pytest ."

[tool.hatch.envs.docs]
features = ["docs"]
python = "3.11"

[tool.hatch.envs.docs.scripts]
build = "sphinx-build -b html ./docs ./docs/_build/html"
serve = "cd docs && ./serve.sh"

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

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

0 comments on commit 4491d73

Please sign in to comment.