Skip to content

Use hatch matrix to test pre-release dependencies - #386

Closed
grst wants to merge 6 commits into
mainfrom
hatch-pre-matrix
Closed

grst wants to merge 6 commits into
mainfrom
hatch-pre-matrix

Conversation

@grst

@grst grst commented Apr 8, 2025

Copy link
Copy Markdown
Collaborator

Close #379

@github-actions

github-actions Bot commented Apr 8, 2025

Copy link
Copy Markdown

A PR has been generated to the instance repo:
scverse/cookiecutter-scverse-instance#192

You can check out the PR to preview your changes
in an instance of the cookiecutter template. The PR will be kept in sync with
this PR automatically.

run: uvx hatch test --cover --python ${{ matrix.python }} --include deps=${{ matrix.deps }}
- name: generate coverage report
run: uvx hatch run hatch-test.py${{ matrix.python }}:coverage xml
run: uvx hatch run hatch-test.py${{ matrix.python }}-${{ matrix.deps }}:coverage xml

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is there a better way to get the env name? Basically this action breaks whenever someone makes changes to the test matrix in pyproject.toml.

The alternative would be to just run uvx coverage, but @flying-sheep you had concerns about edge cases where that could break?

@flying-sheep flying-sheep Apr 8, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah, see https://hatch.pypa.io/1.13/cli/reference/#hatch-run

  1. HATCH_ENV, but idk if that also makes hatch test select this one

  2. The + selection syntax, maybe like this? I’d try locally first though

    Suggested change
    run: uvx hatch run hatch-test.py${{ matrix.python }}-${{ matrix.deps }}:coverage xml
    run: uvx hatch run +py=${{ matrix.python }} +deps=${{ matrix.deps }} hatch-test:coverage xml

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

This fails for me with Variable selection is unsupported for non-matrix environments: hatch-test

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think #390 is the most elegant way here anyway.

hatch env create ${{ matrix.env_name }}
hatch run ${{ matrix.env_name }}:run-cov
hatch run ${{ matrix.env_name }}:coverage xml


[[tool.hatch.envs.hatch-test.matrix]]
deps = [ "stable", "pre" ]
python = [ "3.10", "3.13" ]

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I had the impression that when overriding the default matrix, I also need to manually specify which python versions to test here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you’re right.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Right now we are only testing pre-release deps for the latest python. This matrix would test it for any python specified.

Is this what we want, or is there a way to keep the current behaviour with hatch?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the current behavior is sufficient. The idea is that we’re testing the bleeding edge, and one job is sufficient for that.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

ok, do you know how to set that up using the hatch-test.matrix?

@flying-sheep flying-sheep Apr 8, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I asked people on discord to please answer this: pypa/hatch#1923

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I couldn't make it work, see also my comment in the discussion! If you have an idea, please go for it!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

… and 15 minutes after this comment, ofek solved it:

[[tool.hatch.envs.hatch-test.matrix]]
deps = ["stable", "pre"]
python = ["3.13"]

[[tool.hatch.envs.hatch-test.matrix]]
deps = ["stable"]
python = ["3.10", "3.11", "3.12"]

[tool.hatch.envs.hatch-test.overrides]
matrix.deps.env-vars = [
  { key = "UV_PRERELEASE", value = "allow", if = [ "pre" ] },
]

Comment on lines 28 to 37
- os: ubuntu-latest
python: "3.10"
deps: stable
- os: ubuntu-latest
python: "3.12"
python: "3.13"
deps: stable
- os: ubuntu-latest
python: "3.12"
pip-flags: "--pre"
python: "3.13"
deps: pre
name: PRE-RELEASE DEPENDENCIES

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To keep that in sync with pyproject.toml, maybe we could get this from hatch env show --json?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

good idea!

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

See #390 for an attempt

@grst
grst requested a review from flying-sheep April 8, 2025 07:01
@grst

grst commented Apr 8, 2025

Copy link
Copy Markdown
Collaborator Author

Not super happy with the changes. I feel things are getting complicated. Alternatively we could just set the UV_PRERELEASE variable in CI directly.

@flying-sheep

flying-sheep commented Apr 8, 2025 •

Copy link
Copy Markdown
Member

Not super happy with the changes. I feel things are getting complicated.

I think the complexity matches exactly what we’re doing here. So for people who want to test with pre-releases, exposing all that makes sense.

Alternatively we could just set the UV_PRERELEASE variable in CI directly.

Which would mean that we make things more complicated for users who see that job breaking and don’t know how run tests in an environment like that locally. hatch test won’t reinstall when you set that env var, you’d have to hatch env remove/prune.


So IMHO the question is: do we want users to have the pre-release job or not? If yes, as said, I feel like the configuration complexity matches the complexity of what’s being done, which isn’t a bad thing.

@grst

grst commented Apr 8, 2025

Copy link
Copy Markdown
Collaborator Author

So IMHO the question is: do we want users to have the pre-release job or not?

Ideally, yes. It could be useful for debugging locally and apart from that I don't think there's any good reason for the CI doing different things than the local test job.

@flying-sheep

Copy link
Copy Markdown
Member

Oh, I meant in general. I fully agree with what you said, so the only alternative to the complexity added here is not having pre-release jobs at all.

@grst

grst commented Apr 8, 2025

Copy link
Copy Markdown
Collaborator Author

Yeah, let's add it to hatch.

@flying-sheep

Copy link
Copy Markdown
Member

Should we merge #390 first and then redo this PR based on it?

@grst grst mentioned this pull request Apr 14, 2025
@grst

grst commented Apr 18, 2025

Copy link
Copy Markdown
Collaborator Author

Better to start from scratch

@grst grst closed this Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pre-release dependency test is broken

2 participants