Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Detaching logging from main logic #3205

Merged
merged 19 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/3205.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
feat: Detaching logging from main logic
5 changes: 5 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ doc = [
"vtk==9.3.0",
]

hps =[
"ansys-hps-client==0.8.0",
"keyring==25.2.1",
]

[tool.flit.module]
name = "ansys.mapdl.core"

Expand Down
24 changes: 19 additions & 5 deletions src/ansys/mapdl/core/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@
_HAS_CLICK = False


try:
from ansys.hps.client import Client

Check warning on line 33 in src/ansys/mapdl/core/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/__init__.py#L32-L33

Added lines #L32 - L33 were not covered by tests

_HAS_HPS = True
except ModuleNotFoundError:
_HAS_HPS = False

Check warning on line 37 in src/ansys/mapdl/core/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/__init__.py#L35-L37

Added lines #L35 - L37 were not covered by tests

if _HAS_CLICK:
###################################
# PyMAPDL CLI
Expand All @@ -39,7 +46,6 @@
pass

from ansys.mapdl.core.cli.convert import convert
from ansys.mapdl.core.cli.hpc import submit
from ansys.mapdl.core.cli.list_instances import list_instances
from ansys.mapdl.core.cli.start import start
from ansys.mapdl.core.cli.stop import stop
Expand All @@ -50,10 +56,18 @@
main.add_command(list_instances, name="list")

# HPC commands
# pymapdl hpc submit
# pymapdl hpc list
# pymapdl hpc stop
main.add_command(submit)
# pymapdl (hpc) login
# pymapdl (hpc) submit
# pymapdl (hpc) list #To be implemented
# pymapdl (hpc) stop #To be implemented

if _HAS_HPS:
from ansys.mapdl.core.cli.hpc import submit
from ansys.mapdl.core.cli.login import login, logout

Check warning on line 66 in src/ansys/mapdl/core/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/__init__.py#L64-L66

Added lines #L64 - L66 were not covered by tests

main.add_command(login)
main.add_command(submit)
main.add_command(logout)

Check warning on line 70 in src/ansys/mapdl/core/cli/__init__.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/__init__.py#L68-L70

Added lines #L68 - L70 were not covered by tests

def old_pymapdl_convert_script_entry_point():
print(
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

File mapdl.dat successfully converted to mapdl.out.""",
)
@click.argument("filename_in", callback=get_input_source, required=False)
@click.argument("filename_in", callback=get_input_source, required=True)

Check warning on line 66 in src/ansys/mapdl/core/cli/convert.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/convert.py#L66

Added line #L66 was not covered by tests
koubaa marked this conversation as resolved.
Show resolved Hide resolved
@click.option("-o", default=None, help="Name of the output Python script.")
@click.option("--filename_out", default=None, help="Name of the output Python script.")
@click.option(
Expand Down
54 changes: 42 additions & 12 deletions src/ansys/mapdl/core/cli/hpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@

import click

from ansys.mapdl.core.cli import main

logger = logging.getLogger()


@main.command(
@click.command(

Check warning on line 34 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L34

Added line #L34 was not covered by tests
short_help="Submit jobs to an HPC cluster using PyHPS.",
help="""
Submit jobs to an HPC cluster using PyHPS.
Expand All @@ -55,16 +53,35 @@
"--url",
default=None,
type=str,
help="""URL where the HPS cluster is deployed. For example: "https://myserver:3000/hps" """,
help="""URL where the HPS cluster is deployed. For example: "https://myserver:3000/hps".
If it is not input, there is a chain of places where PyMAPDL looks for an URL.
First, it checks if the URL is given in the file specified by the argument ``--config_file``.
If that file does not have an URL or does not exist, then it checks the default user credentials stored with ``pymapdl login --default`` CLI command.
If no URL is found, an exception is raised.""",
)
@click.option(
"--user", default=None, type=str, help="Username for logging into the HPC cluster."
"--user",
default=None,
type=str,
help="""Username for logging into the HPC cluster.
If it is not input, there is a chain of places where PyMAPDL looks for an username.
First, it checks if the username is given in the file specified by the argument ``--config_file``.
If that file does not have an username or does not exist, then it checks the username configured using ``pymapdl login`` CLI command, for the given HPS cluster URL.
If there is no user credential stored for that HPS cluster URL, then it checks the default user credentials stored with ``pymapdl login --default`` CLI command.
If no user is found, an exception is raised.
""",
)
@click.option(
"--password",
default=None,
type=str,
help="Password for logging into the HPC cluster.",
help="""Password for logging into the HPC cluster.
If it is not input, there is a chain of places where PyMAPDL looks for a password.
First, it checks if the password is given in the file specified by the argument ``--config_file``.
If that file does not have a password or does not exist, then it checks the password configured using ``pymapdl login`` CLI command, for the given HPS cluster URL.
If there is no user credential stored for that HPS cluster URL, then it checks the default user credentials stored with ``pymapdl login --default`` CLI command.
If no password is found, an exception is raised.
""",
)
@click.option(
"--python",
Expand Down Expand Up @@ -235,7 +252,7 @@
mode: Optional[Union["python", "shell", "apdl"]] = None,
to_json: Optional[bool] = False,
):
import json
from ansys.mapdl.core.hpc.login import get_default_url, get_token_access

Check warning on line 255 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L255

Added line #L255 was not covered by tests

if to_json:
import json
Expand All @@ -254,11 +271,25 @@

if config_file is None:
config_file = os.path.join(os.getcwd(), "hps_config.json")
if not os.path.exists(config_file):
config_file = None

Check warning on line 275 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L274-L275

Added lines #L274 - L275 were not covered by tests
logger.debug(f"Using default HPS configuration file: {config_file}")

url = get_value_from_json_or_default(url, config_file, "url", None)
user = get_value_from_json_or_default(user, config_file, "user", None)
password = get_value_from_json_or_default(password, config_file, "password", None)
# Getting cluster login configuration from CLI or file
url = get_value_from_json_or_default(

Check warning on line 279 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L279

Added line #L279 was not covered by tests
url, config_file, "url", None, raise_if_none=False
)
url = url or get_default_url() # using default URL stored.

Check warning on line 282 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L282

Added line #L282 was not covered by tests

# allow retrieving user from the configuration
user = get_value_from_json_or_default(

Check warning on line 285 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L285

Added line #L285 was not covered by tests
user, config_file, "user", raise_if_none=False
)

# Getting access token
token = get_token_access(url, user, password)

Check warning on line 290 in src/ansys/mapdl/core/cli/hpc.py

View check run for this annotation

Codecov / codecov/patch

src/ansys/mapdl/core/cli/hpc.py#L290

Added line #L290 was not covered by tests

# Getting other configuration from CLI or file
python = get_value_from_json_or_default(python, config_file, "python", 3)
name = get_value_from_json_or_default(name, config_file, "name", "My PyMAPDL job")

Expand All @@ -276,8 +307,7 @@

job = PyMAPDLJobSubmission(
url=url,
user=user,
password=password,
token=token,
main_file=main_file,
mode=mode,
inputs=inputs,
Expand Down
1 change: 1 addition & 0 deletions src/ansys/mapdl/core/cli/list_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
@main.command(
short_help="List MAPDL running instances.",
help="""This command list MAPDL instances""",
name="list",
)
@click.option(
"--instances",
Expand Down
Loading
Loading