From 22099ad03e16112bc444e49e8e815751c2b2e551 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Mon, 21 Nov 2022 13:54:21 +0000 Subject: [PATCH 1/6] update --- MANIFEST.in | 11 ++++++++ src/lightning_app/core/flow.py | 13 ++++++++- tests/tests_app/core/test_lightning_app.py | 31 ++++++++++++++++++++++ 3 files changed, 54 insertions(+), 1 deletion(-) diff --git a/MANIFEST.in b/MANIFEST.in index ac8c2556d4f02..02660c0d076e5 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,3 +5,14 @@ include .actions/setup_tools.py include .actions/assistant.py include src/version.info include *.cff # citation info +recursive-include src/lightning *.md +recursive-include requirements *.txt +recursive-include src/lightning/app/ui * +recursive-include src/lightning/cli/*-template * +include src/lightning/version.info + +include src/lightning/app/components/serve/catimage.png + +prune src/lightning_app +prune src/lightning_lite +prune src/pytorch_lightning diff --git a/src/lightning_app/core/flow.py b/src/lightning_app/core/flow.py index ac8a7ff325049..caa75c1c8432a 100644 --- a/src/lightning_app/core/flow.py +++ b/src/lightning_app/core/flow.py @@ -110,7 +110,18 @@ def name(self): """Return the current LightningFlow name.""" return self._name or "root" - def __setattr__(self, name, value): + def _get_property_if_exists(self, name: str) -> Union[property, None]: + attr = getattr(self.__class__, name, None) + return attr if isinstance(attr, property) else None + + def __setattr__(self, name: str, value: Any) -> None: + property_object = self._get_property_if_exists(name) + if property_object is not None and property_object.fset is not None: + property_object.fset(self, value) + else: + self._default_setattr(name, value) + + def _default_setattr(self, name, value): from lightning_app.structures import Dict, List if ( diff --git a/tests/tests_app/core/test_lightning_app.py b/tests/tests_app/core/test_lightning_app.py index 1b438f14632bb..1a8e5b8d7aebf 100644 --- a/tests/tests_app/core/test_lightning_app.py +++ b/tests/tests_app/core/test_lightning_app.py @@ -1108,3 +1108,34 @@ def test_cloud_compute_binding(): with pytest.raises(Exception, match="A Cloud Compute can be assigned only to a single Work"): FlowCC() + + +class FlowValue(LightningFlow): + def __init__(self): + super().__init__() + self._value = None + self._has_found = False + + @property + def value(self): + return self._value + + @value.setter + def value(self, value): + self._value = value + + def run(self): + if self.value is None: + self.value = True + + def _default_setattr(self, name, value): + if name == "_value" and value is True: + self._has_found = True + super()._default_setattr(name, value) + + +def test_lightning_flow_properties(): + + flow = FlowValue() + flow.run() + assert flow._has_found From 4568f29f24a17505a837a0a1ca8c193dbadb5850 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Mon, 21 Nov 2022 13:56:05 +0000 Subject: [PATCH 2/6] update --- tests/tests_app/core/test_lightning_app.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests_app/core/test_lightning_app.py b/tests/tests_app/core/test_lightning_app.py index 1a8e5b8d7aebf..db0eaa5563c61 100644 --- a/tests/tests_app/core/test_lightning_app.py +++ b/tests/tests_app/core/test_lightning_app.py @@ -1135,7 +1135,9 @@ def _default_setattr(self, name, value): def test_lightning_flow_properties(): + """Validates setting properties to the LightningFlow properly calls property.fset.""" flow = FlowValue() + assert not flow._has_found flow.run() assert flow._has_found From 757c33f0be7235c4587255d01b84b84c31178372 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Mon, 21 Nov 2022 13:57:34 +0000 Subject: [PATCH 3/6] update --- MANIFEST.in | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/MANIFEST.in b/MANIFEST.in index 02660c0d076e5..ac8c2556d4f02 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,14 +5,3 @@ include .actions/setup_tools.py include .actions/assistant.py include src/version.info include *.cff # citation info -recursive-include src/lightning *.md -recursive-include requirements *.txt -recursive-include src/lightning/app/ui * -recursive-include src/lightning/cli/*-template * -include src/lightning/version.info - -include src/lightning/app/components/serve/catimage.png - -prune src/lightning_app -prune src/lightning_lite -prune src/pytorch_lightning From f43bea31b237a5e79cc6f1cc20ff622293656508 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Mon, 21 Nov 2022 14:00:52 +0000 Subject: [PATCH 4/6] update --- src/lightning_app/CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lightning_app/CHANGELOG.md b/src/lightning_app/CHANGELOG.md index fc71747559675..00c76ec1aa73d 100644 --- a/src/lightning_app/CHANGELOG.md +++ b/src/lightning_app/CHANGELOG.md @@ -49,6 +49,9 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Fixed debugging with VSCode IDE ([#15747](https://github.com/Lightning-AI/lightning/pull/15747)) +- Fixed setting property to the LightningFlow ([#15750](https://github.com/Lightning-AI/lightning/pull/15750)) + + ## [1.8.1] - 2022-11-10 From f8b8e08792153e67f4457d050bbded731d5ebc12 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Mon, 21 Nov 2022 18:14:38 +0000 Subject: [PATCH 5/6] Update src/lightning_app/core/flow.py Co-authored-by: Ethan Harris --- src/lightning_app/core/flow.py | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/src/lightning_app/core/flow.py b/src/lightning_app/core/flow.py index caa75c1c8432a..eaa7152ab5162 100644 --- a/src/lightning_app/core/flow.py +++ b/src/lightning_app/core/flow.py @@ -110,18 +110,10 @@ def name(self): """Return the current LightningFlow name.""" return self._name or "root" - def _get_property_if_exists(self, name: str) -> Union[property, None]: - attr = getattr(self.__class__, name, None) - return attr if isinstance(attr, property) else None - def __setattr__(self, name: str, value: Any) -> None: - property_object = self._get_property_if_exists(name) - if property_object is not None and property_object.fset is not None: - property_object.fset(self, value) - else: - self._default_setattr(name, value) - - def _default_setattr(self, name, value): + attr = getattr(self.__class__, name, None) + if isinstance(attr, property) and property_object.fset is not None: + return property_object.fset(self, value) from lightning_app.structures import Dict, List if ( From 13862ee08857a186d3de10e373efc4a438574a48 Mon Sep 17 00:00:00 2001 From: thomas chaton Date: Mon, 21 Nov 2022 18:16:01 +0000 Subject: [PATCH 6/6] update --- src/lightning_app/core/flow.py | 5 +++-- tests/tests_app/core/test_lightning_app.py | 4 ++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/lightning_app/core/flow.py b/src/lightning_app/core/flow.py index eaa7152ab5162..18b6fd40f756a 100644 --- a/src/lightning_app/core/flow.py +++ b/src/lightning_app/core/flow.py @@ -112,8 +112,9 @@ def name(self): def __setattr__(self, name: str, value: Any) -> None: attr = getattr(self.__class__, name, None) - if isinstance(attr, property) and property_object.fset is not None: - return property_object.fset(self, value) + if isinstance(attr, property) and attr.fset is not None: + return attr.fset(self, value) + from lightning_app.structures import Dict, List if ( diff --git a/tests/tests_app/core/test_lightning_app.py b/tests/tests_app/core/test_lightning_app.py index db0eaa5563c61..4f2c0d8a50358 100644 --- a/tests/tests_app/core/test_lightning_app.py +++ b/tests/tests_app/core/test_lightning_app.py @@ -1128,10 +1128,10 @@ def run(self): if self.value is None: self.value = True - def _default_setattr(self, name, value): + def __setattr__(self, name, value): if name == "_value" and value is True: self._has_found = True - super()._default_setattr(name, value) + super().__setattr__(name, value) def test_lightning_flow_properties():