diff --git a/hatch_pip_compile/cli.py b/hatch_pip_compile/cli.py index 3ddffbb..e5ea7ce 100644 --- a/hatch_pip_compile/cli.py +++ b/hatch_pip_compile/cli.py @@ -5,13 +5,14 @@ from __future__ import annotations import dataclasses -import json import os import subprocess +from pathlib import Path from typing import Any, Sequence import click import rich.traceback +from hatch.project.core import Project from hatch_pip_compile.__about__ import __application__, __version__ @@ -134,12 +135,10 @@ def _get_supported_environments(cls) -> set[str]: List[str] The name of the environments """ - result = subprocess.run( - args=["hatch", "env", "show", "--json"], - capture_output=True, - check=True, + project = Project( + Path.cwd(), ) - environment_dict: dict[str, Any] = json.loads(result.stdout) + environment_dict = project.config.envs return { key for key, value in environment_dict.items() if value.get("type") == "pip-compile" } diff --git a/tests/test_cli.py b/tests/test_cli.py index e2868e2..21e5d3e 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -39,10 +39,19 @@ def test_cli_no_args_mocked(pip_compile: PipCompileFixture, subprocess_run: Mock runner = CliRunner() with runner.isolated_filesystem(temp_dir=pip_compile.isolation): _ = runner.invoke(cli=cli) - assert subprocess_run.call_count == 1 - subprocess_run.assert_called_once() - subprocess_run.assert_called_with( - args=["hatch", "env", "show", "--json"], capture_output=True, check=True + subprocess_run.assert_called_once_with( + args=[ + "hatch", + "env", + "run", + "--env", + "default", + "--", + "python", + "--version", + ], + capture_output=True, + check=False, )