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

matrix environments with parent environment with different python version raise an error #37

Open
juftin opened this issue Dec 6, 2023 · 1 comment
Labels
documentation Improvements or additions to documentation

Comments

@juftin
Copy link
Owner

juftin commented Dec 6, 2023

This can be problematic in CI/CD where you run hatch run +py={{ matrix.python }} matrix:cov and have hatch.python set to a differing version than your current matrix version

[tool.hatch.envs.default]
pip-compile-constraint = "default"
type = "pip-compile"
python = "3.11"

[tool.hatch.envs.test]
dependencies = [
  "pytest",
  "pytest-cov"
]

[tool.hatch.envs.test.scripts]
cov = [
  "pytest --cov-config=pyproject.toml --cov {args:tests}"
]

[tool.hatch.envs.matrix]
template = "test"

[[tool.hatch.envs.matrix.matrix]]
python = ["3.8", "3.9", "3.10", "3.11", "3.12"]

In the above example you must have the 3.11 environment available to use pip-compile environments from a matrix because default is a constraint environment

AttributeError: 'NoneType' object has no attribute 'executable'

https://github.com/juftin/hatch-pip-compile/actions/runs/7117731072/job/19379122673?pr=28

See how this is handled here:

- name: Set up Python Environment ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Default Python
if: matrix.python != '3.11'
uses: actions/setup-python@v4
with:
python-version: "3.11"

IMO this isn't a bug - but this should probably be documented

@juftin juftin added the documentation Improvements or additions to documentation label Dec 6, 2023
@juftin
Copy link
Owner Author

juftin commented Dec 6, 2023

The way that it's handled in this repo means we generate a lockfile for each Python version - if you wanted one lockfile for all python versions you could handle it like this and forget the hatch matrix entirely:

[tool.hatch.envs.default]
type = "pip-compile"
python = "3.11"

[tool.hatch.envs.test]
template = "test"
dependencies = [
  "pytest",
  "pytest-cov"
]
type = "pip-compile"
pip-compile-constraint = "default"

[tool.hatch.envs.test.scripts]
cov = [
  "pytest --cov-config=pyproject.toml --cov {args:tests}"
]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant