Skip to content

Commit 0deeda1

Browse files
fix: Respect user-provided directory in Ansys Notebook (#4358)
This pull request updates the file download logic in the `file_transfer_service.py` utility to improve how the local download directory is handled. The changes ensure that if no local directory is specified, the current working directory (`self.cwd`) is used by default, and that files are always downloaded to the intended directory. Improvements to file download handling: * Changed the default value of the `local_directory` parameter in the `download` method from `"."` to `None`, clarifying intent and allowing explicit handling of the default directory. * Updated the logic in the `download` method to set `download_directory` to `self.cwd` if `local_directory` is not provided, ensuring consistent download behavior. * Modified file copy operations to use the resolved `download_directory` instead of always using `self.cwd`, so files are placed in the correct location as specified by the user. --------- Co-authored-by: pyansys-ci-bot <[email protected]>
1 parent 0d0065e commit 0deeda1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

doc/changelog.d/4358.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Respect user-provided directory in Ansys Notebook

src/ansys/fluent/core/utils/file_transfer_service.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ def download_file(self, file_name: str, local_directory: str | None = None):
647647
else:
648648
raise FileNotFoundError("Remote file does not exist.")
649649

650-
def download(self, file_name: list[str] | str, local_directory: str | None = "."):
650+
def download(self, file_name: list[str] | str, local_directory: str | None = None):
651651
"""Download a file from the server.
652652
653653
Parameters
@@ -657,22 +657,23 @@ def download(self, file_name: list[str] | str, local_directory: str | None = "."
657657
local_directory : str, optional
658658
Local directory. The default is the current working directory.
659659
"""
660+
download_directory = local_directory if local_directory else self.cwd
660661
files = [file_name] if isinstance(file_name, str) else file_name
661662
if self.is_configured():
662663
for file in files:
663-
download_file_name = os.path.join(self.instance_dir, file)
664664
if os.path.isfile(file):
665665
warnings.warn(
666666
f"\nFile already exists. File path:\n{file}\n",
667667
PyFluentUserWarning,
668668
)
669669
else:
670+
download_file_name = os.path.join(self.instance_dir, file)
670671
if os.path.exists(download_file_name):
671-
shutil.copy2(download_file_name, self.cwd)
672+
shutil.copy2(download_file_name, download_directory)
672673
else:
673674
self.download_file(
674675
file_name=os.path.basename(file),
675-
local_directory=local_directory,
676+
local_directory=download_directory,
676677
)
677678

678679
def __call__(self, pim_instance: Any | None = None):

0 commit comments

Comments
 (0)