From eb3322bab62cee5ddd59b2e7bfab84c7389ae7b1 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Tue, 7 Jun 2022 13:43:14 -0500 Subject: [PATCH 1/5] __dir__ --- CHANGELOG.md | 3 +++ WrightTools/data/_data.py | 7 +++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd3e6c78..1657ccdb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] +## Added +- iPython autocomplete recognizes axis, variable, and channel names + ## [3.4.4] ### Added diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index f51e3473..a44e49dd 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -85,6 +85,13 @@ def __repr__(self) -> str: self.natural_name, str(self.axis_names), "::".join([self.filepath, self.name]) ) + def __dir__(self) -> List[str]: + default = object.__dir__(self) + axes = [ax.natural_name for ax in self.axes] + channels = [ch.natural_name for ch in self.channels] + variables = [v.natural_name for v in self.variables] + return default + axes + channels + variables + @property def axes(self) -> tuple: return tuple(self._axes) From 813e922b35670396ad9ba72f7e50a0a105fbdfa9 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Tue, 7 Jun 2022 13:54:21 -0500 Subject: [PATCH 2/5] data: key completions --- CHANGELOG.md | 2 +- WrightTools/data/_data.py | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1657ccdb..01ca0ae5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ## [Unreleased] ## Added -- iPython autocomplete recognizes axis, variable, and channel names +- iPython integration: autocomplete includes axis, variable, and channel names ## [3.4.4] diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index a44e49dd..6982e6b2 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -85,12 +85,15 @@ def __repr__(self) -> str: self.natural_name, str(self.axis_names), "::".join([self.filepath, self.name]) ) - def __dir__(self) -> List[str]: + def __dir__(self) -> list: default = object.__dir__(self) axes = [ax.natural_name for ax in self.axes] + return default + axes + self._ipython_key_completions() + + def _ipython_key_completions_(self) -> list: channels = [ch.natural_name for ch in self.channels] variables = [v.natural_name for v in self.variables] - return default + axes + channels + variables + return axes + channels + variables @property def axes(self) -> tuple: From e166f226df660c5d31f99fa90ce795bfc92fc6a3 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:01:26 -0500 Subject: [PATCH 3/5] Update _data.py --- WrightTools/data/_data.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WrightTools/data/_data.py b/WrightTools/data/_data.py index 6982e6b2..f536c6c0 100644 --- a/WrightTools/data/_data.py +++ b/WrightTools/data/_data.py @@ -88,12 +88,12 @@ def __repr__(self) -> str: def __dir__(self) -> list: default = object.__dir__(self) axes = [ax.natural_name for ax in self.axes] - return default + axes + self._ipython_key_completions() + return default + axes + self._ipython_key_completions_() def _ipython_key_completions_(self) -> list: channels = [ch.natural_name for ch in self.channels] variables = [v.natural_name for v in self.variables] - return axes + channels + variables + return channels + variables @property def axes(self) -> tuple: From 29badb94a853b27871ab1e28e515fe3c09d8ba81 Mon Sep 17 00:00:00 2001 From: Daniel Kohler <11864045+ddkohler@users.noreply.github.com> Date: Tue, 7 Jun 2022 15:01:41 -0500 Subject: [PATCH 4/5] Update _collection.py completion for collections --- WrightTools/collection/_collection.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/WrightTools/collection/_collection.py b/WrightTools/collection/_collection.py index 80b3f8f8..b9d0cbc8 100644 --- a/WrightTools/collection/_collection.py +++ b/WrightTools/collection/_collection.py @@ -45,6 +45,13 @@ def __repr__(self): self.natural_name, self.item_names, "::".join([self.filepath, self.name]) ) + def __dir__(self) -> list: + default = object.__dir__(self) + return default + list(self._ipython_key_completions_()) + + def _ipython_key_completions_(self) -> list: + return list(self.item_names) + def __getitem__(self, key): if isinstance(key, int): key = self.item_names[key] From b99d1017c36651e68b79c594b5467d460288cc61 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 7 Jun 2022 20:05:25 +0000 Subject: [PATCH 5/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- WrightTools/collection/_collection.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WrightTools/collection/_collection.py b/WrightTools/collection/_collection.py index b9d0cbc8..7b19866a 100644 --- a/WrightTools/collection/_collection.py +++ b/WrightTools/collection/_collection.py @@ -48,7 +48,7 @@ def __repr__(self): def __dir__(self) -> list: default = object.__dir__(self) return default + list(self._ipython_key_completions_()) - + def _ipython_key_completions_(self) -> list: return list(self.item_names)