Skip to content

Conversation

@valentinoli
Copy link
Contributor

@valentinoli valentinoli commented Jul 23, 2025

Get the set of environments by using hatch.core instead of using subprocess.run() to run a hatch CLI command. The stdout from the subprocess can be tricky to parse correctly due to side-effects, e.g. output printed by an environment collector plugin.

...instead of using subprocess.run() to run a hatch CLI command, which can be tricky and error prone to extract the output from
@valentinoli valentinoli marked this pull request as ready for review July 23, 2025 21:21
@juftin
Copy link
Owner

juftin commented Jul 28, 2025

Nice - this is a great solution. Any idea how far back the Project.config.envs API goes back? The project test as far back as 1.7.x

@valentinoli
Copy link
Contributor Author

I see it is present in Hatch 1.6 and maybe even previous versions (did not check)

All the test suites for Hatch 1.7.x+ are passing so that shows everything is fine, doesn't it?

@juftin
Copy link
Owner

juftin commented Jul 29, 2025

This is an interesting one - AFAICT any environment collector plugins also need to be installed into the hatch-pip-compile environment in order for this work, whereas the generic hatch env show --json option will auto-install the plugins itself.

I need to work on reproducing some issues I saw with this

@valentinoli
Copy link
Contributor Author

@juftin Any news? :)

@juftin
Copy link
Owner

juftin commented Aug 22, 2025

@valentinoli sorry for not following up. It looks like the EnvironmentCollector is an issue here - basically invoking hatch env show --json via the CLI will handle installing any required EnvironmentCollector plugin but doing so through the Python API doesn't handle this edge case.

The following script raises an error: UnknownPluginError: Unknown environment collector: mkdocs. (I ran these commands in an isolated docker environment that included git and uv installed - you can use my personal base image if you'd like - docker run --rm -it juftin/juftin:latest). It uses the mkdocs project as an example since they use hatch-pip-compile

cd $(mktemp -d)
git clone https://github.com/mkdocs/mkdocs
cd mkdocs
uv tool run git+https://github.com/valentinoli/hatch-pip-compile@patch-3 docs

whereas the current hatch-pip-compile method handles the bootstrapping of any required plugins

cd $(mktemp -d)
git clone https://github.com/mkdocs/mkdocs
cd mkdocs
uv tool run hatch-pip-compile docs

@juftin
Copy link
Owner

juftin commented Aug 22, 2025

Just spitballing, but maybe there's a method you can call on the Project class that would install any required plugins?

@valentinoli
Copy link
Contributor Author

Ah I see. Since this Project class is undocumented and part of Hatch core (which is prone to change without notice) it might be a bad idea

It is probably safer to stick with #96

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.

2 participants