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 pacgraph-tk regression for Python 3.12 #13

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 15 additions & 3 deletions pacgraph-tk
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,21 @@ from multiprocessing import Process
import sys, threading, queue, time

if not dev:
import imp
imp.load_source('pacgraph', '/usr/bin/pacgraph')
import pacgraph
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If dev = True is set to enable developement mode, import pacgraph from local folder should work. This MR moves all the importing of pacgraph into the if not dev: branch. Which renders the development mode broken (with no import).

Instead of hard coding the dev mode, we could first try to import pacgraph locally and catch the ImportError and only then attempt to do the import magic.

module_name = 'pacgraph'
module_path = '/usr/bin/pacgraph'
if sys.version_info[0] >= 3 and sys.version_info[1] >= 12:
import importlib.util
import importlib.machinery
loader = importlib.machinery.SourceFileLoader(module_name, module_path)
spec = importlib.util.spec_from_loader(module_name, loader)
if spec is None:
raise ImportError(f'Failed to load pacgraph module at {module_path}')
pacgraph = importlib.util.module_from_spec(spec)
loader.exec_module(pacgraph)
else:
import imp
imp.load_source(module_name, module_path)
import pacgraph

colors = {'sel' : '#000',
'uns' : '#888',
Expand Down