Skip to content

Commit 5c2e1a5

Browse files
authored
Merge pull request #2871 to replace deprecated imp.load_source call
imp is deprecated and is getting removed in Python 3.12. This follows official suggestion for replacing imp.load_source calls from the documentation here: https://docs.python.org/3/whatsnew/3.12.html#imp
2 parents c202031 + 284c155 commit 5c2e1a5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

rmgpy/data/kinetics/database.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,15 @@ def load_recommended_families(self, filepath):
138138
139139
Both styles can be loaded by this method.
140140
"""
141-
import imp
141+
import importlib
142142

143143
# Load the recommended.py file as a module
144144
try:
145-
rec = imp.load_source('rec', filepath)
145+
# https://docs.python.org/3/whatsnew/3.12.html#imp
146+
loader = importlib.machinery.SourceFileLoader('rec', filepath)
147+
spec = importlib.util.spec_from_file_location('rec', filepath, loader=loader)
148+
rec = importlib.util.module_from_spec(spec)
149+
loader.exec_module(rec)
146150
except Exception as e:
147151
raise DatabaseError('Unable to load recommended.py file for kinetics families: {0!s}'.format(e))
148152

0 commit comments

Comments
 (0)