Tests: Make kicad docker image configurable

This commit is contained in:
jaseg 2024-11-06 14:49:36 +01:00
parent 091ee84910
commit 1a854b1812
2 changed files with 13 additions and 5 deletions

View file

@ -8,7 +8,7 @@ from itertools import chain
import pytest
from .image_support import ImageDifference, run_cargo_cmd, bulk_populate_kicad_fp_export_cache
from .image_support import ImageDifference, run_cargo_cmd, bulk_populate_kicad_fp_export_cache, KICAD_CONTAINER
def pytest_assertrepr_compare(op, left, right):
if isinstance(left, ImageDifference) or isinstance(right, ImageDifference):
@ -56,7 +56,7 @@ def pytest_configure(config):
raise ValueError(f'Path "{lib_dir}" given by KICAD_FOOTPRINTS environment variable does not exist or is not a directory.')
print('Updating podman image')
subprocess.run(['podman', 'pull', 'registry.hub.docker.com/kicad/kicad:nightly'], check=True)
subprocess.run(['podman', 'pull', KICAD_CONTAINER], check=True)
print('Checking and bulk re-building KiCad footprint library cache')
with multiprocessing.pool.ThreadPool() as pool: # use thread pool here since we're only monitoring podman processes

View file

@ -40,6 +40,8 @@ from PIL import Image
cachedir = Path(__file__).parent / 'image_cache'
cachedir.mkdir(exist_ok=True)
KICAD_CONTAINER = os.environ.get('KICAD_CONTAINER', 'registry.hub.docker.com/kicad/kicad:nightly')
@total_ordering
class ImageDifference:
def __init__(self, value, histogram):
@ -169,7 +171,7 @@ def kicad_fp_export(mod_file, out_svg):
'--userns=keep-id', # To allow container to read from bind mount
'--mount', f'type=bind,src={pretty_dir},dst=/{pretty_dir.name}',
'--mount', f'type=bind,src={tmpdir},dst=/out',
'registry.hub.docker.com/kicad/kicad:nightly',
KICAD_CONTAINER,
'kicad-cli', 'fp', 'export', 'svg', '--output', '/out', '--footprint', fp_name, f'/{pretty_dir.name}']
subprocess.run(cmd, check=True) #, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
out_file = Path(tmpdir) / f'{fp_name}.svg'
@ -199,9 +201,15 @@ def bulk_populate_kicad_fp_export_cache(pretty_dir):
'--userns=keep-id', # To allow container to read from bind mount
'--mount', f'type=bind,src={pretty_dir},dst=/{pretty_dir.name}',
'--mount', f'type=bind,src={tmpdir},dst=/out',
'registry.hub.docker.com/kicad/kicad:nightly',
KICAD_CONTAINER,
'kicad-cli', 'fp', 'export', 'svg', '--output', '/out', f'/{pretty_dir.name}']
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL)
try:
subprocess.run(cmd, check=True, stdout=subprocess.DEVNULL)
except subprocess.CalledProcessError as e:
print('Error running command with command line:', ' '.join(e.cmd), file=sys.stderr)
raise e
for fn in mod_files:
out_file = Path(tmpdir) / fn.with_suffix('.svg').name