Skip to content

Commit e6a32b5

Browse files
committed
Fix cli and relative imports
1 parent 0e2fe70 commit e6a32b5

File tree

3 files changed

+18
-12
lines changed

3 files changed

+18
-12
lines changed

InteractiveHtmlBom/__init__.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66
import wx
77
import wx.aui
88

9-
from .generate_interactive_bom import GenerateInteractiveBomPlugin
10-
119

1210
def check_for_bom_button():
1311
# From Miles McCoo's blog
@@ -42,12 +40,15 @@ def callback(_):
4240
top_tb.Realize()
4341

4442

45-
plugin = GenerateInteractiveBomPlugin()
46-
plugin.register()
43+
if wx.GetApp():
44+
from .generate_interactive_bom import GenerateInteractiveBomPlugin
45+
46+
plugin = GenerateInteractiveBomPlugin()
47+
plugin.register()
4748

48-
# Add a button the hacky way if plugin button is not supported
49-
# in pcbnew, unless this is linux.
50-
if not plugin.pcbnew_icon_support and not sys.platform.startswith('linux'):
51-
t = threading.Thread(target=check_for_bom_button)
52-
t.daemon = True
53-
t.start()
49+
# Add a button the hacky way if plugin button is not supported
50+
# in pcbnew, unless this is linux.
51+
if not plugin.pcbnew_icon_support and not sys.platform.startswith('linux'):
52+
t = threading.Thread(target=check_for_bom_button)
53+
t.daemon = True
54+
t.start()

InteractiveHtmlBom/config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66
from wx import FileConfig
77

8-
from .dialog import settings_dialog
9-
108

119
class Config:
1210
# Helper constants

InteractiveHtmlBom/generate_interactive_bom.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@
99
import pcbnew
1010
import wx
1111

12+
if __name__ == "__main__":
13+
# Circumvent the "scripts can't do relative imports because they are not
14+
# packages" restriction by exerting dominance and making it a package!
15+
__package__ = os.path.basename(os.path.dirname(__file__))
16+
sys.path.insert(0, os.path.dirname(os.path.dirname(__file__)))
17+
__import__(__package__)
18+
1219
from . import dialog
1320
from . import units
1421
from .config import Config

0 commit comments

Comments
 (0)