Skip to content

Commit 06c93c0

Browse files
germa89pyansys-ci-botclatapiepre-commit-ci[bot]
authored
refactor: annotate pymapdl part 1 (#3569)
* refactor: annotating version file * refactor: annotate __init__ * refactor: annotate commands.py * refactor: annotate common_grpc.py * refactor: annotate components.py * refactor: annotating convert.py * refactor: annotating errors.py * refactor: annotate information.py * refactor: annotate cli files * refactor: annotate examples module * chore: explain better a variable comment * refactor: annotate inline_functions * refactor: annotate jupyter.py * refactor: annotate krylov * fix: missing imports * chore: adding changelog file 3569.added.md [dependabot-skip] * chore: update src/ansys/mapdl/core/cli/stop.py Co-authored-by: Camille <[email protected]> * fix: missing import * feat: add missing import * fix: requests import * fix: missing import * fix: missing imports and wrong literal * fix: test_detach_examples_submodule * fix: pandas * test: testing examples * fix: add missing import * feat: fix pandas warning in docs. Also remove non-used function and adding _HAS_PANDAS to globals * fix: import * fix: import * ci: auto fixes from pre-commit.com hooks. for more information, see https://pre-commit.ci --------- Co-authored-by: pyansys-ci-bot <[email protected]> Co-authored-by: Camille <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 121c3d0 commit 06c93c0

23 files changed

+505
-446
lines changed

doc/changelog.d/3569.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
refactor: annotate pymapdl part 1

src/ansys/mapdl/core/__init__.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
import importlib.metadata as importlib_metadata
24-
2523
###############################################################################
2624
# Imports
2725
# =======
@@ -40,17 +38,16 @@
4038
#
4139
from ansys.mapdl.core.logging import Logger
4240

43-
LOG = Logger(level=logging.ERROR, to_file=False, to_stdout=True)
41+
LOG: Logger = Logger(level=logging.ERROR, to_file=False, to_stdout=True)
4442
LOG.debug("Loaded logging module as LOG")
4543

4644
###############################################################################
4745
# Globals
4846
# =======
4947
#
48+
from ansys.mapdl.core._version import __version__
5049
from ansys.mapdl.core.helpers import is_installed, run_every_import, run_first_time
5150

52-
__version__: str = importlib_metadata.version(__name__.replace(".", "-"))
53-
5451
# A dictionary relating PyMAPDL server versions with the unified install ones
5552
VERSION_MAP: Dict[Tuple[int, int, int], str] = {
5653
(0, 0, 0): "2020R2",
@@ -69,17 +66,21 @@
6966

7067
# Import related globals
7168
_HAS_ATP: bool = is_installed("ansys.tools.path")
69+
_HAS_CLICK: bool = is_installed("click")
7270
_HAS_PIM: bool = is_installed("ansys.platform.instancemanagement")
71+
_HAS_PANDAS: bool = is_installed("pandas")
7372
_HAS_PYANSYS_REPORT: bool = is_installed("ansys.tools.report")
7473
_HAS_PYVISTA: bool = is_installed("pyvista")
74+
_HAS_REQUESTS: bool = is_installed("requests")
7575
_HAS_TQDM: bool = is_installed("tqdm")
7676
_HAS_VISUALIZER: bool = is_installed("ansys.tools.visualization_interface")
7777

78+
7879
# Setup directories
7980
USER_DATA_PATH: str = user_data_dir(appname="ansys_mapdl_core", appauthor="Ansys")
80-
EXAMPLES_PATH = os.path.join(USER_DATA_PATH, "examples")
81+
EXAMPLES_PATH: str = os.path.join(USER_DATA_PATH, "examples")
8182

82-
# Store local ports
83+
# Store ports occupied by local instances
8384
_LOCAL_PORTS: List[int] = []
8485

8586
###############################################################################

src/ansys/mapdl/core/_version.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,18 +29,15 @@
2929
version_info = 0, 58, 'dev0'
3030
3131
"""
32-
33-
try:
34-
import importlib.metadata as importlib_metadata
35-
except ModuleNotFoundError: # pragma: no cover
36-
import importlib_metadata
32+
import importlib.metadata as importlib_metadata
33+
from typing import Dict
3734

3835
# Read from the pyproject.toml
3936
# major, minor, patch
40-
__version__ = importlib_metadata.version("ansys-mapdl-core")
37+
__version__: str = importlib_metadata.version("ansys-mapdl-core")
4138

4239
# In descending order
43-
SUPPORTED_ANSYS_VERSIONS = {
40+
SUPPORTED_ANSYS_VERSIONS: Dict[int, str] = {
4441
252: "2025R2",
4542
251: "2025R1",
4643
242: "2024R2",

src/ansys/mapdl/core/cli/__init__.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,16 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23-
try:
24-
import click
25-
26-
_HAS_CLICK = True
27-
28-
except ModuleNotFoundError:
29-
_HAS_CLICK = False
30-
23+
from ansys.mapdl.core import _HAS_CLICK
3124

3225
if _HAS_CLICK:
3326
###################################
3427
# PyMAPDL CLI
28+
import click
3529

3630
@click.group(invoke_without_command=True)
3731
@click.pass_context
38-
def main(ctx):
32+
def main(ctx: click.Context):
3933
pass
4034

4135
from ansys.mapdl.core.cli.convert import convert

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,14 @@
2121
# SOFTWARE.
2222

2323
import os
24+
from typing import Any, List
2425

2526
import click
2627

27-
_USING_PIPE = [False]
28+
_USING_PIPE: List[bool] = [False]
2829

2930

30-
def get_input_source(ctx, param, value):
31+
def get_input_source(ctx: click.Context, param: Any, value: Any):
3132
if not value and not click.get_text_stream("stdin").isatty():
3233
_USING_PIPE[0] = True
3334
return click.get_text_stream("stdin").read().strip()
@@ -180,7 +181,7 @@ def convert(
180181
use_vtk: bool,
181182
clear_at_start: bool,
182183
check_parameter_names: bool,
183-
):
184+
) -> None:
184185
"""Convert MAPDL code to PyMAPDL"""
185186
from ansys.mapdl.core.convert import convert_apdl_block, convert_script
186187

src/ansys/mapdl/core/cli/list_instances.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
default=False,
6666
help="Print running location info.",
6767
)
68-
def list_instances(instances, long, cmd, location):
68+
def list_instances(instances, long, cmd, location) -> None:
6969
import psutil
7070
from tabulate import tabulate
7171

src/ansys/mapdl/core/cli/start.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def start(
191191
add_env_vars: Dict[str, str], # ignored
192192
replace_env_vars: Dict[str, str], # ignored
193193
version: Union[int, str],
194-
):
194+
) -> None:
195195
from ansys.mapdl.core.launcher import launch_mapdl
196196

197197
if mode:

src/ansys/mapdl/core/cli/stop.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
# SOFTWARE.
2222

23+
from typing import Optional
24+
2325
import click
2426

2527

@@ -49,7 +51,21 @@
4951
default=False,
5052
help="Kill all MAPDL instances",
5153
)
52-
def stop(port, pid, all):
54+
def stop(port: int, pid: Optional[int], all: bool) -> None:
55+
"""Stop MAPDL instances running on a given port or with a given process id (PID).
56+
57+
This command stops MAPDL instances running on a given port or with a given process id (PID).
58+
By default, it stops instances running on the port 50052.
59+
60+
Parameters
61+
----------
62+
port : int
63+
Port where the MAPDL instance is running.
64+
pid : Optional[int]
65+
PID of the MAPDL instance
66+
all : bool
67+
If :class:`True`, kill all the instances regardless their port or PID.
68+
"""
5369
import psutil
5470

5571
from ansys.mapdl.core.launcher import is_ansys_process

0 commit comments

Comments
 (0)