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

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

Open
itzwam opened this issue Oct 1, 2023 · 0 comments · May be fixed by #280
Open

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

itzwam opened this issue Oct 1, 2023 · 0 comments · May be fixed by #280

Comments

@itzwam
Copy link

itzwam commented Oct 1, 2023

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 <[email protected]>
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant