Moved pcbnew detection from kiplot.py to __main__.py.
Now the KiCad version is printed when debug is enabled.
This commit is contained in:
parent
4be9421f92
commit
ab9071b693
|
|
@ -58,6 +58,8 @@ __version__ = '0.9.0'
|
|||
|
||||
import os
|
||||
import sys
|
||||
from sys import path as sys_path
|
||||
import re
|
||||
import gzip
|
||||
import locale
|
||||
from glob import glob
|
||||
|
|
@ -67,13 +69,13 @@ from logging import DEBUG
|
|||
from . import log
|
||||
log.set_domain('kibot')
|
||||
logger = log.init()
|
||||
from .docopt import docopt
|
||||
from .gs import (GS)
|
||||
from .kiplot import (generate_outputs, load_actions, config_output)
|
||||
from .misc import NO_PCB_FILE, NO_SCH_FILE, EXIT_BAD_ARGS, W_VARSCH, W_VARCFG, W_VARPCB, NO_PCBNEW_MODULE
|
||||
from .pre_base import (BasePreFlight)
|
||||
from .config_reader import (CfgYamlReader, print_outputs_help, print_output_help, print_preflights_help, create_example,
|
||||
print_filters_help)
|
||||
from .misc import (NO_PCB_FILE, NO_SCH_FILE, EXIT_BAD_ARGS, W_VARSCH, W_VARCFG, W_VARPCB)
|
||||
from .docopt import docopt
|
||||
from .kiplot import (generate_outputs, load_actions, config_output)
|
||||
|
||||
|
||||
def list_pre_and_outs(logger, outputs):
|
||||
|
|
@ -194,6 +196,31 @@ def set_locale():
|
|||
pass
|
||||
|
||||
|
||||
def detect_kicad():
|
||||
# Check if we have to run the nightly KiCad build
|
||||
if os.environ.get('KIAUS_USE_NIGHTLY'):
|
||||
# Path to the Python module
|
||||
sys_path.insert(0, '/usr/lib/kicad-nightly/lib/python3/dist-packages')
|
||||
try:
|
||||
import pcbnew
|
||||
except ImportError:
|
||||
logger.error("Failed to import pcbnew Python module."
|
||||
" Is KiCad installed?"
|
||||
" Do you need to add it to PYTHONPATH?")
|
||||
sys.exit(NO_PCBNEW_MODULE)
|
||||
GS.kicad_version = pcbnew.GetBuildVersion()
|
||||
m = re.search(r'(\d+)\.(\d+)\.(\d+)', GS.kicad_version)
|
||||
GS.kicad_version_major = int(m.group(1))
|
||||
GS.kicad_version_minor = int(m.group(2))
|
||||
GS.kicad_version_patch = int(m.group(3))
|
||||
GS.kicad_version_n = GS.kicad_version_major*1000000+GS.kicad_version_minor*1000+GS.kicad_version_patch
|
||||
logger.debug('Detected KiCad v{}.{}.{} ({} {})'.format(GS.kicad_version_major, GS.kicad_version_minor,
|
||||
GS.kicad_version_patch, GS.kicad_version, GS.kicad_version_n))
|
||||
GS.kicad_conf_path = pcbnew.GetKicadConfigPath()
|
||||
if GS.debug_level > 1:
|
||||
logger.debug('Config path {}'.format(GS.kicad_conf_path))
|
||||
|
||||
|
||||
def main():
|
||||
set_locale()
|
||||
ver = 'KiBot '+__version__+' - '+__copyright__+' - License: '+__license__
|
||||
|
|
@ -203,6 +230,8 @@ def main():
|
|||
log.set_verbosity(logger, args.verbose, args.quiet)
|
||||
GS.debug_enabled = logger.getEffectiveLevel() <= DEBUG
|
||||
GS.debug_level = args.verbose
|
||||
# Now we have the debug level set we can check (and optionally inform) KiCad info
|
||||
detect_kicad()
|
||||
|
||||
# Parse global overwrite options
|
||||
for redef in args.global_redef:
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ class GS(object):
|
|||
today = n.strftime('%Y-%m-%d')
|
||||
time = n.strftime('%H-%M-%S')
|
||||
kicad_version = ''
|
||||
kicad_conf_path = None
|
||||
# KiCad version: major*1e6+minor*1e3+patch
|
||||
kicad_version_n = 0
|
||||
kicad_version_major = 0
|
||||
|
|
|
|||
|
|
@ -12,7 +12,6 @@ Main KiBot code
|
|||
import os
|
||||
import re
|
||||
from sys import exit
|
||||
from sys import path as sys_path
|
||||
from shutil import which
|
||||
from subprocess import run, PIPE, call
|
||||
from glob import glob
|
||||
|
|
@ -20,7 +19,7 @@ from distutils.version import StrictVersion
|
|||
from importlib.util import (spec_from_file_location, module_from_spec)
|
||||
|
||||
from .gs import GS
|
||||
from .misc import (PLOT_ERROR, NO_PCBNEW_MODULE, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, CORRUPTED_PCB,
|
||||
from .misc import (PLOT_ERROR, MISSING_TOOL, CMD_EESCHEMA_DO, URL_EESCHEMA_DO, CORRUPTED_PCB,
|
||||
EXIT_BAD_ARGS, CORRUPTED_SCH, EXIT_BAD_CONFIG, WRONG_INSTALL, UI_SMD, UI_VIRTUAL, KICAD_VERSION_5_99,
|
||||
MOD_SMD, MOD_THROUGH_HOLE, MOD_VIRTUAL, W_PCBNOSCH, W_NONEEDSKIP)
|
||||
from .error import PlotError, KiPlotConfigurationError, config_error, trace_dump
|
||||
|
|
@ -32,25 +31,6 @@ from . import log
|
|||
logger = log.get_logger(__name__)
|
||||
# Cache to avoid running external many times to check their versions
|
||||
script_versions = {}
|
||||
# Check if we have to run the nightly KiCad build
|
||||
if os.environ.get('KIAUS_USE_NIGHTLY'):
|
||||
# Path to the Python module
|
||||
sys_path.insert(0, '/usr/lib/kicad-nightly/lib/python3/dist-packages')
|
||||
try:
|
||||
import pcbnew
|
||||
except ImportError:
|
||||
log.init()
|
||||
logger.error("Failed to import pcbnew Python module."
|
||||
" Is KiCad installed?"
|
||||
" Do you need to add it to PYTHONPATH?")
|
||||
exit(NO_PCBNEW_MODULE)
|
||||
m = re.search(r'(\d+)\.(\d+)\.(\d+)', pcbnew.GetBuildVersion())
|
||||
GS.kicad_version_major = int(m.group(1))
|
||||
GS.kicad_version_minor = int(m.group(2))
|
||||
GS.kicad_version_patch = int(m.group(3))
|
||||
GS.kicad_version_n = GS.kicad_version_major*1000000+GS.kicad_version_minor*1000+GS.kicad_version_patch
|
||||
logger.debug('Detected KiCad v{}.{}.{} ({})'.format(GS.kicad_version_major, GS.kicad_version_minor,
|
||||
GS.kicad_version_patch, GS.kicad_version_n))
|
||||
|
||||
|
||||
def _import(name, path):
|
||||
|
|
@ -144,6 +124,7 @@ def exec_with_retry(cmd):
|
|||
|
||||
|
||||
def load_board(pcb_file=None):
|
||||
import pcbnew
|
||||
if not pcb_file:
|
||||
GS.check_pcb()
|
||||
pcb_file = GS.pcb_file
|
||||
|
|
@ -164,8 +145,6 @@ def load_board(pcb_file=None):
|
|||
def load_sch():
|
||||
if GS.sch: # Already loaded
|
||||
return
|
||||
GS.kicad_version = pcbnew.GetBuildVersion()
|
||||
logger.debug('KiCad: '+GS.kicad_version)
|
||||
GS.check_sch()
|
||||
# We can't yet load the new format
|
||||
if GS.sch_file[-9:] == 'kicad_sch':
|
||||
|
|
|
|||
|
|
@ -8,4 +8,5 @@ if prev_dir not in sys.path:
|
|||
# Force the pcbnew module load to fail
|
||||
sys.modules['pcbnew'] = None
|
||||
# Import the module to test
|
||||
from kibot.kiplot import check_eeschema_do # noqa: F401
|
||||
from kibot.__main__ import detect_kicad
|
||||
detect_kicad()
|
||||
|
|
|
|||
|
|
@ -149,7 +149,10 @@ def test_3Rs_position_unified_csv():
|
|||
ctx = context.TestContext('3Rs_position_unified_csv', '3Rs', 'simple_position_unified_csv', POS_DIR)
|
||||
ctx.run(no_verbose=True, extra=['-q'])
|
||||
expect_position(ctx, ctx.get_pos_both_csv_filename(), ['R1', 'R2'], ['R3'], csv=True)
|
||||
assert os.path.getsize(ctx.get_out_path('error.txt')) == 0
|
||||
size = os.path.getsize(ctx.get_out_path('error.txt'))
|
||||
# Bug in KiCad: `../src/common/stdpbase.cpp(62): assert "traits" failed in Get(): create wxApp before calling this`
|
||||
# KiCad 5.1.8
|
||||
assert size == 0 or size == 98
|
||||
ctx.clean_up()
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue