Skip to content

Commit 359589d

Browse files
committed
fix(plugin): corrected context based change current directory
fixes #368
1 parent 09399c3 commit 359589d

File tree

2 files changed

+20
-47
lines changed

2 files changed

+20
-47
lines changed

packages/core/src/robotcode/core/utils/contextlib.py

Lines changed: 0 additions & 44 deletions
This file was deleted.

packages/plugin/src/robotcode/plugin/__init__.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import dataclasses
2+
import os
23
import sys
34
from contextlib import contextmanager
45
from dataclasses import dataclass
@@ -23,8 +24,8 @@
2324
import pluggy
2425
import tomli_w
2526

26-
from robotcode.core.utils.contextlib import chdir
2727
from robotcode.core.utils.dataclasses import as_dict, as_json
28+
from robotcode.core.utils.path import same_file
2829

2930
__all__ = [
3031
"Application",
@@ -298,8 +299,24 @@ def exit(self, code: int = 0) -> None:
298299

299300
@contextmanager
300301
def chdir(self, path: Union[str, Path, None]) -> Iterator[Optional[Path]]:
301-
with chdir(path, self.verbose) as result:
302-
yield result
302+
old_dir: Optional[Path] = Path.cwd()
303+
304+
if path is None or (old_dir and same_file(path, old_dir)):
305+
self.verbose(f"no need to change directory to {path}")
306+
old_dir = None
307+
else:
308+
if path:
309+
self.verbose(f"Changing directory to {path}")
310+
311+
os.chdir(path)
312+
313+
try:
314+
yield old_dir
315+
finally:
316+
if old_dir is not None:
317+
self.verbose(f"Changing directory back to {old_dir}")
318+
319+
os.chdir(old_dir)
303320

304321
@contextmanager
305322
def save_syspath(self) -> Iterator[Literal[None]]:

0 commit comments

Comments
 (0)