Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions hatch_pip_compile/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__

Expand Down Expand Up @@ -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"
}
Expand Down
17 changes: 13 additions & 4 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)


Expand Down