Skip to content

Commit

Permalink
Enable Anod class to use methods instead of properties
Browse files Browse the repository at this point in the history
  • Loading branch information
leocardao committed Mar 26, 2024
1 parent 8d38900 commit 0a80bf0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/e3/anod/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,26 @@ class MyProduct(Anod):
ExternalSourceBuilder = e3.anod.package.ExternalSourceBuilder
ThirdPartySourceBuilder = e3.anod.package.ThirdPartySourceBuilder

def __new__(cls, *args: Any, **kwargs: Any) -> Any:
"""Replace `method` by property when decorator is missing."""
should_be_property = (
"enable_name_generator",
"readme_info",
"base_name",
"build_space_name",
"has_package",
"package",
"component",
"source_pkg_build",
)

for prop in should_be_property:
class_property = getattr(cls, prop)
if callable(class_property):
setattr(cls, prop, property(fget=class_property))

return super().__new__(cls)

def __init__(
self,
qualifier: str,
Expand Down
9 changes: 9 additions & 0 deletions tests/tests_e3/anod/spec_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,12 @@ class GeneratorDisabled(Anod):

assert spec_enable.args == {"q1": True}
assert spec_disable.args == {"q1": ""}


def test_missing_property():
class NoProperty(Anod):
def source_pkg_build(self) -> list:
return []

noproperty = NoProperty(qualifier="", kind="source")
assert noproperty.source_pkg_build == []

0 comments on commit 0a80bf0

Please sign in to comment.