Skip to content

Commit e095a3f

Browse files
committed
replace deprecated pkg_resources package
1 parent b790913 commit e095a3f

1 file changed

Lines changed: 12 additions & 3 deletions

File tree

femmt/functions.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
"""Contains different functions, used by the whole FEMMT functions."""
22
# Python standard libraries
33
import json
4-
import pkg_resources
54
import subprocess
65
import sys
76
import os
87
import warnings
98
from scipy.integrate import quad
109
import logging
10+
import importlib.metadata
11+
1112
# Third parry libraries
1213
import gmsh
1314
from matplotlib import pyplot as plt
@@ -18,7 +19,6 @@
1819
import schemdraw
1920
import schemdraw.elements as elm
2021

21-
2222
# Local libraries
2323
from femmt.constants import *
2424
from femmt.enumerations import ConductorType
@@ -845,11 +845,20 @@ def pm_core_inner_diameter_calculator(inner_core_diameter: float, hole_diameter:
845845

846846
return np.around(2 * np.sqrt(area_total / np.pi), decimals=4)
847847

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
848857

849858
def install_pyfemm_if_missing() -> None:
850859
"""Installs femm-software pip package in case of running on Windows machine. Windows users only."""
851860
required = {'pyfemm'}
852-
installed = {pkg.key for pkg in pkg_resources.working_set}
861+
installed = list_installed_packages()
853862
missing = required - installed
854863

855864
if missing:

0 commit comments

Comments
 (0)