Skip to content

Commit

Permalink
🐛 hatch compatibility layer
Browse files Browse the repository at this point in the history
  • Loading branch information
juftin committed Jul 13, 2024
1 parent 3ee5fff commit 28484a4
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions hatch_pip_compile/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from subprocess import CompletedProcess
from typing import Any, ClassVar, Dict, List, Optional, Type, Union

import hatch.cli
from hatch.env.virtual import VirtualEnvironment
from hatch.utils.platform import Platform
from hatchling.dep.core import dependencies_in_sync
Expand Down Expand Up @@ -264,18 +265,22 @@ def get_piptools_environment(self, environment_name: str) -> "PipCompileEnvironm
f"[hatch-pip-compile] The environment {environment_name} does not exist."
)
raise HatchPipCompileError(error_message)
return PipCompileEnvironment(
root=self.root,
metadata=self.metadata,
name=environment_name,
config=self.pipools_environment_dict.get(environment_name, {}),
matrix_variables=self.matrix_variables,
data_directory=self.data_directory,
isolated_data_directory=self.isolated_data_directory,
platform=Platform(),
verbosity=self.verbosity,
app=None,
)
if isinstance(self.app, hatch.cli.Application):
env = self.app.get_environment(env_name=environment_name)
else:
env = PipCompileEnvironment(
root=self.root,
metadata=self.metadata,
name=environment_name,
config=self.pipools_environment_dict.get(environment_name, {}),
matrix_variables=self.matrix_variables,
data_directory=self.data_directory,
isolated_data_directory=self.isolated_data_directory,
platform=Platform(),
verbosity=self.verbosity,
app=self.app,
)
return env

@functools.cached_property
def constraint_env(self) -> "PipCompileEnvironment":
Expand Down Expand Up @@ -360,8 +365,9 @@ def prepare_environment(self) -> None:
"""
Prepare the environment
Ideally, hatch.cli.Application.prepare_environment would be called
but the `Application` class is not exposed to the environment plugin.
Ideally, we could access the `self.app` attribute,
but this ultimately leads to a recursion error when
`self.app.prepare_environment()` is called.
"""
if not self.virtualenv_exists():
self.create()
Expand Down

0 comments on commit 28484a4

Please sign in to comment.