Skip to content

Commit

Permalink
fix: expose hook, bug
Browse files Browse the repository at this point in the history
  • Loading branch information
agoose77 committed Aug 27, 2024
1 parent dabb6da commit 098c751
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,6 @@ Source = "https://github.com/jupyter-book/hatch-deps-selector"

[tool.hatch.version]
path = "src/hatch_deps_selector/__about__.py"

[project.entry-points.hatch]
selector = "hatch_deps_selector.hooks"
25 changes: 18 additions & 7 deletions src/hatch_deps_selector/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,29 @@ def variants(self):
raise TypeError(f"Option `variants` for build hook `{self.PLUGIN_NAME}` must be a table")

self.__variants = variants
return self.variants
return self.__variants


def initialize(self, version, build_data):
# Allow variant to be unset or empty
variant = os.environ.get(self.env_var)
if not variant:
variant_name = os.environ.get(self.env_var)
if not variant_name:
return

# But if defined, should be valid
dependencies = self.variants.get(variant, [])
if dependencies is None:
raise ValueError(f"Variant `{variant}` not found for build hook `{self.PLUGIN_NAME}`")
# But if defined, variant should exist in config
try:
variant = self.variants[variant_name]
except KeyError:
raise ValueError(f"Variant `{variant}` not found for build hook `{self.PLUGIN_NAME}`") from None

# And variant should be a table
if not isinstance(variant, dict):
raise TypeError(f"Option `variants.{variant_name}` for build hook `{self.PLUGIN_NAME}` must be a table")
# Dependencies do not need to be defined
try:
dependencies = variant["dependencies"]
except KeyError:
raise ValueError(f"Variant `{variant}` not found for build hook `{self.PLUGIN_NAME}`") from None

build_data["dependencies"].extend(dependencies)

0 comments on commit 098c751

Please sign in to comment.