|
| 1 | +"""Python post processing integrations for the Fluent solver.""" |
| 2 | +import platform |
| 3 | +import struct |
| 4 | +import sys |
| 5 | + |
| 6 | +import pkg_resources |
| 7 | + |
| 8 | +required_libraries = { |
| 9 | + "vtk": "9.1.0", |
| 10 | + "pyvista": "0.33.2", |
| 11 | + "pyvistaqt": "0.7.0", |
| 12 | + "pyside6": "6.2.3", |
| 13 | + "matplotlib": "3.5.1", |
| 14 | +} |
| 15 | + |
| 16 | + |
| 17 | +def _get_vtk_install_cmd(reinstall=False): |
| 18 | + is64 = struct.calcsize("P") * 8 == 64 |
| 19 | + if sys.version_info.minor == 10 and is64: |
| 20 | + if platform.system().lower() == "linux": |
| 21 | + return f" Please {'reinstall' if reinstall else 'install'} vtk with `pip install {'-I' if reinstall else ''} https://github.com/pyvista/pyvista-wheels/raw/main/vtk-9.1.0.dev0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl`" # noqa: E501 |
| 22 | + |
| 23 | + elif platform.system().lower() == "windows": |
| 24 | + return f" Please {'reinstall' if reinstall else 'install'} vtk with `pip install {'-I' if reinstall else ''} https://github.com/pyvista/pyvista-wheels/raw/main/vtk-9.1.0.dev0-cp310-cp310-win_amd64.whl`" # noqa: E501 |
| 25 | + else: |
| 26 | + return ( |
| 27 | + f" Please {'reinstall' if reinstall else 'install'} " |
| 28 | + f"vtk with `pip install vtk=={required_libraries[lib]}`." |
| 29 | + ) |
| 30 | + |
| 31 | + |
| 32 | +def _update_vtk_version(): |
| 33 | + is64 = struct.calcsize("P") * 8 == 64 |
| 34 | + if sys.version_info.minor in (9, 10) and is64: |
| 35 | + required_libraries.update({"vtk": "9.1.0.dev0"}) |
| 36 | + |
| 37 | + |
| 38 | +_update_vtk_version() |
| 39 | +installed = {pkg.key for pkg in pkg_resources.working_set} |
| 40 | +installed_libraries = [ |
| 41 | + lib for lib, version in required_libraries.items() if lib in installed |
| 42 | +] |
| 43 | +missing_libraries = required_libraries.keys() - installed |
| 44 | +import_errors = [] |
| 45 | +if missing_libraries: |
| 46 | + import_errors.append( |
| 47 | + (f"Required libraries {missing_libraries} " "are missing to use this feature.") |
| 48 | + ) |
| 49 | + for lib in missing_libraries: |
| 50 | + import_errors.append( |
| 51 | + ( |
| 52 | + f" Please install {lib} with " |
| 53 | + f"`pip install {lib}=={required_libraries[lib]}`." |
| 54 | + if lib != "vtk" |
| 55 | + else _get_vtk_install_cmd() |
| 56 | + ) |
| 57 | + ) |
| 58 | +if installed_libraries: |
| 59 | + versions_mismatched_message = False |
| 60 | + for lib in installed_libraries: |
| 61 | + required_version = required_libraries[lib] |
| 62 | + installed_version = pkg_resources.get_distribution(lib).version |
| 63 | + if pkg_resources.parse_version(installed_version) < pkg_resources.parse_version( |
| 64 | + required_version |
| 65 | + ): |
| 66 | + if not versions_mismatched_message: |
| 67 | + import_errors.append( |
| 68 | + ( |
| 69 | + f"Required libraries version is incompatible " |
| 70 | + "to use this feature." |
| 71 | + ) |
| 72 | + ) |
| 73 | + versions_mismatched_message = True |
| 74 | + import_errors.append( |
| 75 | + ( |
| 76 | + f" Please re-install {lib} with " |
| 77 | + f"`pip install -I {lib}=={required_libraries[lib]}`." |
| 78 | + if lib != "vtk" |
| 79 | + else _get_vtk_install_cmd(True) |
| 80 | + ) |
| 81 | + ) |
| 82 | + |
| 83 | +if import_errors: |
| 84 | + raise ImportError("\n".join(import_errors)) |
| 85 | +from ansys.fluent.post._config import get_config, set_config # noqa: F401 |
0 commit comments