Skip to content

Commit 367993e

Browse files
authored
refactor: Centralize Vega project versioning (#3720)
1 parent f0de7f2 commit 367993e

File tree

9 files changed

+388
-57
lines changed

9 files changed

+388
-57
lines changed

NOTES_FOR_MAINTAINERS.md

Lines changed: 49 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,56 @@ The script output is designed to be deterministic; if the vega-lite version
2727
is not changed, then running the script should overwrite the schema wrappers
2828
with identical copies.
2929

30-
## Updating the Vega-Lite version
30+
## Updating Vega versions
31+
All versions are maintained in [pyproject.toml](pyproject.toml).
3132

32-
The vega & vega-lite versions for the Python code can be updated by manually
33-
changing the ``SCHEMA_VERSION`` definition within
34-
``tools/generate_schema_wrapper.py``, and then re-running the script.
33+
### Python Packages
34+
35+
Projects which publish a package to PyPI are listed with a version bound in one of the following tables:
36+
37+
- [`project.dependencies`](https://packaging.python.org/en/latest/specifications/pyproject-toml/#dependencies-optional-dependencies): Published dependencies.
38+
- [`project.optional-dependencies`](https://packaging.python.org/en/latest/specifications/pyproject-toml/#dependencies-optional-dependencies): Published optional dependencies, or "extras".
39+
- [`dependency-groups`](https://peps.python.org/pep-0735/): Local dependencies for development.
40+
41+
> [!NOTE]
42+
> All are currently declared in sub-tables of `project.optional-dependencies`.
43+
44+
The lower version bounds defined here are reused for [altair/utils/_importers.py](altair/utils/_importers.py).
45+
46+
#### `vl-convert`
47+
48+
We need to ensure that [vl-convert](https://github.com/vega/vl-convert) includes support for the new Vega-Lite version.
49+
Check the [vl-convert releases](https://github.com/vega/vl-convert/releases) to find the minimum
50+
version of `vl-convert` that includes support for the desired version of Vega-Lite (and [open
51+
an issue](https://github.com/vega/vl-convert/issues) if this version hasn't been
52+
included in a released yet).
53+
54+
### Javascript/other
55+
56+
Additional version constraints, including for [`Vega-Lite`](https://github.com/vega/vega-lite) itself are declared in `[tool.altair.vega]`.
57+
58+
Whereas the [previous dependencies](#python-packages) are used primarily at *install-time*; this group is embedded into `altair` for use at *runtime* or when [generating the python code](#auto-generating-the-python-code):
59+
60+
```toml
61+
[tool.altair.vega]
62+
vega-datasets = "..." # https://github.com/vega/vega-datasets
63+
vega-embed = "..." # https://github.com/vega/vega-embed
64+
vega-lite = "..." # https://github.com/vega/vega-lite
65+
```
66+
67+
Some examples of where these propagate to:
68+
- [altair/jupyter/js/index.js](altair/jupyter/js/index.js)
69+
- [altair/utils/_importers.py](altair/utils/_importers.py)
70+
- [tools/generate_schema_wrapper.py](tools/generate_schema_wrapper.py)
71+
- [tools/versioning.py](tools/versioning.py)
72+
- [altair/utils/schemapi.py](https://github.com/vega/altair/blob/0e23fd33e9a755bab0ef73a856340c48c14897e6/altair/utils/schemapi.py#L1619-L1640)
73+
74+
> [!IMPORTANT]
75+
> When updating **any** of these versions, be sure to [re-generate the python code](#auto-generating-the-python-code).
76+
77+
#### Updating the Vega-Lite version
78+
79+
The Vega-Lite version for the Python code propagates to `tools.generate_schema_wrapper.SCHEMA_VERSION`.
3580

3681
This will update all of the automatically-generated files in the ``schema``
3782
directory for each version, but please note that it will *not* update other
@@ -50,30 +95,6 @@ of some docstrings.
5095
Major version updates (e.g. Vega-Lite 1.X->2.X) have required substantial
5196
rewrites, because the internal structure of the schema changed appreciably.
5297

53-
### Updating the Vega-Lite in JupyterChart
54-
To update the Vega-Lite version used in JupyterChart, update the version in the
55-
esm.sh URL in `altair/jupyter/js/index.js`.
56-
57-
For example, to update to Vega-Lite 5.15.1, Vega 5 and Vega-Embed 6, the URL
58-
should be:
59-
60-
```javascript
61-
import embed from "https://esm.sh/vega-embed@6?deps=vega@5&[email protected]";
62-
```
63-
64-
### Updating vl-convert version bound
65-
66-
When updating the version of Vega-Lite, it's important to ensure that
67-
[vl-convert](https://github.com/vega/vl-convert) includes support for the new Vega-Lite version.
68-
Check the [vl-convert releases](https://github.com/vega/vl-convert/releases) to find the minimum
69-
version of vl-convert that includes support for the desired version of Vega-Lite (and [open
70-
an issue](https://github.com/vega/vl-convert/issues) if this version hasn't been
71-
included in a released yet.). Update the vl-convert version check in `altair/utils/_importers.py`
72-
with the new minimum required version of vl-convert.
73-
74-
Also, the version bound of the `vl-convert-python` package should be updated in the
75-
`[project.optional-dependencies]/all` dependency group in `pyproject.toml`.
76-
7798
## Releasing the Package
7899

79100
To cut a new release of Altair, follow the steps outlined in

RELEASING.md

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
1. Make sure to have an environment set up with `hatch` installed. See `CONTRIBUTING.md`.
1+
1. Check all [Vega project](https://github.com/orgs/vega/repositories?type=source) versions are up-to-date. See [NOTES_FOR_MAINTAINERS.md](NOTES_FOR_MAINTAINERS.md)
2+
3+
2. Make sure to have an environment set up with `hatch` installed. See [CONTRIBUTING.md](CONTRIBUTING.md).
24
Remove any existing environments managed by `hatch` so that it will create new ones
35
with the latest dependencies when executing the commands further below:
46

57
hatch env prune
68

7-
2. Make certain your branch is in sync with head, and that you have no uncommitted modifications. If you work on a fork, replace `origin` with `upstream`:
9+
3. Make certain your branch is in sync with head, and that you have no uncommitted modifications. If you work on a fork, replace `origin` with `upstream`:
810

911
git checkout main
1012
git pull origin main
1113
git status # Should show "nothing to commit, working tree clean"
1214

13-
3. Do a clean doc build:
15+
4. Do a clean doc build:
1416

1517
hatch run doc:clean-all
1618
hatch run doc:build-html
@@ -19,62 +21,62 @@
1921
Navigate to http://localhost:8000 and ensure it looks OK (particularly
2022
do a visual scan of the gallery thumbnails).
2123

22-
4. Create a new release branch:
24+
5. Create a new release branch:
2325

2426
git switch -c version_5.0.0
2527

26-
5. Update version to, e.g. 5.0.0:
28+
6. Update version to, e.g. 5.0.0:
2729

2830
- in ``altair/__init__.py``
2931
- in ``doc/conf.py``
3032

31-
6. Commit changes and push:
33+
7. Commit changes and push:
3234

3335
git add . -u
3436
git commit -m "chore: Bump version to 5.0.0"
3537
git push
3638

37-
7. Merge release branch into main, make sure that all required checks pass
39+
8. Merge release branch into main, make sure that all required checks pass
3840

39-
8. On main, build source & wheel distributions. If you work on a fork, replace `origin` with `upstream`:
41+
9. On main, build source & wheel distributions. If you work on a fork, replace `origin` with `upstream`:
4042

4143
git switch main
4244
git pull origin main
4345
hatch clean # clean old builds & distributions
4446
hatch build # create a source distribution and universal wheel
4547

46-
9. publish to PyPI (Requires correct PyPI owner permissions):
48+
10. publish to PyPI (Requires correct PyPI owner permissions):
4749

4850
hatch publish
4951

50-
10. build and publish docs (Requires write-access to altair-viz/altair-viz.github.io):
52+
11. build and publish docs (Requires write-access to altair-viz/altair-viz.github.io):
5153

5254
hatch run doc:publish-clean-build
5355

54-
11. On main, tag the release. If you work on a fork, replace `origin` with `upstream`:
56+
12. On main, tag the release. If you work on a fork, replace `origin` with `upstream`:
5557

5658
git tag -a v5.0.0 -m "Version 5.0.0 release"
5759
git push origin v5.0.0
5860

59-
12. Create a new branch:
61+
13. Create a new branch:
6062

6163
git switch -c maint_5.1.0dev
6264

63-
13. Update version and add 'dev' suffix, e.g. 5.1.0dev:
65+
14. Update version and add 'dev' suffix, e.g. 5.1.0dev:
6466

6567
- in ``altair/__init__.py``
6668
- in ``doc/conf.py``
6769

68-
14. Commit changes and push:
70+
15. Commit changes and push:
6971

7072
git add . -u
7173
git commit -m "chore: Bump version to 5.1.0dev"
7274
git push
7375
74-
15. Merge maintenance branch into main
76+
16. Merge maintenance branch into main
7577

76-
16. Double-check that a conda-forge pull request is generated from the updated
78+
17. Double-check that a conda-forge pull request is generated from the updated
7779
pip package by the conda-forge bot (may take up to several hours):
7880
https://github.com/conda-forge/altair-feedstock/pulls
7981

80-
17. Publish a new release in https://github.com/vega/altair/releases/
82+
18. Publish a new release in https://github.com/vega/altair/releases/

altair/utils/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,18 @@
1212
from .deprecation import AltairDeprecationWarning, deprecated, deprecated_warn
1313
from .html import spec_to_html
1414
from .plugin_registry import PluginRegistry
15-
from .schemapi import Optional, SchemaBase, SchemaLike, Undefined, is_undefined
15+
from .schemapi import (
16+
VERSIONS,
17+
Optional,
18+
SchemaBase,
19+
SchemaLike,
20+
Undefined,
21+
is_undefined,
22+
)
1623

1724
__all__ = (
1825
"SHORTHAND_KEYS",
26+
"VERSIONS",
1927
"AltairDeprecationWarning",
2028
"Optional",
2129
"PluginRegistry",

altair/utils/_importers.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55

66
from packaging.version import Version
77

8+
from altair.utils.schemapi import VERSIONS
9+
810
if TYPE_CHECKING:
911
from types import ModuleType
1012

1113

1214
def import_vegafusion() -> ModuleType:
13-
min_version = "1.5.0"
15+
min_version = VERSIONS["vegafusion"]
1416
try:
1517
import vegafusion as vf
1618

@@ -45,7 +47,7 @@ def import_vegafusion() -> ModuleType:
4547

4648

4749
def import_vl_convert() -> ModuleType:
48-
min_version = "1.6.0"
50+
min_version = VERSIONS["vl-convert-python"]
4951
try:
5052
version = importlib_version("vl-convert-python")
5153
if Version(version) < Version(min_version):

altair/utils/schemapi.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,3 +1676,27 @@ def with_property_setters(cls: type[TSchemaBase]) -> type[TSchemaBase]:
16761676
for prop, propschema in schema.get("properties", {}).items():
16771677
setattr(cls, prop, _PropertySetter(prop, propschema))
16781678
return cls
1679+
1680+
1681+
VERSIONS: Mapping[
1682+
Literal[
1683+
"vega-datasets", "vega-embed", "vega-lite", "vegafusion", "vl-convert-python"
1684+
],
1685+
str,
1686+
] = {
1687+
"vega-datasets": "v2.11.0",
1688+
"vega-embed": "6",
1689+
"vega-lite": "v5.20.1",
1690+
"vegafusion": "1.6.6",
1691+
"vl-convert-python": "1.7.0",
1692+
}
1693+
"""
1694+
Version pins for non-``python`` `vega projects`_.
1695+
1696+
Notes
1697+
-----
1698+
When cutting a new release, make sure to update ``[tool.altair.vega]`` in ``pyproject.toml``.
1699+
1700+
.. _vega projects:
1701+
https://github.com/vega
1702+
"""

pyproject.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ dev = [
8484
"types-setuptools",
8585
"geopandas",
8686
"polars>=0.20.3",
87+
"tomli; python_version<\"3.11\""
8788
]
8889
doc = [
8990
"sphinx",
@@ -99,6 +100,12 @@ doc = [
99100
"scipy",
100101
]
101102

103+
[tool.altair.vega]
104+
# Minimum/exact versions, for projects under the `vega` organization
105+
vega-datasets = "v2.11.0" # https://github.com/vega/vega-datasets
106+
vega-embed = "6" # https://github.com/vega/vega-embed
107+
vega-lite = "v5.20.1" # https://github.com/vega/vega-lite
108+
102109
[tool.hatch.version]
103110
path = "altair/__init__.py"
104111

tools/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
markup,
55
schemapi,
66
update_init_file,
7+
versioning,
78
)
89

910
__all__ = [
@@ -12,4 +13,5 @@
1213
"markup",
1314
"schemapi",
1415
"update_init_file",
16+
"versioning",
1517
]

tools/generate_schema_wrapper.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
spell_literal,
4242
)
4343
from tools.vega_expr import write_expr_module
44+
from tools.versioning import VERSIONS
4445

4546
if TYPE_CHECKING:
4647
from collections.abc import Iterable, Iterator
@@ -50,7 +51,7 @@
5051

5152
T = TypeVar("T", bound="str | Iterable[str]")
5253

53-
SCHEMA_VERSION: Final = "v5.20.1"
54+
SCHEMA_VERSION: Final = VERSIONS["vega-lite"]
5455

5556

5657
HEADER_COMMENT = """\
@@ -633,9 +634,8 @@ def copy_schemapi_util() -> None:
633634
destination_fp.open("w", encoding="utf8") as dest,
634635
):
635636
dest.write(HEADER_COMMENT)
636-
dest.writelines(source.readlines())
637-
if sys.platform == "win32":
638-
ruff.format(destination_fp)
637+
dest.writelines(chain(source.readlines(), VERSIONS.iter_inline_literal()))
638+
ruff.format(destination_fp)
639639

640640

641641
def recursive_dict_update(schema: dict, root: dict, def_dict: dict) -> None:
@@ -1390,13 +1390,10 @@ def main() -> None:
13901390
"--skip-download", action="store_true", help="skip downloading schema files"
13911391
)
13921392
args = parser.parse_args()
1393+
VERSIONS.update_all()
13931394
copy_schemapi_util()
13941395
vegalite_main(args.skip_download)
1395-
write_expr_module(
1396-
vlc.get_vega_version(),
1397-
output=EXPR_FILE,
1398-
header=HEADER_COMMENT,
1399-
)
1396+
write_expr_module(VERSIONS.vlc_vega, output=EXPR_FILE, header=HEADER_COMMENT)
14001397

14011398
# The modules below are imported after the generation of the new schema files
14021399
# as these modules import Altair. This allows them to use the new changes

0 commit comments

Comments
 (0)