diff --git a/backend/src/hatchling/builders/config.py b/backend/src/hatchling/builders/config.py index da4a9f9b9..dd9757ea3 100644 --- a/backend/src/hatchling/builders/config.py +++ b/backend/src/hatchling/builders/config.py @@ -14,6 +14,7 @@ if TYPE_CHECKING: from hatchling.builders.plugin.interface import BuilderInterface + from hatchling.utils.context import Context class BuilderConfig: @@ -30,6 +31,7 @@ def __init__( self.__plugin_name = plugin_name self.__build_config = build_config self.__target_config = target_config + self.__context: Context | None = None self.__hook_config: dict[str, Any] | None = None self.__versions: list[str] | None = None self.__dependencies: list[str] | None = None @@ -89,6 +91,15 @@ def build_config(self) -> dict[str, Any]: def target_config(self) -> dict[str, Any]: return self.__target_config + @property + def context(self) -> Context: + if self.__context is None: + from hatchling.utils.context import Context + + self.__context = Context(self.root) + + return self.__context + def include_path(self, relative_path: str, *, explicit: bool = False, is_package: bool = True) -> bool: return ( self.path_is_build_artifact(relative_path) @@ -575,7 +586,7 @@ def dependencies(self) -> list[str]: ) raise TypeError(message) - dependencies[dependency] = None + dependencies[self.context.format(dependency)] = None global_dependencies = self.build_config.get('dependencies', []) if not isinstance(global_dependencies, list): @@ -587,7 +598,7 @@ def dependencies(self) -> list[str]: message = f'Dependency #{i} of field `tool.hatch.build.dependencies` must be a string' raise TypeError(message) - dependencies[dependency] = None + dependencies[self.context.format(dependency)] = None require_runtime_dependencies = self.require_runtime_dependencies require_runtime_features = dict.fromkeys(self.require_runtime_features) @@ -642,7 +653,7 @@ def dependencies(self) -> list[str]: ) raise TypeError(message) - dependencies[dependency] = None + dependencies[self.context.format(dependency)] = None if require_runtime_dependencies: for dependency in self.builder.metadata.core.dependencies: @@ -677,7 +688,7 @@ def dynamic_dependencies(self) -> list[str]: except ImportError: continue - dependencies.extend(build_hook.dependencies()) + dependencies.extend([self.context.format(dependency) for dependency in build_hook.dependencies()]) return dependencies