Skip to content

matrix environment selection with run and env run doesn't work as expected / documented #858

@tobi45

Description

@tobi45

I have a matrix environment defined and want to run a script/command in a subset of all matrix based environments. For that purpose the run command has the + and - options and the env run command the -i and -x options to select a subset of all environments.

With both commands and options it is possible to select a value along one dimension/list, but not along more than one dimension/list.

Should it be possible to select/include values along multiple dimensions/lists?

Environment definition from pyproject.toml:

[tool.hatch.envs.test]
detached = true

[[tool.hatch.envs.test.matrix]]
python = ["3.8", "3.9"]
tensorflow = ["2.12.*", "2.11.*", "2.10.*", "2.9.*"]

[tool.hatch.envs.test.scripts]
test = [ "echo {env_name}" ]

My goal is e. g. to run a script/command in the environment with python 3.8 and tensorflow 2.11.*. Next are my tries with their result. Note that I included runs to show that the * in the value shouldn't be the problem.

  • hatch run +tensorflow=2.11.* test:test
    • works correctly, all python versions: test.py3.8-2.11.*, test.py3.9-2.11.*
  • hatch run +python=3.8 test:test
    • works correctly, all tensorflow versions
  • hatch run +tensorflow=2.11.* +python=3.8 test:test and hatch run +python=3.8 +tensorflow=2.11.* test:test
    • neither python specific nor tensorflow specific, thus all python versions and all tensorflow versions
  • hatch run +python=3.8,tensorflow=2.11.* test:test
    • python specific but not tensorflow specific, thus all tensorflow versions
  • hatch run +tensorflow=2.11.*,python=3.8 test:test
    • tensorflow specific but not python specific, thus all python versions

Then I tried env run:

  • hatch env run -i tensorflow=2.11.* -i python=3.8 test:test
  • hatch env run --env test -i tensorflow=2.11.* -i python=3.8 test
    • neither python specific nor tensorflow specific, thus all python versions and all tensorflow versions
  • hatch env run --env test -i tensorflow=2.11.* test
    • works correctly, all python versions
  • hatch env run --env test -i python=3.8 test
    • works correctly, all tensorflow versions
  • hatch env run --env test -i tensorflow=2.11.* python=3.8 test
    • no error message, no output, just does nothing
  • hatch env run --env test -i tensorflow=2.11.*,python=3.8 test
    • tensorflow specific but not python specific, thus all python versions

The only way I found to run scripts in exactly one matrix based environment, python 3.8 and tensorflow 2.11.*, is without the options -i or + but:

hatch env run --env test.py3.8-2.11.* test

It is unclear to me, if it shouldn't be possible and if the documentation is unclear and the command line parser has a bug or if it should be possible and there is a bug in the selection process and another one in the command line parser / option error handling.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions