From 73ed39d6ab31d70e7b61b700965160536c0321a7 Mon Sep 17 00:00:00 2001 From: German Date: Tue, 17 Jan 2023 12:30:22 +0000 Subject: [PATCH 1/4] Avoiding use 'self._path' in '_verify_local' --- src/ansys/mapdl/core/mapdl_grpc.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 3edd80790d5..bcecdea9768 100755 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -573,10 +573,7 @@ def _verify_local(self): """Check if Python is local to the MAPDL instance.""" # Verify if python has assess to the MAPDL directory. if self._local: - if self._path is None: - directory = self.directory - else: - directory = self._path + directory = self.directory if self._jobname is None: jobname = self.jobname From 9ceac60088995747b571ab9aadbc92746eda0603 Mon Sep 17 00:00:00 2001 From: German Date: Tue, 17 Jan 2023 12:47:29 +0000 Subject: [PATCH 2/4] Adding a redundancy mechanism --- src/ansys/mapdl/core/mapdl.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index 4ee5a293493..c00b375929e 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -3174,16 +3174,25 @@ def directory(self) -> str: a warning. """ # always attempt to cache the path - try: - self._path = self.inquire("", "DIRECTORY") - except Exception: - pass + self._path = None + i = 0 + while not self._path and i > 5: + try: + self._path = self.inquire("", "DIRECTORY") + except Exception: + pass + i += 1 # os independent path format if self._path: # self.inquire might return ''. self._path = self._path.replace("\\", "/") # new line to fix path issue, see #416 self._path = repr(self._path)[1:-1] + else: + raise IOError( + f"The directory returned by /INQUIRE is not valid ('{self._path}')." + ) + return self._path @directory.setter From c59a4193dfcfc25686a4246510f87a10542a1cde Mon Sep 17 00:00:00 2001 From: German Date: Tue, 17 Jan 2023 13:31:33 +0000 Subject: [PATCH 3/4] Avoiding overwriting self._path --- src/ansys/mapdl/core/mapdl.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index c00b375929e..eb473b89d94 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -3174,14 +3174,15 @@ def directory(self) -> str: a warning. """ # always attempt to cache the path - self._path = None i = 0 - while not self._path and i > 5: + while (not self._path and i > 5) or i == 0: try: self._path = self.inquire("", "DIRECTORY") except Exception: pass i += 1 + if not self._path: + time.sleep(0.1) # os independent path format if self._path: # self.inquire might return ''. From b2224103d787e0204fd9b1e2df618d98efe5b51e Mon Sep 17 00:00:00 2001 From: German Date: Tue, 17 Jan 2023 13:45:07 +0000 Subject: [PATCH 4/4] Fixing coverage --- src/ansys/mapdl/core/mapdl.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index eb473b89d94..c0e041dcb49 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -3178,10 +3178,10 @@ def directory(self) -> str: while (not self._path and i > 5) or i == 0: try: self._path = self.inquire("", "DIRECTORY") - except Exception: + except Exception: # pragma: no cover pass i += 1 - if not self._path: + if not self._path: # pragma: no cover time.sleep(0.1) # os independent path format @@ -3189,7 +3189,7 @@ def directory(self) -> str: self._path = self._path.replace("\\", "/") # new line to fix path issue, see #416 self._path = repr(self._path)[1:-1] - else: + else: # pragma: no cover raise IOError( f"The directory returned by /INQUIRE is not valid ('{self._path}')." )