Skip to content

Commit

Permalink
Merge pull request #2 from jupyter-book/agoose77/feat-default-variant
Browse files Browse the repository at this point in the history
🚀 Add support for default variants
  • Loading branch information
agoose77 authored Aug 28, 2024
2 parents ecc9397 + 92d0d18 commit 0cf4ec1
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/hatch_deps_selector/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, *args, **kwargs):

self.__env_var = None
self.__variants = None
self.__default_variant = None

@property
def env_var(self):
Expand All @@ -31,10 +32,23 @@ def variants(self):
self.__variants = variants
return self.__variants

@property
def default_variant(self):
if self.__default_variant is None:
default_variant = self.config.get("default-variant", {})
if not isinstance(default_variant, str):
raise TypeError(f"Option `default-variant` for build hook `{self.PLUGIN_NAME}` must be a string")

self.__default_variant = default_variant
return self.__default_variant


def initialize(self, version, build_data):
# Allow variant to be unset or empty
variant_name = os.environ.get(self.env_var)
# If variant is not set, use default variant
# Otherwise, respect the set value
variant_name = os.environ.get(self.env_var, self.default_variant)

# If the variant name is empty or None, assume we don't want a variant
if not variant_name:
return

Expand Down

0 comments on commit 0cf4ec1

Please sign in to comment.