-
Notifications
You must be signed in to change notification settings - Fork 794
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
build: Migrate from hatch
to uv
#3723
Conversation
https://ss64.com/bash/mkdir.html We would want to see an error if `doc/` didn't exist. The docs wouldn't build as all the content is in that directory. Working on migrating to a cross-platform shell that doesn't require this option anyway https://www.nushell.sh/commands/docs/mkdir.html
Decouples from `bash`, simplifies (#3577 (comment))
Provides 2 interfaces: - `tasks.py`: to define using decorators - `tasks.toml`: an example of defining in a similar way to `hatch` scripts #3577 (comment)
Steps to reproduce: - `uv self update` or install `uv` for the [first time](https://docs.astral.sh/uv/getting-started/installation/) - `uv python install 3.12` - `cd $ALTAIR_REPO_ROOT` - `uv venv -p 3.12 --seed` - `uv sync --all-extras`
This is the non-`hatch` equivalent of `tool.hatch.envs.hatch-test.default-args` https://hatch.pypa.io/latest/config/internal/testing/#default-arguments
Bug revealed after changing the `pytest` task to only contain `"pytest"`
- Add docs - Handle semicolon joining in one place - align `mkdir_cmd` with `mkdir -p` (https://ss64.com/bash/mkdir.html)
`*_cmd` functions and these variables are unrelated Planning to namespace the functions, using `cmd`
All of these tools are now accessible under a single namespace, with discoverable docs
You can now safely run: ```py import tools tools.tasks.app.run(["lint", "format"]) ```
Terms like "clean", "build", "publish" have another meaning when talking about the distribution https://docs.astral.sh/uv/concepts/projects/build/
Covers part of step 8, step 9 in https://github.com/vega/altair/blob/7c2d97ffe80749a7cd1b24703547e40f4918172d/RELEASING.md
- Extra prep for string escaping while in a subprocess - Use `--force` in `git add` to override (https://github.com/vega/altair/blob/7c2d97ffe80749a7cd1b24703547e40f4918172d/doc/.gitignore#L1) - Raise a more informative error when a subprocess fails
All previous functionality is possible without this now. Did some tidying up of what is left using (https://github.com/vega/vega-datasets/blob/369b462f7505e4ef3454668793e001e3620861ff/taplo.toml) ## Remaining sections - `build`, `metadata`, `version` tables are used by `hatchling` - (https://hatch.pypa.io/latest/why/#build-backend) - The `doc` environment is retained **only** due to how `_HatchRunner` is implemented - Otherwise we can remove that - (6e792a1) - The test matrix functionality isn't something I've tried to reproduce, so left that in - Unsure how often others use it, but we could swap that out for `nox` - https://github.com/narwhals-dev/narwhals/blob/024d5d2294d1dcdd2e2f043d59eb03a3238c9e87/noxfile.py#L13
Didn't realise this was part of the Public API, as it wasn't listed in https://github.com/python-poetry/tomlkit/blob/635831f1be9b0e107047e74af8ebecc7c0e4b7bf/tomlkit/__init__.py#L31-L59 https://tomlkit.readthedocs.io/en/latest/api/#module-tomlkit.toml_file
You should now have access to the Altair docs repo to test things further👍 |
A bit out of scope, but I'm also fine if updating the docs becomes a manual triggered workflow via github actions. |
Ah thanks @mattijn!
If I'm unable to get things working in (https://github.com/vega/altair/blob/0ed58e59e312f1af0cc71b72655e4115f229e892/tools/sync_website.py) I'll just revert back to (https://github.com/vega/altair/blob/8a6f65c02e18c9acd3a08e02f73670795c0a7e66/doc/sync_website.sh) Happy to hold off on making that cross-platform if it becomes a blocker UpdateResolved in (#3723 (comment)) |
`uv lock --upgrade-package ruff` `uv sync --all-extras` https://docs.astral.sh/uv/guides/projects/#managing-dependencies https://github.com/vega/altair/actions/runs/12713787515/job/35442461698?pr=3723
Seems like applying the filter prevents `clone` from resulting in being on `master`
Thanks for all the work here @dangotbanned. Another concern I have is the introduction of a lock file. While it’s described as recommended to include it in the repository (https://docs.astral.sh/uv/guides/projects/#uvlock) if you need exact resolvment across OS. Can we avoid this? Why not add it to the .gitignore instead? Our dependencies are already clearly defined in the project.toml file and slight variations in resolution across maintainers shouldn’t be an issue as long as the base requirements are met? I hope we can live without. What do you think? |
Hey @mattijn, thanks for taking a look at this PR!
I'm sorry to hear you feel that way, but I am hopeful that this is something we can resolve. Just for my benefit, are these your concerns regarding complexity?
I don't quite follow how these are at-odds with simplifying maintenance, could you elaborate on that a bit further for me please?
|
Install the project with all development dependencies: | |
```cmd | |
uv sync --all-extras | |
``` |
I want to explore this some more in #3725 - where I'm hoping we'll end up with a simpler, faster workflow and be able to reproduce it locally.
I ended up writing quite a bit more (sorry) than I expected on this one 😅
I'm hoping that I was able to illustrate how the switch to uv
solves issues beyond those mentioned in #3577
I can live with the added taskipy, since it is something temporary. Regarding the lock file, now every time a subdependency is changing, we will see this related diff coming up in a PR. We worked hard to reduce the number of files in the root directory for maintenance to almost a single pyproject.toml file. It's easier to add new files or dependencies than to reduce them, so if we can avoid adding these, that is a win for all. All in all, I'm not really a big fan of a lock file. We can synchronize to a single unified developer experience, but it won't change the issues users face. I hadn't seen #3725, that seems interesting. Let me approve anyways, hopefully our initial statement holds and will the transition towards uv increase the influx of maintainers. |
Thanks for approving @mattijn
Here are some examples of actions leading to a Upgrading a dependency This one is syncing after a merge This one was after adding |
@mattijn I've thought some more about this and think I have an idea that gives us the benefits of both
So we get the failures isolated to a single branch (one less concern for new contributors). I would split this into another issue to plan out how we'd achieve this. |
Failure caused by stale resolution following #3764 fix Upgrading everything so that when this merges it will be equivalent to no `uv.lock` (which is what `main` is now) https://github.com/vega/altair/actions/runs/12828370500/job/35772253406?pr=3723
I think your suggestion is also a step towards #3574. |
Will close #3577
Description
This PR transitions us from
hatch
touv
with a solution for the issue I raised in (#3577 (comment)).Note
Don't be alarmed by the +3k additions, it is mostly (89.4%) in
uv.lock
More info
Using
uv
Install
uv
for the first time or run:Install python:
Go to the root of the repo:
cd altair/
Initialize a new virtual env:
Install/update dependencies:
Also see CONTRIBUTING
Task Runner
I've been following astral-sh/uv#5903 pretty closely and after experimenting rolling my own runner - I settled on https://github.com/taskipy/taskipy.
Usage
Works in a similar way to
hatch run ...
, with commands defined in[tool.taskipy.tasks]
.Changes
Composition
Composing tasks uses
"... && ..."
, rather than["...", "..."]
Invoking
Invoking a task:
Alternatives
These were also mentioned in astral-sh/uv#5903.
uv
integration is newnoxfile.py
make
pyproject.toml
hatch
venv
and no support foruv
I chose
taskipy
as:The last point is quite apparent when looking at the changes in (00f353a) vs (https://github.com/vega/altair/blob/ba836abb77b8e1eb8b5d194ed9442916ccdbf2a9/tasks.toml)
Tasks
hatch
config frompyproject.toml
(e8d57cd)hatch clean
hatch build
hatch publish
sync_website.py
(https://github.com/altair-viz/altair-viz.github.io)RELEASING.md
NOTES_FOR_MAINTAINERS.md
README.md
uv pip
interfacelint.yml
docbuild.yml
build.yml
to better utilizeuv
#3725tasks.py
,_tasks.py
(b9e6eb9), (2ed212a)