Skip to content

Fails to import modules installed with python setuptools cuz they are .pyc #275

@itzwam

Description

@itzwam

Any module using .pyc extension is basically ignored, quick-fixed it using this patch, but not sure if it's the proper way

From c243c3ea1e44b1b9502f5ef56eea1f237de628c1 Mon Sep 17 00:00:00 2001
From: Itz 'toinux' Wam <root@epycfailgp.local>
Date: Sun, 1 Oct 2023 19:46:42 +0200
Subject: [PATCH 3/4] Support PYCompiled Modules

---
 ifupdown2/ifupdown/ifupdownmain.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/ifupdown2/ifupdown/ifupdownmain.py b/ifupdown2/ifupdown/ifupdownmain.py
index 51f5460..8bbc202 100644
--- a/ifupdown2/ifupdown/ifupdownmain.py
+++ b/ifupdown2/ifupdown/ifupdownmain.py
@@ -1433,6 +1433,8 @@ class ifupdownMain:
                         if self.modules.get(mname):
                             continue
                         mpath = modules_dir + '/' + mname + '.py'
+                        if not os.path.exists(mpath) and os.path.exists(mpath + 'c'):
+                            mpath = modules_dir + '/' + mname + '.pyc'
                         if os.path.exists(mpath) and mpath not in failed_import:
                             try:
                                 m = __import__(mname)
@@ -1447,7 +1449,7 @@ class ifupdownMain:
                                 self.overridden_ifupdown_scripts.extend(script_override)
                             except moduleNotSupported as e:
                                 self.logger.info('module %s not loaded (%s)'
-                                                 %(mname, str(e)))
+                                                %(mname, str(e)))
                                 continue
                             except Exception:
                                 raise
-- 
2.30.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions