diff --git a/pyproject.toml b/pyproject.toml index 18593f1a960..db656e8e7a2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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" -beartype = ">=0.17" docker = ">=7.1.0" grpcio = "^1.30.0" grpcio-health-checking = "^1.30.0" @@ -52,10 +51,8 @@ lxml = ">=4.9.2" nltk = ">=3.9.1" numpy= ">=1.14.0,<2.0.0" pandas = ">=1.1.0,<2.3" -platformdirs = ">=3.6.0" psutil = ">=5.9.5" pyyaml = ">=6.0" -requests = ">=2.32.3" h5py = { version = "==3.12.1", optional = true } [tool.poetry.group.docs] diff --git a/src/ansys/fluent/core/__init__.py b/src/ansys/fluent/core/__init__.py index b69dda70bd9..dd2b250ca58 100644 --- a/src/ansys/fluent/core/__init__.py +++ b/src/ansys/fluent/core/__init__.py @@ -4,8 +4,6 @@ from pathlib import Path import pydoc -import platformdirs - # isort: off # Logging has to be imported before importing other PyFluent modules from ansys.fluent.core.logging import set_console_logging_level # noqa: F401 @@ -38,7 +36,7 @@ MeshingEvent, SolverEvent, ) -from ansys.fluent.core.utils import fldoc +from ansys.fluent.core.utils import fldoc, get_examples_download_dir from ansys.fluent.core.utils.fluent_version import FluentVersion # noqa: F401 from ansys.fluent.core.utils.setup_for_fluent import setup_for_fluent # noqa: F401 from ansys.fluent.core.warnings import ( # noqa: F401 @@ -78,9 +76,7 @@ def version_info() -> str: return _VERSION_INFO if _VERSION_INFO is not None else __version__ -EXAMPLES_PATH = os.path.join( - platformdirs.user_documents_dir(), "ansys_fluent_core_examples" -) +EXAMPLES_PATH = str(get_examples_download_dir()) # Host path which is mounted to the container CONTAINER_MOUNT_SOURCE = None diff --git a/src/ansys/fluent/core/examples/downloads.py b/src/ansys/fluent/core/examples/downloads.py index fb78879c0ad..6526f4b2e77 100644 --- a/src/ansys/fluent/core/examples/downloads.py +++ b/src/ansys/fluent/core/examples/downloads.py @@ -7,9 +7,8 @@ import shutil import zipfile -import requests - import ansys.fluent.core as pyfluent +from ansys.fluent.core.utils.networking import check_url_exists, get_url_content logger = logging.getLogger("pyfluent.networking") @@ -86,7 +85,7 @@ def _retrieve_file( # Download file logger.info(f'Downloading URL: "{url}"') - content = requests.get(url).content + content = get_url_content(url) with open(local_path, "wb") as f: f.write(content) @@ -166,8 +165,7 @@ def download_file( return_without_path = True url = _get_file_url(file_name, directory) - head = requests.head(f"{url}") - if not head.ok: + if not check_url_exists(url): raise RemoteFileNotFoundError(url) return _retrieve_file(url, file_name, save_path, return_without_path) diff --git a/src/ansys/fluent/core/launcher/launcher_utils.py b/src/ansys/fluent/core/launcher/launcher_utils.py index ac1635ffe71..79739a07408 100644 --- a/src/ansys/fluent/core/launcher/launcher_utils.py +++ b/src/ansys/fluent/core/launcher/launcher_utils.py @@ -82,12 +82,13 @@ def _build_journal_argument( ) -> str: """Build Fluent commandline journal argument.""" - from beartype import BeartypeConf, beartype - - @beartype(conf=BeartypeConf(violation_type=TypeError)) def _impl( topy: None | bool | str, journal_file_names: None | str | list[str] ) -> str: + if journal_file_names and not isinstance(journal_file_names, (str, list)): + raise TypeError( + "Use 'journal_file_names' to specify and convert journal files." + ) if topy and not journal_file_names: raise InvalidArgument( "Use 'journal_file_names' to specify and convert journal files." diff --git a/src/ansys/fluent/core/utils/__init__.py b/src/ansys/fluent/core/utils/__init__.py index 3158e9a88cd..50d80a95fff 100644 --- a/src/ansys/fluent/core/utils/__init__.py +++ b/src/ansys/fluent/core/utils/__init__.py @@ -2,6 +2,7 @@ import importlib.util import logging +from pathlib import Path import sys logger = logging.getLogger("pyfluent.general") @@ -17,3 +18,19 @@ def load_module(module_name, file_path): spec.loader.exec_module(module) logger.info(f"Loaded module {module_name} from {file_path}") return module + + +def get_examples_download_dir(): + """Return the path to the examples download directory.""" + parent_path = Path.home() / "Downloads" + if not parent_path.exists(): + parent_path = Path.home() + return parent_path / "ansys_fluent_core_examples" + + +def get_user_data_dir(): + """Return the path to the user data directory.""" + if sys.platform == "win32": + return Path.home() / "AppData" / "Local" / "Ansys" / "ansys_fluent_core" + else: + return Path.home() / ".local" / "share" / "Ansys" / "ansys_fluent_core" diff --git a/src/ansys/fluent/core/utils/file_transfer_service.py b/src/ansys/fluent/core/utils/file_transfer_service.py index bd02b5632c2..ce4f2f852f3 100644 --- a/src/ansys/fluent/core/utils/file_transfer_service.py +++ b/src/ansys/fluent/core/utils/file_transfer_service.py @@ -7,16 +7,13 @@ from typing import Any, Callable, List, Protocol # noqa: F401 import warnings -import platformdirs - +from ansys.fluent.core.utils import get_user_data_dir from ansys.fluent.core.utils.deprecate import deprecate_argument from ansys.fluent.core.warnings import PyFluentUserWarning import ansys.platform.instancemanagement as pypim # Host path which is mounted to the file-transfer-service container -MOUNT_SOURCE = platformdirs.user_data_dir( - appname="ansys_fluent_core", appauthor="Ansys" -) +MOUNT_SOURCE = str(get_user_data_dir()) class PyPIMConfigurationError(ConnectionError): diff --git a/src/ansys/fluent/core/utils/networking.py b/src/ansys/fluent/core/utils/networking.py index 59eda4e1145..9161f61e3df 100644 --- a/src/ansys/fluent/core/utils/networking.py +++ b/src/ansys/fluent/core/utils/networking.py @@ -4,6 +4,7 @@ import logging import socket from typing import Any +import urllib import grpc from grpc_health.v1 import health_pb2, health_pb2_grpc @@ -83,3 +84,40 @@ def find_remoting_ip() -> str: return ip except Exception: network_logger.debug(f"Cannot use {ip} as remoting ip") + + +def check_url_exists(url: str) -> bool: + """Check if a URL exists. + + Parameters + ---------- + url : str + URL to check + + Returns + ------- + bool + True if the URL exists, False otherwise + """ + try: + with urllib.request.urlopen(url) as response: + return response.status == 200 + except Exception: + return False + + +def get_url_content(url: str) -> str: + """Get the content of a URL. + + Parameters + ---------- + url : str + URL to get content from + + Returns + ------- + str + content of the URL + """ + with urllib.request.urlopen(url) as response: + return response.read() diff --git a/tests/test_settings_api.py b/tests/test_settings_api.py index 0d04b04b9fb..5f0497b0850 100644 --- a/tests/test_settings_api.py +++ b/tests/test_settings_api.py @@ -24,8 +24,6 @@ def test_setup_models_viscous_model_settings(new_solver_session) -> None: solver_session.file.read( file_name=case_path, file_type="case", lightweight_setup=True ) - # NOTE: Not sure why initialization is necessary here - # solver_session.solution.initialization.hybrid_initialize() viscous_model = solver_session.setup.models.viscous