Skip to content

Commit

Permalink
feat: remove beartype, platformdirs and requests (#3426)
Browse files Browse the repository at this point in the history
* feat: remove beartype

* feat: remove platformdirs

* feat: remove requests

* feat: fix

* feat: fix

* feat: fix

* feat: fix
  • Loading branch information
mkundu1 authored Oct 25, 2024
1 parent 1e8140c commit 2cf9aa7
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 24 deletions.
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,15 @@ 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"
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]
Expand Down
8 changes: 2 additions & 6 deletions src/ansys/fluent/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 3 additions & 5 deletions src/ansys/fluent/core/examples/downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
7 changes: 4 additions & 3 deletions src/ansys/fluent/core/launcher/launcher_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
17 changes: 17 additions & 0 deletions src/ansys/fluent/core/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import importlib.util
import logging
from pathlib import Path
import sys

logger = logging.getLogger("pyfluent.general")
Expand All @@ -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"
7 changes: 2 additions & 5 deletions src/ansys/fluent/core/utils/file_transfer_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
38 changes: 38 additions & 0 deletions src/ansys/fluent/core/utils/networking.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
2 changes: 0 additions & 2 deletions tests/test_settings_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2cf9aa7

Please sign in to comment.