|
1 | 1 | """Contains different functions, used by the whole FEMMT functions.""" |
2 | 2 | # Python standard libraries |
3 | 3 | import json |
4 | | -import pkg_resources |
5 | 4 | import subprocess |
6 | 5 | import sys |
7 | 6 | import os |
8 | 7 | import warnings |
9 | 8 | from scipy.integrate import quad |
10 | 9 | import logging |
| 10 | +import importlib.metadata |
| 11 | + |
11 | 12 | # Third parry libraries |
12 | 13 | import gmsh |
13 | 14 | from matplotlib import pyplot as plt |
|
18 | 19 | import schemdraw |
19 | 20 | import schemdraw.elements as elm |
20 | 21 |
|
21 | | - |
22 | 22 | # Local libraries |
23 | 23 | from femmt.constants import * |
24 | 24 | from femmt.enumerations import ConductorType |
@@ -845,11 +845,20 @@ def pm_core_inner_diameter_calculator(inner_core_diameter: float, hole_diameter: |
845 | 845 |
|
846 | 846 | return np.around(2 * np.sqrt(area_total / np.pi), decimals=4) |
847 | 847 |
|
| 848 | +def list_installed_packages() -> set: |
| 849 | + """"List installed python packages.""" |
| 850 | + distributions = importlib.metadata.distributions() |
| 851 | + installed_packages = [] |
| 852 | + for dist in distributions: |
| 853 | + args = dist.metadata['Name'] |
| 854 | + installed_packages.append(args) |
| 855 | + set_installed_packages = set(installed_packages) |
| 856 | + return set_installed_packages |
848 | 857 |
|
849 | 858 | def install_pyfemm_if_missing() -> None: |
850 | 859 | """Installs femm-software pip package in case of running on Windows machine. Windows users only.""" |
851 | 860 | required = {'pyfemm'} |
852 | | - installed = {pkg.key for pkg in pkg_resources.working_set} |
| 861 | + installed = list_installed_packages() |
853 | 862 | missing = required - installed |
854 | 863 |
|
855 | 864 | if missing: |
|
0 commit comments