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

build: Migrate from hatch to uv #3723

Draft
wants to merge 31 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
5819a2e
ci: remove unused `--parents` option
dangotbanned Dec 24, 2024
ddc8358
ci: replace `sync_website.sh` with `.py`
dangotbanned Dec 24, 2024
6ebc0ee
ci(DRAFT): migrate `hatch` scripts to hybrid `tasks.py` runner
dangotbanned Dec 29, 2024
fbc5a0f
ci: switch `Tasks` runner to `"uv"`
dangotbanned Dec 29, 2024
f614e4f
build(uv): Generate `uv.lock`
dangotbanned Dec 29, 2024
0fa8ecc
refactor: Move `PYTEST_ARGS` -> `tool.pytest.ini_options.addopts`
dangotbanned Dec 29, 2024
dca3f0d
fix: Add recursive guard during `Tasks._expand`
dangotbanned Dec 29, 2024
8bf774f
ci: add `export-tasks` and update `tasks.toml`
dangotbanned Dec 29, 2024
3513259
ci: try fixing `anywidget` import error
dangotbanned Dec 29, 2024
c160c4c
feat: Improve `*_cmd` functions
dangotbanned Dec 29, 2024
53bc298
refactor: reduce overloading of term `"cmd"`
dangotbanned Dec 29, 2024
8323881
feat: adds `cmd` helper class
dangotbanned Dec 29, 2024
1fd5790
chore: re-enable `tasks.py` export
dangotbanned Dec 29, 2024
cd9ccf9
docs: fix incorrect import path
dangotbanned Dec 29, 2024
ee426d9
Merge branch 'main' into migrate-hatch-scripts
dangotbanned Dec 29, 2024
74c10bb
ci: Prefix doc-related tasks
dangotbanned Dec 30, 2024
9900aa1
ci: Adds `clean`, `build`, `publish` tasks
dangotbanned Dec 30, 2024
ba836ab
ci: disable hard-coded no-op for `tools/sync_website.py`
dangotbanned Dec 30, 2024
404bb26
fix(DRAFT): resolve some `sync_website.py` issues
dangotbanned Dec 30, 2024
9285871
ci: Add different no-op in `sync_website.py`
dangotbanned Dec 30, 2024
6e792a1
fix: Resolve typo in `hatch` extras check
dangotbanned Dec 31, 2024
e8d57cd
ci: Remove all unused `hatch` config
dangotbanned Dec 31, 2024
1c0310b
refactor: Use `tomlkit.toml_file_TOMLFile` directly
dangotbanned Dec 31, 2024
fc6496f
ci: Support updating `tasks` table in-place
dangotbanned Dec 31, 2024
aaca9bc
Merge branch 'main' into migrate-hatch-scripts
dangotbanned Jan 1, 2025
9150935
Merge remote-tracking branch 'upstream/main' into migrate-hatch-scripts
dangotbanned Jan 2, 2025
f240884
Merge remote-tracking branch 'upstream/main' into migrate-hatch-scripts
dangotbanned Jan 2, 2025
b61dc3c
Merge remote-tracking branch 'upstream/main' into migrate-hatch-scripts
dangotbanned Jan 6, 2025
f3a7f62
ci(uv): sync dependencies
dangotbanned Jan 6, 2025
e43e464
chore(typing): Ignore `mypy` inference
dangotbanned Jan 6, 2025
00f353a
ci: Port to `taskipy`
dangotbanned Jan 7, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ jobs:
fi
- name: Test with pytest
run: |
uv run pytest --pyargs --numprocesses=logical --doctest-modules tests
uv run pytest --pyargs --numprocesses=logical --doctest-modules --doctest-ignore-import-errors tests
- name: Validate Vega-Lite schema
run: |
# We install all 'format' dependencies of jsonschema as check-jsonschema
Expand Down
27 changes: 0 additions & 27 deletions doc/sync_website.sh

This file was deleted.

134 changes: 43 additions & 91 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ dev = [
"types-setuptools",
"geopandas",
"polars>=0.20.3",
"tomli; python_version<\"3.11\""
"taskipy>=1.14.1",
"tomli>=2.2.1",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had to make tomli available on all versions, since taskipy imports it unconditionally.

Originally added with a runtime version gate block in dd0980b (#3720)

]
doc = [
"sphinx",
Expand All @@ -106,101 +107,20 @@ vega-datasets = "v2.11.0" # https://github.com/vega/vega-datasets
vega-embed = "6" # https://github.com/vega/vega-embed
vega-lite = "v5.20.1" # https://github.com/vega/vega-lite

[tool.hatch.version]
path = "altair/__init__.py"
[tool.hatch]
build = { include = ["/altair"], artifacts = ["altair/jupyter/js/index.js"] }
metadata = { allow-direct-references = true }
version = { path = "altair/__init__.py" }

[tool.hatch.metadata]
allow-direct-references = true

[tool.hatch.build]
include = ["/altair"]
artifacts = ["altair/jupyter/js/index.js"]

[tool.hatch.envs.default]
features = ["all", "dev"]
[tool.hatch.envs]
# https://hatch.pypa.io/latest/how-to/environment/select-installer/#enabling-uv
installer = "uv"

[tool.hatch.envs.default.scripts]
generate-schema-wrapper = [
"mypy tools",
"python tools/generate_schema_wrapper.py",
"test"
]
test = [
"ruff check .",
"ruff format --diff --check .",
"mypy altair tests",
"python -m pytest --pyargs --numprocesses=logical --doctest-modules tests altair tools",
]
test-coverage = "python -m pytest --pyargs --doctest-modules --cov=altair --cov-report term altair"
test-coverage-html = "python -m pytest --pyargs --doctest-modules --cov=altair --cov-report html altair"
update-init-file = [
"python tools/update_init_file.py",
"ruff check .",
"ruff format .",
]
test-fast = [
"ruff check .", "ruff format .",
"pytest -p no:randomly -n logical --numprocesses=logical --doctest-modules tests altair tools -m \"not slow\" {args}"
]
test-slow = [
"ruff check .", "ruff format .",
"pytest -p no:randomly -n logical --numprocesses=logical --doctest-modules tests altair tools -m \"slow\" {args}"
]
default = { features = ["all", "dev"], installer = "uv" }
doc = { features = ["all", "dev", "doc"] }

[tool.hatch.envs.hatch-test]
# https://hatch.pypa.io/latest/tutorials/testing/overview/
features = ["all", "dev", "doc"]
# https://pytest-xdist.readthedocs.io/en/latest/distribution.html#running-tests-across-multiple-cpus
default-args = ["--numprocesses=logical","--doctest-modules", "tests", "altair", "tools"]
parallel = true
[[tool.hatch.envs.hatch-test.matrix]]
python = ["3.9", "3.10", "3.11", "3.12", "3.13"]
[tool.hatch.envs.hatch-test.scripts]
run = [
"ruff check .",
"ruff format --diff --check .",
"mypy altair tests",
"pytest{env:HATCH_TEST_ARGS:} {args}"
]
run-cov = "coverage run -m pytest{env:HATCH_TEST_ARGS:} {args}"
cov-combine = "coverage combine"
cov-report = "coverage report"

[tool.hatch.envs.doc]
features = ["all", "dev", "doc"]

[tool.hatch.envs.doc.scripts]
clean = "rm -rf doc/_build"
clean-generated = ["rm -rf doc/user_guide/generated", "rm -rf doc/gallery"]
clean-all = ["clean", "clean-generated", "rm -rf doc/_images"]
clean-win = "if exist doc\\_build rd /s /q doc\\_build"
clean-generated-win = [
"if exist doc\\user_guide\\generated rd /s /q doc\\user_guide\\generated",
"if exist doc\\gallery rd /s /q doc\\gallery",
]
clean-all-win = [
"clean-win",
"clean-generated-win",
"if exist doc\\_images rd /s /q doc\\_images",
]
build-html = [
"mkdir -p doc/_images",
"sphinx-build -b html -d doc/_build/doctrees doc doc/_build/html",
]
build-html-win = [
"if not exist doc\\_images md doc\\_images",
"sphinx-build -b html -d doc\\_build\\doctrees doc doc\\_build\\html",
]
doctest = "sphinx-build -b doctest -d doc/_build/doctrees doc doc/_build/doctest"
coverage = "sphinx-build -b coverage -d doc/_build/doctrees doc doc/_build/coverage"
serve = "(cd doc/_build/html && python -m http.server)"
publish-clean-build = [
"clean-all",
"build-html",
"(cd doc && bash sync_website.sh)",
]
matrix = [{ python = ["3.9", "3.10", "3.11", "3.12", "3.13"] }]

[tool.ruff]
target-version = "py39"
Expand Down Expand Up @@ -432,12 +352,44 @@ line-ending = "lf"
docstring-code-format = true
docstring-code-line-length = 88

[tool.taskipy.settings]
cwd = "."

[tool.taskipy.tasks]
lint = "ruff check"
format = "ruff format --diff --check"
ruff-fix = "task lint && ruff format"
type-check = "mypy altair tests"

pytest = "pytest"
test = "task lint && task format && task type-check && task pytest"
test-fast = "task ruff-fix && pytest -m \"not slow\""
test-slow = "task ruff-fix && pytest -m \"slow\""

generate-schema-wrapper = "mypy tools && python tools/generate_schema_wrapper.py && task test"
update-init-file = "python tools/update_init_file.py && task ruff-fix"

doc-clean = "python -c \"import shutil;shutil.rmtree('doc/_build', ignore_errors=True)\""
doc-clean-generated = "python -c \"import shutil;shutil.rmtree('doc/user_guide/generated', ignore_errors=True);shutil.rmtree('doc/gallery', ignore_errors=True)\""
doc-clean-images = "python -c \"import shutil;shutil.rmtree('doc/_images', ignore_errors=True)\""
doc-clean-all = "task doc-clean && task doc-clean-generated && task doc-clean-images"
doc-mkdir = """python -c \"from pathlib import Path;Path('doc/_images').mkdir(parents=True, exist_ok=True)\""""
doc-build-html = "task doc-mkdir && sphinx-build -b html -d doc/_build/doctrees doc doc/_build/html"
doc-clean-build = "task doc-clean-all && task doc-build-html"
doc-serve = "python -m http.server --bind \"127.0.0.1\" --directory doc/_build/html 8000"
doc-publish = "python tools/sync_website.py"
doc-publish-clean-build = "task doc-clean-build && task doc-publish"

clean = "python -c \"import shutil;shutil.rmtree('dist', ignore_errors=True)\""
build = "task clean && uv build"
publish = "task build && uv publish"

[tool.pytest.ini_options]
# Pytest does not need to search these folders for test functions.
# They contain examples which are being executed by the
# test_examples tests.
norecursedirs = ["tests/examples_arguments_syntax", "tests/examples_methods_syntax"]
addopts = ["--numprocesses=logical"]
addopts = ["--numprocesses=logical", "--doctest-modules", "tests", "altair", "tools"]
# https://docs.pytest.org/en/stable/how-to/mark.html#registering-marks
markers = [
"slow: Label tests as slow (deselect with '-m \"not slow\"')"
Expand Down
54 changes: 54 additions & 0 deletions tasks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
[tool.altair.tasks]
lint = ["ruff check"]
format = ["ruff format --diff --check"]
ruff-fix = ["ruff check", "ruff format"]
type-check = ["mypy altair tests"]
pytest = ["pytest"]
test = ["lint", "format", "type-check", "pytest"]
test-fast = ["ruff-fix", "pytest -m \"not slow\""]
test-slow = ["ruff-fix", "pytest -m \"slow\""]
generate-schema-wrapper = [
"mypy tools",
"python tools/generate_schema_wrapper.py",
"test",
]
update-init-file = ["python tools/update_init_file.py", "ruff-fix"]
doc-clean = [
"python -c \"import shutil;shutil.rmtree('doc/_build', ignore_errors=True)\"",
]
doc-clean-generated = [
"python -c \"import shutil;shutil.rmtree('doc/user_guide/generated', ignore_errors=True)\"",
"python -c \"import shutil;shutil.rmtree('doc/gallery', ignore_errors=True)\"",
]
doc-clean-all = [
"doc-clean",
"doc-clean-generated",
"python -c \"import shutil;shutil.rmtree('doc/_images', ignore_errors=True)\"",
]
doc-serve = [
"python -m http.server --bind \"127.0.0.1\" --directory doc/_build/html 8000",
]
doc-publish = ["python tools/sync_website.py"]
clean = [
"python -c \"import shutil;shutil.rmtree('dist', ignore_errors=True)\"",
]
build = ["clean", "uv build"]
publish = ["build", "uv publish"]
export-tasks = [
"python -c \"from tools.tasks import app;app.to_path('tasks.toml')\"",
]

[tool.altair.tasks.doc-build-html]
commands = [
"python -c \"from pathlib import Path;Path('doc/_images').mkdir(parents=True, exist_ok=True)\"",
"sphinx-build -b html -d doc/_build/doctrees doc doc/_build/html",
]
extras = ["doc"]

[tool.altair.tasks.doc-clean-build]
commands = ["doc-clean-all", "doc-build-html"]
extras = ["doc"]

[tool.altair.tasks.doc-publish-clean-build]
commands = ["doc-clean-build", "doc-publish"]
extras = ["doc"]
2 changes: 2 additions & 0 deletions tools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
generate_schema_wrapper,
markup,
schemapi,
tasks,
update_init_file,
versioning,
)
Expand All @@ -12,6 +13,7 @@
"generate_schema_wrapper",
"markup",
"schemapi",
"tasks",
"update_init_file",
"versioning",
]
Loading
Loading