Skip to content

Commit

Permalink
Review representation of key-value qualifier when value is empty
Browse files Browse the repository at this point in the history
Ensure that representation is "" and that that it has no impact
on the trailing hash.
  • Loading branch information
Nikokrock committed Aug 1, 2023
1 parent 05a2893 commit 30ecf19
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
39 changes: 22 additions & 17 deletions src/e3/anod/qualifiers_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,30 +157,35 @@ def value(self, value: str | bool) -> str | bool:
def repr(self, value: str | bool, hash_pool: list[str] | None) -> str:
"""See QualifierDeclaration.repr."""
list_repr = []
if not self.repr_omit_key:
list_repr.append(self.repr_name)
if value:
list_repr.append(str(value))

str_repr = "-".join(list_repr)
if not value:
# An empty value for tag value should lead to an empty representation
str_repr = ""
elif (
value == self.default
and self.choices is not None
and "" not in self.choices
):
# In the case the value of qualifier is a finite set and
# that "" is not in that set, if value is the default value then
# just return an empty representation.
str_repr = ""
else:
# Otherwise compute components of the representation.
if not self.repr_omit_key:
list_repr.append(self.repr_name)
if value:
list_repr.append(str(value))

# And join them with a dash.
str_repr = "-".join(list_repr)

if hash_pool is not None and self.repr_in_hash:
if str_repr:
hash_pool.append(str_repr)
return ""
else:
if (
value != ""
and value == self.default
and self.choices is not None
and "" not in self.choices
):
# In the case the value of qualifier is a finite set and
# that "" is not in that set, if value is the default value then
# just return an empty representation.
return ""
else:
return str_repr
return str_repr


class TagDeclaration(QualifierDeclaration):
Expand Down
8 changes: 7 additions & 1 deletion tests/tests_e3/anod/test_qualifier_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def declare_qualifiers_and_components(self, qualifiers_manager):
assert simple_debug.get_qualifier("debug")

simple_empty = Simple(qualifier="optional_qual", kind="build")
assert simple_empty.build_space_name == "simple_optional_qual"
assert simple_empty.build_space_name == "simple"

# Disable the name generator
class Base(Anod):
Expand Down Expand Up @@ -304,13 +304,15 @@ def declare_qualifiers_and_components(self, qualifiers_manager):
name="path",
description="The first path.",
repr_in_hash=True,
default="",
)

# Add the "path_bis" qualifier
qualifiers_manager.declare_key_value_qualifier(
name="path_bis",
description="A second path.",
repr_in_hash=True,
default="",
)

anod_no_component_1 = AnodNoComponent(
Expand All @@ -331,6 +333,10 @@ def declare_qualifiers_and_components(self, qualifiers_manager):
assert anod_no_component_3.build_space_name == "my_spec_debug_1.2_a2aaba2e"
assert anod_no_component_3.component is None

anod_no_component_4 = AnodNoComponent(qualifier="debug,version=1.2", kind="build")
assert anod_no_component_4.build_space_name == "my_spec_debug_1.2"
assert anod_no_component_4.component is None

class AnodComponent(Anod):
enable_name_generator = True
base_name = "my_spec"
Expand Down

0 comments on commit 30ecf19

Please sign in to comment.