Skip to content

Commit

Permalink
Add support for context formatting in builder dependencies.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewwardrop committed May 6, 2024
1 parent 44d66f5 commit d116be8
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions backend/src/hatchling/builders/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

if TYPE_CHECKING:
from hatchling.builders.plugin.interface import BuilderInterface
from hatchling.utils.context import Context


class BuilderConfig:
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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):
Expand All @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit d116be8

Please sign in to comment.