|
20 | 20 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
21 | 21 | # SOFTWARE. |
22 | 22 |
|
23 | | -# Importing logging |
| 23 | +import importlib.metadata as importlib_metadata |
| 24 | + |
| 25 | +############################################################################### |
| 26 | +# Imports |
| 27 | +# ======= |
| 28 | +# |
24 | 29 | import logging |
25 | 30 | import os |
26 | 31 | import sys |
| 32 | +from typing import Dict, List, Tuple |
27 | 33 | from warnings import warn |
28 | 34 |
|
29 | | -import platformdirs |
30 | | - |
31 | | -# Setup data directory |
32 | | -USER_DATA_PATH = platformdirs.user_data_dir( |
33 | | - appname="ansys_mapdl_core", appauthor="Ansys" |
34 | | -) |
35 | | -if not os.path.exists(USER_DATA_PATH): # pragma: no cover |
36 | | - os.makedirs(USER_DATA_PATH) |
37 | | - |
38 | | -DEPRECATING_MINIMUM_PYTHON_VERSION = True |
39 | | -MINIMUM_PYTHON_VERSION = (3, 10) |
40 | | - |
41 | | -first_time_file = os.path.join(USER_DATA_PATH, ".firstime") |
42 | | -if not os.path.exists(first_time_file): # pragma: no cover |
43 | | - py_ver = f"{sys.version_info[0]}.{sys.version_info[1]}" |
44 | | - py_ver_min = f"{MINIMUM_PYTHON_VERSION[0]}.{MINIMUM_PYTHON_VERSION[1]}" |
45 | | - |
46 | | - if ( |
47 | | - sys.version_info[1] == MINIMUM_PYTHON_VERSION[1] |
48 | | - and DEPRECATING_MINIMUM_PYTHON_VERSION |
49 | | - ): |
50 | | - warn( |
51 | | - f"Support for Python {py_ver} will be dropped in the next minor " "release." |
52 | | - ) |
53 | | - |
54 | | - if sys.version_info[1] <= MINIMUM_PYTHON_VERSION[1]: |
55 | | - warn( |
56 | | - f"Python {py_ver} is not being tested or officially supported. " |
57 | | - "It is recommended you use a newer version of Python. " |
58 | | - f"The mininimum supported and tested version is {py_ver_min}.\n\n" |
59 | | - "**This warning is shown only the first time you run PyMAPDL.**\n" |
60 | | - ) |
61 | | - |
62 | | - with open(first_time_file, "w") as fid: |
63 | | - fid.write("") |
64 | | - |
65 | | -EXAMPLES_PATH = os.path.join(USER_DATA_PATH, "examples") |
| 35 | +from platformdirs import user_data_dir |
66 | 36 |
|
| 37 | +############################################################################### |
| 38 | +# Logging |
| 39 | +# ======= |
| 40 | +# |
67 | 41 | from ansys.mapdl.core.logging import Logger |
68 | 42 |
|
69 | 43 | LOG = Logger(level=logging.ERROR, to_file=False, to_stdout=True) |
70 | 44 | LOG.debug("Loaded logging module as LOG") |
71 | 45 |
|
| 46 | +############################################################################### |
| 47 | +# Globals |
| 48 | +# ======= |
| 49 | +# |
| 50 | +from ansys.mapdl.core.helpers import is_installed, run_every_import, run_first_time |
72 | 51 |
|
73 | | -BUILDING_GALLERY = False |
74 | | -RUNNING_TESTS = False |
75 | | - |
76 | | -if RUNNING_TESTS: # pragma: no cover |
77 | | - LOG.debug("Running tests on Pytest") |
78 | | - |
79 | | -_LOCAL_PORTS = [] |
80 | | - |
| 52 | +__version__: str = importlib_metadata.version(__name__.replace(".", "-")) |
81 | 53 |
|
82 | | -try: |
83 | | - from ansys.tools.visualization_interface import Plotter |
| 54 | +# A dictionary relating PyMAPDL server versions with the unified install ones |
| 55 | +VERSION_MAP: Dict[Tuple[int, int, int], str] = { |
| 56 | + (0, 0, 0): "2020R2", |
| 57 | + (0, 3, 0): "2021R1", |
| 58 | + (0, 4, 0): "2021R2", |
| 59 | + (0, 4, 1): "2021R2", |
| 60 | + (0, 5, 0): "2022R1", |
| 61 | + (0, 5, 1): "2022R2", |
| 62 | +} |
84 | 63 |
|
85 | | - _HAS_VISUALIZER = True |
86 | | -except ModuleNotFoundError: # pragma: no cover |
87 | | - LOG.debug("The module 'ansys-tools-visualization_interface' is not installed.") |
88 | | - _HAS_VISUALIZER = False |
| 64 | +BUILDING_GALLERY: bool = False |
| 65 | +RUNNING_TESTS: bool = False |
89 | 66 |
|
90 | | -try: |
91 | | - import pyvista as pv |
| 67 | +DEPRECATING_MINIMUM_PYTHON_VERSION: bool = True |
| 68 | +MINIMUM_PYTHON_VERSION: Tuple[int, int] = (3, 10) |
92 | 69 |
|
93 | | - _HAS_PYVISTA = True |
94 | | -except ModuleNotFoundError: # pragma: no cover |
95 | | - LOG.debug("The module 'pyvista' is not installed.") |
96 | | - _HAS_PYVISTA = False |
| 70 | +# Import related globals |
| 71 | +_HAS_ATP: bool = is_installed("ansys.tools.path") |
| 72 | +_HAS_PIM: bool = is_installed("ansys.platform.instancemanagement") |
| 73 | +_HAS_PYANSYS_REPORT: bool = is_installed("ansys.tools.report") |
| 74 | +_HAS_PYVISTA: bool = is_installed("pyvista") |
| 75 | +_HAS_TQDM: bool = is_installed("tqdm") |
| 76 | +_HAS_VISUALIZER: bool = is_installed("ansys.tools.visualization_interface") |
97 | 77 |
|
| 78 | +# Setup directories |
| 79 | +USER_DATA_PATH: str = user_data_dir(appname="ansys_mapdl_core", appauthor="Ansys") |
| 80 | +EXAMPLES_PATH = os.path.join(USER_DATA_PATH, "examples") |
98 | 81 |
|
99 | | -try: |
100 | | - import importlib.metadata as importlib_metadata |
101 | | -except ModuleNotFoundError: # pragma: no cover |
102 | | - import importlib_metadata |
| 82 | +# Store local ports |
| 83 | +_LOCAL_PORTS: List[int] = [] |
103 | 84 |
|
104 | | -__version__ = importlib_metadata.version(__name__.replace(".", "-")) |
| 85 | +############################################################################### |
| 86 | +# First time |
| 87 | +# ========== |
| 88 | +# |
| 89 | +# This function runs only the first time PyMAPDL is importad after it is installed. |
| 90 | +# It creates the required directories and raise Python version related warnings. |
| 91 | +# |
| 92 | +run_first_time() |
105 | 93 |
|
106 | | -try: |
107 | | - from ansys.tools.path.path import ( |
108 | | - change_default_ansys_path, |
109 | | - find_ansys, |
110 | | - get_ansys_path, |
111 | | - get_available_ansys_installations, |
112 | | - save_ansys_path, |
113 | | - ) |
114 | | -except: |
115 | | - # We don't really use these imports in the library. They are here for |
116 | | - # convenience. |
117 | | - pass |
| 94 | +############################################################################### |
| 95 | +# Runs every time |
| 96 | +# =============== |
| 97 | +# |
| 98 | +# This function runs every time that PyMAPDL is imported. |
| 99 | +# |
| 100 | +run_every_import() |
118 | 101 |
|
| 102 | +############################################################################### |
| 103 | +# Library imports |
| 104 | +# =============== |
| 105 | +# |
119 | 106 | from ansys.mapdl.core._version import SUPPORTED_ANSYS_VERSIONS |
120 | 107 | from ansys.mapdl.core.convert import convert_apdl_block, convert_script |
121 | 108 | from ansys.mapdl.core.launcher import close_all_local_instances |
|
131 | 118 | from ansys.mapdl.core.misc import Report, _check_has_ansys |
132 | 119 | from ansys.mapdl.core.pool import MapdlPool |
133 | 120 |
|
134 | | -_HAS_ANSYS = _check_has_ansys() |
| 121 | +############################################################################### |
| 122 | +# Convenient imports |
| 123 | +# ================== |
| 124 | +# |
| 125 | +# For compatibility with other versions or for convenience |
| 126 | +if _HAS_ATP: |
| 127 | + from ansys.tools.path.path import ( |
| 128 | + change_default_ansys_path, |
| 129 | + find_ansys, |
| 130 | + get_ansys_path, |
| 131 | + get_available_ansys_installations, |
| 132 | + save_ansys_path, |
| 133 | + ) |
135 | 134 |
|
136 | 135 | if _HAS_VISUALIZER: |
137 | | - from ansys.mapdl.core.plotting.theme import _apply_default_theme |
138 | | - |
139 | | - _apply_default_theme() |
140 | | - |
141 | | -BUILDING_GALLERY = False |
142 | | -RUNNING_TESTS = False |
143 | | - |
144 | | - |
145 | | -VERSION_MAP = { |
146 | | - (0, 0, 0): "2020R2", |
147 | | - (0, 3, 0): "2021R1", |
148 | | - (0, 4, 0): "2021R2", |
149 | | - (0, 4, 1): "2021R2", |
150 | | - (0, 5, 0): "2022R1", |
151 | | - (0, 5, 1): "2022R2", # as of 21 Mar 2022 unreleased |
152 | | -} |
153 | | -"""A dictionary relating PyMAPDL server versions with the unified install ones.""" |
| 136 | + from ansys.tools.visualization_interface import Plotter |
0 commit comments