Skip to content

Commit

Permalink
feat: Remove alive-progress dependency (#3424)
Browse files Browse the repository at this point in the history
* feat: Manual progress bar

* feat: remove alive-progress

* feat: print file name only

* feat: refactor

* feat: remove progress bar

* feat: update logger name

* feat: update logger name

* feat: update logger message

* feat: update logger

* feat: use print
  • Loading branch information
hpohekar authored Oct 25, 2024
1 parent cb8cae3 commit 9dc77ff
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 37 deletions.
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ ansys-api-fluent = "^0.3.28"
ansys-platform-instancemanagement = "~=1.0"
ansys-tools-filetransfer = ">=0.1,<0.3"
ansys-units = "^0.3.2"
alive-progress = ">=3.1.5"
beartype = ">=0.17"
docker = ">=7.1.0"
grpcio = "^1.30.0"
Expand Down
62 changes: 26 additions & 36 deletions src/ansys/fluent/core/utils/file_transfer_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Provides a module for file transfer service."""

import logging
import os
import pathlib
import random
Expand All @@ -14,9 +13,6 @@
from ansys.fluent.core.warnings import PyFluentUserWarning
import ansys.platform.instancemanagement as pypim

logger = logging.getLogger("pyfluent.file_transfer_service")


# Host path which is mounted to the file-transfer-service container
MOUNT_SOURCE = platformdirs.user_data_dir(
appname="ansys_fluent_core", appauthor="Ansys"
Expand Down Expand Up @@ -482,23 +478,20 @@ def upload(self, file_name: list[str] | str, remote_file_name: str | None = None
"""
files = [file_name] if isinstance(file_name, str) else file_name
if self.is_configured():
from alive_progress import alive_bar

with alive_bar(len(files), title="Uploading...") as bar:
for file in files:
if os.path.isfile(file):
if not self.file_service.file_exist(os.path.basename(file)):
self.upload_file(
file_name=file, remote_file_name=remote_file_name
)
bar()
else:
warnings.warn(
f"\n{file} with the same name exists at the remote location.\n",
PyFluentUserWarning,
)
elif not self.file_service.file_exist(os.path.basename(file)):
raise FileNotFoundError(f"{file} does not exist.")
for file in files:
if os.path.isfile(file):
if not self.file_service.file_exist(os.path.basename(file)):
self.upload_file(
file_name=file, remote_file_name=remote_file_name
)
print(f"\n{os.path.basename(file_name)} uploaded.\n")
else:
warnings.warn(
f"\n{file} with the same name exists at the remote location.\n",
PyFluentUserWarning,
)
elif not self.file_service.file_exist(os.path.basename(file)):
raise FileNotFoundError(f"{file} does not exist.")

def download_file(self, file_name: str, local_directory: str | None = None):
"""Download a file from the server supported by `PyPIM<https://pypim.docs.pyansys.com/version/stable/>`.
Expand Down Expand Up @@ -537,21 +530,18 @@ def download(self, file_name: list[str] | str, local_directory: str | None = "."
"""
files = [file_name] if isinstance(file_name, str) else file_name
if self.is_configured():
from alive_progress import alive_bar

with alive_bar(len(files), title="Downloading...") as bar:
for file in files:
if os.path.isfile(file):
warnings.warn(
f"\nFile already exists. File path:\n{file}\n",
PyFluentUserWarning,
)
else:
self.download_file(
file_name=os.path.basename(file),
local_directory=local_directory,
)
bar()
for file in files:
if os.path.isfile(file):
warnings.warn(
f"\nFile already exists. File path:\n{file}\n",
PyFluentUserWarning,
)
else:
self.download_file(
file_name=os.path.basename(file),
local_directory=local_directory,
)
print(f"\n{os.path.basename(file_name)} downloaded.\n")

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

0 comments on commit 9dc77ff

Please sign in to comment.