From c0f85cd1d1676f5fcdfda337d4990e24e93a9c39 Mon Sep 17 00:00:00 2001 From: Dan Redding <125183946+dangotbanned@users.noreply.github.com> Date: Thu, 4 Jul 2024 16:22:24 +0100 Subject: [PATCH 1/2] docs: Update `hatch` guidance (#3461) * docs: Update references to `hatch` commands These now use the dedicated `hatch-test` environment https://hatch.pypa.io/latest/tutorials/testing/overview/ * docs: adds two testing sub-sections in `CONTRIBUTING.md` Related: - https://github.com/vega/altair/pull/3452#issuecomment-2198620502 - https://github.com/vega/altair/pull/3452#issuecomment-2198661052 * docs: fix missing closing parenthesis --- CONTRIBUTING.md | 32 ++++++++++++++++++++++++++++---- NOTES_FOR_MAINTAINERS.md | 10 ++++++---- README.md | 4 ++-- tests/test_toplevel.py | 2 +- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 2e573cce8..4471f6e84 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -56,7 +56,11 @@ With this branch checked-out, make the desired changes to the package. A large part of Altair's code base is automatically generated. After you have made your manual changes, make sure to run the following to see if there are any changes -to the automatically generated files: `python tools/generate_schema_wrapper.py`. +to the automatically generated files: + +```bash +hatch run generate-schema-wrapper +``` For information on how to update the Vega-Lite version that Altair uses, please read [the maintainers' notes](NOTES_FOR_MAINTAINERS.md). @@ -67,8 +71,8 @@ Before suggesting your contributing your changing to the main Altair repository, it is recommended that you run the Altair test suite, which includes a number of tests to validate the correctness of your code: -```cmd -hatch run test +```bash +hatch test ``` @@ -78,6 +82,26 @@ This also runs the [`ruff`](https://ruff.rs/) linter and formatter as well as [` Study the output of any failed tests and try to fix the issues before proceeding to the next section. +#### Failures on specific python version(s) +By default, `hatch test` will run the test suite against the currently active python version. Two useful variants for debugging failures that only appear *after* you've submitted your PR: + +```bash +# Test all environments in the matrix +hatch test --all +# The Python versions to test +hatch test --python 3.8 +``` + +See [hatch test](https://hatch.pypa.io/latest/cli/reference/#hatch-test) docs for other options. + +#### Changes to `__all__` +If `test_completeness_of__all__` fails, you may need to run: + +```bash +hatch run update-init-file +``` +However, this test usually indicates *unintentional* addition(s) to the top-level `alt.` namespace that will need resolving first. + ### Creating a Pull Request When you are happy with your changes, you can commit them to your branch by running @@ -187,7 +211,7 @@ The specific commands for each step depend on your operating system. Make sure you execute the following commands from the root dir of altair and have [`hatch`](https://hatch.pypa.io/) installed in your local environment. - For MacOS and Linux, run the following commands in your terminal: -```cmd +```bash hatch run doc:clean-all hatch run doc:build-html hatch run doc:serve diff --git a/NOTES_FOR_MAINTAINERS.md b/NOTES_FOR_MAINTAINERS.md index 82a0ac8f5..27ce05a46 100644 --- a/NOTES_FOR_MAINTAINERS.md +++ b/NOTES_FOR_MAINTAINERS.md @@ -10,7 +10,7 @@ All the files within these directories are created automatically by running the following script from the root of the repository: ```bash -$ hatch run python tools/generate_schema_wrapper.py +hatch run generate-schema-wrapper ``` This script does a couple things: @@ -36,12 +36,14 @@ changing the ``SCHEMA_VERSION`` definition within This will update all of the automatically-generated files in the ``schema`` directory for each version, but please note that it will *not* update other pieces (for example, the core of the Altair API, including methods and -doc strings within ``altair/vegalite/v5/api.py``. +doc strings within ``altair/vegalite/v5/api.py``). These additional methods have fairly good test coverage, so running the test suite should identify any inconsistencies: + +```bash +hatch test ``` -hatch run test -``` + Generally, minor version updates (e.g. Vega-Lite 2.3->2.4) have been relatively painless, maybe requiring the addition of a few chart methods or modification of some docstrings. diff --git a/README.md b/README.md index e426770a9..0e14e8826 100644 --- a/README.md +++ b/README.md @@ -117,8 +117,8 @@ You can find the instructions on how to install the package for development in [ To run the tests and linters, use -``` -hatch run test +```bash +hatch test ``` For information on how to contribute your developments back to the Vega-Altair repository, see diff --git a/tests/test_toplevel.py b/tests/test_toplevel.py index 9d31c958d..2fb583c91 100644 --- a/tests/test_toplevel.py +++ b/tests/test_toplevel.py @@ -8,5 +8,5 @@ def test_completeness_of__all__(): # If the assert statement fails below, there are probably either new objects # in the top-level Altair namespace or some were removed. - # In that case, run tools/update_init_file.py to update __all__ + # In that case, run `hatch run update-init-file` to update __all__ assert alt.__all__ == relevant_attributes From ca6ae153efeb804b3931fd289071b3d6580f4067 Mon Sep 17 00:00:00 2001 From: Marco Edward Gorelli Date: Sun, 7 Jul 2024 22:07:21 +0100 Subject: [PATCH 2/2] chore: fixup ruff-mypy CI job due to Ruff change (#3463) --- pyproject.toml | 2 +- tests/utils/test_compiler.py | 2 +- tests/utils/test_core.py | 2 +- tests/utils/test_html.py | 2 +- tests/utils/test_mimebundle.py | 4 ++-- tests/utils/test_schemapi.py | 2 +- tests/vegalite/test_common.py | 2 +- tests/vegalite/v5/test_api.py | 2 +- tests/vegalite/v5/test_data.py | 2 +- tests/vegalite/v5/test_renderers.py | 2 +- tests/vegalite/v5/test_theme.py | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 3ddaa278b..2b9dc55f0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -66,7 +66,7 @@ all = [ ] dev = [ "hatch", - "ruff>=0.3.0", + "ruff>=0.5.1", "ipython", "pytest", "pytest-cov", diff --git a/tests/utils/test_compiler.py b/tests/utils/test_compiler.py index 79fc5fed1..0840da4a8 100644 --- a/tests/utils/test_compiler.py +++ b/tests/utils/test_compiler.py @@ -8,7 +8,7 @@ vlc = None -@pytest.fixture() +@pytest.fixture def chart(): return ( Chart("cars.json") diff --git a/tests/utils/test_core.py b/tests/utils/test_core.py index e127885d8..8327d3afe 100644 --- a/tests/utils/test_core.py +++ b/tests/utils/test_core.py @@ -249,7 +249,7 @@ def test_update_nested(): assert output == output2 -@pytest.fixture() +@pytest.fixture def channels(): channels = types.ModuleType("channels") exec(FAKE_CHANNELS_MODULE, channels.__dict__) diff --git a/tests/utils/test_html.py b/tests/utils/test_html.py index faee7b4c8..1ce63445f 100644 --- a/tests/utils/test_html.py +++ b/tests/utils/test_html.py @@ -3,7 +3,7 @@ from altair.utils.html import spec_to_html -@pytest.fixture() +@pytest.fixture def spec(): return { "data": {"url": "data.json"}, diff --git a/tests/utils/test_mimebundle.py b/tests/utils/test_mimebundle.py index a7ab352b0..1d7130f18 100644 --- a/tests/utils/test_mimebundle.py +++ b/tests/utils/test_mimebundle.py @@ -15,7 +15,7 @@ vf = None -@pytest.fixture() +@pytest.fixture def vegalite_spec(): return { "$schema": "https://vega.github.io/schema/vega-lite/v5.json", @@ -41,7 +41,7 @@ def vegalite_spec(): } -@pytest.fixture() +@pytest.fixture def vega_spec(): return { "$schema": "https://vega.github.io/schema/vega/v5.json", diff --git a/tests/utils/test_schemapi.py b/tests/utils/test_schemapi.py index 2fafa43a8..b8af99cc3 100644 --- a/tests/utils/test_schemapi.py +++ b/tests/utils/test_schemapi.py @@ -288,7 +288,7 @@ def test_schema_validator_selection(): Draft6Schema.from_dict(dct) -@pytest.fixture() +@pytest.fixture def dct(): return { "a": {"foo": "bar"}, diff --git a/tests/vegalite/test_common.py b/tests/vegalite/test_common.py index ca99e942a..2c043f47f 100644 --- a/tests/vegalite/test_common.py +++ b/tests/vegalite/test_common.py @@ -7,7 +7,7 @@ from altair.vegalite import v5 -@pytest.fixture() +@pytest.fixture def basic_spec(): return { "data": {"url": "data.csv"}, diff --git a/tests/vegalite/v5/test_api.py b/tests/vegalite/v5/test_api.py index 556bda631..a7197e0b1 100644 --- a/tests/vegalite/v5/test_api.py +++ b/tests/vegalite/v5/test_api.py @@ -64,7 +64,7 @@ def _make_chart_type(chart_type): raise ValueError(msg) -@pytest.fixture() +@pytest.fixture def basic_chart(): data = pd.DataFrame( { diff --git a/tests/vegalite/v5/test_data.py b/tests/vegalite/v5/test_data.py index a2af707fa..5603912f8 100644 --- a/tests/vegalite/v5/test_data.py +++ b/tests/vegalite/v5/test_data.py @@ -6,7 +6,7 @@ from altair.vegalite.v5 import data as alt -@pytest.fixture() +@pytest.fixture def sample_data(): return pd.DataFrame({"x": range(10), "y": range(10)}) diff --git a/tests/vegalite/v5/test_renderers.py b/tests/vegalite/v5/test_renderers.py index a20de1503..b84aa9796 100644 --- a/tests/vegalite/v5/test_renderers.py +++ b/tests/vegalite/v5/test_renderers.py @@ -19,7 +19,7 @@ anywidget = None # type: ignore -@pytest.fixture() +@pytest.fixture def chart(): return alt.Chart("data.csv").mark_point() diff --git a/tests/vegalite/v5/test_theme.py b/tests/vegalite/v5/test_theme.py index 64bb9cf28..0eab5546d 100644 --- a/tests/vegalite/v5/test_theme.py +++ b/tests/vegalite/v5/test_theme.py @@ -4,7 +4,7 @@ from altair.vegalite.v5.theme import VEGA_THEMES -@pytest.fixture() +@pytest.fixture def chart(): return alt.Chart("data.csv").mark_bar().encode(x="x:Q")