Skip to content

Commit

Permalink
[Windows][macOS] KiCad plug-in detection
Browse files Browse the repository at this point in the history
See #642
  • Loading branch information
set-soft committed Jul 17, 2024
1 parent 6a032c0 commit 04228ed
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 21 deletions.
22 changes: 17 additions & 5 deletions kibot/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@
from .gs import GS
from . import dep_downloader
from .misc import (EXIT_BAD_ARGS, W_VARCFG, NO_PCBNEW_MODULE, W_NOKIVER, hide_stderr, TRY_INSTALL_CHECK, W_ONWIN,
FAILED_EXECUTE)
FAILED_EXECUTE, W_ONMAC)
from .pre_base import BasePreFlight
from .error import KiPlotConfigurationError, config_error
from .config_reader import (CfgYamlReader, print_outputs_help, print_output_help, print_preflights_help, create_example,
Expand Down Expand Up @@ -330,14 +330,17 @@ def detect_kicad():
GS.kicad_plugins_dirs.append(os.path.join(GS.kicad_conf_path, 'scripting'))
GS.kicad_plugins_dirs.append(os.path.join(GS.kicad_conf_path, 'scripting', 'plugins'))
# ~/.kicad_plugins and ~/.kicad
if 'HOME' in os.environ:
home = os.environ['HOME']
home = os.path.expanduser('~')
if home:
GS.kicad_plugins_dirs.append(os.path.join(home, '.kicad_plugins'))
GS.kicad_plugins_dirs.append(os.path.join(home, '.kicad', 'scripting'))
GS.kicad_plugins_dirs.append(os.path.join(home, '.kicad', 'scripting', 'plugins'))
if GS.kicad_version_major >= 6:
ver_dir = str(GS.kicad_version_major)+'.'+str(GS.kicad_version_minor)
local_share = os.path.join(home, '.local', 'share', 'kicad', ver_dir)
if GS.on_macos or GS.on_windows:
local_share = os.path.join(home, 'Documents', 'KiCad', ver_dir)
else:
local_share = os.path.join(home, '.local', 'share', 'kicad', ver_dir)
GS.kicad_plugins_dirs.append(os.path.join(local_share, 'scripting'))
GS.kicad_plugins_dirs.append(os.path.join(local_share, 'scripting', 'plugins'))
GS.kicad_plugins_dirs.append(os.path.join(local_share, '3rdparty', 'plugins')) # KiCad 6.0 PCM
Expand Down Expand Up @@ -403,6 +406,14 @@ def detect_windows(): # pragma: no cover (Windows)
logger.warning(W_ONWIN+'Running on Windows, this is experimental, please report any problem')


def detect_macos(): # pragma: no cover (Darwin)
if platform.system() != 'Darwin':
return
# Note: We assume this is the Python from KiCad, but we should check it ...
GS.on_macos = True
logger.warning(W_ONMAC+'Running on macOS, this is experimental, please report any problem')


def check_needs_convert():
""" Try to convert Altium PCBs to KiCad.
If successful just use the converted file. """
Expand Down Expand Up @@ -442,8 +453,9 @@ def main():
apply_warning_filter(args)
log.stop_on_warnings = args.stop_on_warnings
# Now we have the debug level set we can check (and optionally inform) KiCad info
detect_kicad()
detect_windows()
detect_macos()
detect_kicad()
debug_arguments(args)

# Force iBoM to avoid the use of graphical stuff
Expand Down
1 change: 1 addition & 0 deletions kibot/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ class GS(object):
kibot_version = None
n = datetime.now()
on_windows = False
on_macos = False
kicad_version = ''
kicad_conf_path = None
kicad_share_path = None
Expand Down
1 change: 1 addition & 0 deletions kibot/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@
W_NOQR = '(W160) '
W_NOFOOTP = '(W161) '
W_CHKFLD = '(W162) '
W_ONMAC = '(W163) '
# Somehow arbitrary, the colors are real, but can be different
PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"}
PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'enepig': "cfb96e",
Expand Down
18 changes: 10 additions & 8 deletions src/kibot-check
Original file line number Diff line number Diff line change
Expand Up @@ -1395,8 +1395,8 @@ def check_tool_binary_python(name):


def check_tool_binary_local(name):
home = os.environ.get('HOME') or os.environ.get('username')
if home is None:
home = os.path.expanduser('~')
if not home:
return None
home_bin = os.path.join(home, '.local', 'share', 'kibot', 'bin')
full_name = os.path.join(home_bin, name)
Expand Down Expand Up @@ -1702,7 +1702,7 @@ if args.show_paths:
print(' '+os.__file__)
print(' '+str(which('python3')))
# KiCad
home = None
home = os.path.expanduser('~')
try:
import pcbnew
kicad_ok = True
Expand All @@ -1725,8 +1725,7 @@ try:
kicad_plugins_dirs.append(os.path.join(kicad_conf_path, 'scripting'))
kicad_plugins_dirs.append(os.path.join(kicad_conf_path, 'scripting', 'plugins'))
# ~/.kicad_plugins and ~/.kicad
if 'HOME' in os.environ:
home = os.environ['HOME']
if home:
kicad_plugins_dirs.append(os.path.join(home, '.kicad_plugins'))
kicad_plugins_dirs.append(os.path.join(home, '.kicad', 'scripting'))
kicad_plugins_dirs.append(os.path.join(home, '.kicad', 'scripting', 'plugins'))
Expand Down Expand Up @@ -1765,7 +1764,10 @@ if kicad_ok:
if kicad_version[0] >= 6 and home:
# KiCad 6.0 PCM
ver_dir = str(kicad_version[0])+'.'+str(kicad_version[1])
local_share = os.path.join(home, '.local', 'share', 'kicad', ver_dir)
if system == 'Linux':
local_share = os.path.join(home, '.local', 'share', 'kicad', ver_dir)
else:
local_share = os.path.join(home, 'Documents', 'KiCad', ver_dir)
kicad_plugins_dirs.append(os.path.join(local_share, 'scripting'))
kicad_plugins_dirs.append(os.path.join(local_share, 'scripting', 'plugins'))
kicad_plugins_dirs.append(os.path.join(local_share, '3rdparty', 'plugins')) # KiCad 6.0 PCM
Expand Down Expand Up @@ -1877,9 +1879,9 @@ elif which('pip'):
if not os_ok:
print(sev2color(4)+'* KiBot is currently tested under Linux')
if system == 'Darwin':
print(' MacOSX should be supported for KiCad 6.x')
print(' MacOSX should be supported for KiCad 6.x or newer')
elif system == 'Windows':
print(' Windows may work with some limitations for KiCad 6.x')
print(' Windows may work with some limitations for KiCad 6.x or newer')
print(' Consider using a docker image, Windows docker can run Linux images (using virtualization)')
print(' You can also try WSL (Windows Subsystem for Linux)')
else:
Expand Down
18 changes: 10 additions & 8 deletions src/kibot-check.in
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def check_tool_binary_python(name):


def check_tool_binary_local(name):
home = os.environ.get('HOME') or os.environ.get('username')
if home is None:
home = os.path.expanduser('~')
if not home:
return None
home_bin = os.path.join(home, '.local', 'share', 'kibot', 'bin')
full_name = os.path.join(home_bin, name)
Expand Down Expand Up @@ -358,7 +358,7 @@ if args.show_paths:
print(' '+os.__file__)
print(' '+str(which('python3')))
# KiCad
home = None
home = os.path.expanduser('~')
try:
import pcbnew
kicad_ok = True
Expand All @@ -381,8 +381,7 @@ try:
kicad_plugins_dirs.append(os.path.join(kicad_conf_path, 'scripting'))
kicad_plugins_dirs.append(os.path.join(kicad_conf_path, 'scripting', 'plugins'))
# ~/.kicad_plugins and ~/.kicad
if 'HOME' in os.environ:
home = os.environ['HOME']
if home:
kicad_plugins_dirs.append(os.path.join(home, '.kicad_plugins'))
kicad_plugins_dirs.append(os.path.join(home, '.kicad', 'scripting'))
kicad_plugins_dirs.append(os.path.join(home, '.kicad', 'scripting', 'plugins'))
Expand Down Expand Up @@ -421,7 +420,10 @@ if kicad_ok:
if kicad_version[0] >= 6 and home:
# KiCad 6.0 PCM
ver_dir = str(kicad_version[0])+'.'+str(kicad_version[1])
local_share = os.path.join(home, '.local', 'share', 'kicad', ver_dir)
if system == 'Linux':
local_share = os.path.join(home, '.local', 'share', 'kicad', ver_dir)
else:
local_share = os.path.join(home, 'Documents', 'KiCad', ver_dir)
kicad_plugins_dirs.append(os.path.join(local_share, 'scripting'))
kicad_plugins_dirs.append(os.path.join(local_share, 'scripting', 'plugins'))
kicad_plugins_dirs.append(os.path.join(local_share, '3rdparty', 'plugins')) # KiCad 6.0 PCM
Expand Down Expand Up @@ -533,9 +535,9 @@ elif which('pip'):
if not os_ok:
print(sev2color(4)+'* KiBot is currently tested under Linux')
if system == 'Darwin':
print(' MacOSX should be supported for KiCad 6.x')
print(' MacOSX should be supported for KiCad 6.x or newer')
elif system == 'Windows':
print(' Windows may work with some limitations for KiCad 6.x')
print(' Windows may work with some limitations for KiCad 6.x or newer')
print(' Consider using a docker image, Windows docker can run Linux images (using virtualization)')
print(' You can also try WSL (Windows Subsystem for Linux)')
else:
Expand Down

0 comments on commit 04228ed

Please sign in to comment.