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

Try switching to UV #225

Merged
merged 10 commits into from
Oct 23, 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
41 changes: 26 additions & 15 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,56 +25,67 @@ jobs:
- "3.10"
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@1.79.0
- uses: Swatinem/rust-cache@v2
- name: Setup python ${{ matrix.py }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.py }}
cache: "pip"
- run: pip install -e .[test]
- run: pytest --benchmark-disable -vvv
- run: uv sync --extra test --locked
- run: uv run pytest --benchmark-disable -vvv
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@1.79.0
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
# Run on oldest Python version to catch more errors
python-version: "3.10"
cache: "pip"
- run: pip install -e .[test] mypy pre-commit
- run: pre-commit run --hook-stage manual --all-files mypy
- run: pre-commit run --hook-stage manual --all-files stubtest
- run: uv sync --extra test --locked
- run: make mypy
- run: make stubtest

benchmark:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@1.79.0
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: "3.12"
cache: "pip"
- run: pip install -e .[test]
python-version-file: ".python-version"
- run: uv sync --extra test --locked
- uses: CodSpeedHQ/action@v3
with:
token: ${{ secrets.CODSPEED_TOKEN }}
run: pytest -vvv -n auto
run: uv run pytest -vvv -n auto

docs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v3
with:
enable-cache: true
- uses: dtolnay/rust-toolchain@1.79.0
- uses: Swatinem/rust-cache@v2
- uses: actions/setup-python@v5
with:
python-version: "3.10"
cache: "pip"
python-version-file: ".python-version"
- name: Install graphviz
run: |
sudo apt-get update
sudo apt-get install -y graphviz
- run: pip install -e .[docs] pre-commit
- run: pre-commit run --hook-stage manual --all-files docs
- run: uv sync --extra docs --locked
- run: make docs
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ docs/_build/
.vscode/

# Pyenv
.python-version

TODO
*.code-workspace
Expand Down
31 changes: 0 additions & 31 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,39 +1,8 @@
exclude: ^python/tests/__snapshots__/
default_language_version:
python: python3.10
ci:
skip: [mypy, docs, stubtest]
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.0
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- id: ruff-format
- repo: local
hooks:
- id: mypy
name: mypy
entry: dmypy run -- python/
language: system
require_serial: true
pass_filenames: false
stages: [manual]
- repo: local
hooks:
- id: stubtest
name: stubtest
entry: python -m mypy.stubtest egglog.bindings --allowlist stubtest_allow
language: system
pass_filenames: false
require_serial: true
stages: [manual]
- repo: local
hooks:
- id: docs
name: docs
entry: sphinx-build -T -b html docs docs/_build/html
language: system
pass_filenames: false
require_serial: true
stages: [manual]
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
23 changes: 8 additions & 15 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,17 @@ build:
python: "3.12"
# # You can also specify other tool versions:
# # nodejs: "16"
rust: "1.70"
rust: "1.78"
# golang: "1.17"
apt_packages:
- graphviz
commands:
- asdf plugin add uv
- asdf install uv latest
- asdf global uv latest
- uv sync --extra docs --frozen
- uv run -m sphinx -T -b html -d docs/_build/doctrees -D language=en docs $READTHEDOCS_OUTPUT/html

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

# If using Sphinx, optionally build your docs in additional formats such as PDF
# formats:
# - pdf

# Optionally declare the Python requirements required to build your docs
python:
install:
- method: pip
path: .
extra_requirements:
- docs
# conda:
# environment: docs/environment.yml
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.PHONY: all clean from-local mypy stubtest docs

all: python/egglog/visualizer.js

Expand Down Expand Up @@ -26,3 +27,14 @@ clean:
from-local:
cp ../egraph-visualizer/dist/index.js python/egglog/visualizer.js
cp ../egraph-visualizer/dist/style.css python/egglog/visualizer.css

# remove once https://github.com/astral-sh/uv/issues/5903

mypy:
uv run dmypy run -- python/

stubtest:
uv run python -m mypy.stubtest egglog.bindings --allowlist stubtest_allow

docs:
uv run sphinx-build -T -b html docs docs/_build/html
9 changes: 0 additions & 9 deletions docs/how-to-guides.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,3 @@ commands
```{code-cell}
egraph.run_program(*commands)
```

## Developing this package

To get started developing on this package:

1. Create a Python environment to develop on, either with virtualenv or conda.
2. Install this package in editable mode: `pip install -e .[dev,test]`
3. Run the tests: `pytest`
4. Run the pre-commit hooks: `pre-commit run --all-files`
20 changes: 9 additions & 11 deletions docs/reference/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ gh repo fork egraphs-good/egglog-python --clone
cd egglog-python
```

Then [install Rust](https://www.rust-lang.org/tools/install) and get a Python environment set up with a compatible version. Using [miniconda](https://formulae.brew.sh/cask/miniconda) this would be:
Then [install Rust](https://www.rust-lang.org/tools/install) and get a Python environment set up with a compatible version. Using [uv](https://docs.astral.sh/uv/getting-started/installation/) this would be:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
brew install --cask miniconda
conda create -n egglog-python python
conda activate egglog-python
curl -LsSf https://astral.sh/uv/install.sh | sh
```

Then install the package in editable mode with the development dependencies:

```bash
maturin develop -E dev,docs,test,array
uv sync --all-extras
```

Anytime you change the rust code, you can run `maturin develop` to recompile the rust code.
Anytime you change the rust code, you can run `uv sync` to recompile the rust code.

If you would like to download a new version of the visualizer source, run `make clean; make`. This will download
the most recent released version from the github actions artifact in the [egraph-visualizer](https://github.com/egraphs-good/egraph-visualizer) repo. It is checked in because it's a pain to get cargo to include only one git ignored file while ignoring the rest of the files that were ignored.
Expand All @@ -45,33 +43,33 @@ the most recent released version from the github actions artifact in the [egraph
To run the tests, you can use the `pytest` command:

```bash
pytest
uv run pytest
```

All code must pass ruff linters and formaters. This will be checked automatically by the pre-commit if you run `pre-commit install`.

To run it manually, you can use:

```bash
pre-commit run --all-files ruff
uv run pre-commit run --all-files ruff
```

If you make changes to the rust bindings, you can check that the stub files accurately reflect the rust code by running:

```bash
pre-commit run --all-files --hook-stage manual stubtest
make stubtest
```

All code must all pass MyPy type checking. To run that locally use:

```bash
pre-commit run --all-files --hook-stage manual mypy
make mypy
```

Finally, to build the docs locally and test that they work, you can run:

```bash
pre-commit run --all-files --hook-stage manual docs
make docs
```

## Making changes
Expand Down
6 changes: 5 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ array = [
"numba==0.59.1",
"llvmlite==0.42.0",
]
dev = ["pre-commit", "ruff", "mypy", "anywidget[dev]", "egglog[docs,test]"]
dev = ["ruff", "pre-commit", "mypy", "anywidget[dev]", "egglog[docs,test]"]

test = [
"pytest",
Expand All @@ -62,6 +62,7 @@ docs = [
"ablog",
]


[tool.ruff.lint]
ignore = [
# Allow uppercase vars
Expand Down Expand Up @@ -243,3 +244,6 @@ exclude_also = [
"@(abc\\.)?abstractmethod",
"assert_never\\(",
]

[tool.uv.workspace]
members = ["egglog"]
Loading