Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix removal of imp module in Python 3.12 #2048

Merged
merged 1 commit into from
Nov 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions swig/openscap_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,24 @@

logger = logging.getLogger("openscap")

from sys import version_info
if version_info >= (2, 6, 0):
def _import_helper():
from os.path import dirname
import imp
fp = None
try:
fp, pathname, description = imp.find_module(
'_openscap_py', [dirname(__file__)])
except ImportError:
import _openscap_py as OSCAP
return OSCAP
if fp is not None:
try:
_mod = imp.load_module(
'_openscap_py', fp, pathname, description)
finally:
fp.close()
return _mod
OSCAP = _import_helper()
del _import_helper
else:
import _openscap_py as OSCAP

del version_info

def _import_helper():
from os.path import dirname
import importlib.machinery
import importlib.util
spec = importlib.machinery.PathFinder.find_spec('_openscap_py', [dirname(__file__)])
if not spec:
spec = importlib.machinery.PathFinder.find_spec('_openscap_py')
if not spec:
raise ImportError("Unable to import _openscap_py module, extra path: '%s'."
% dirname(__file__))
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod


OSCAP = _import_helper()
del _import_helper

import os

Expand Down