Skip to content

Commit f2813ca

Browse files
committed
[KiRi][Added] Support for uninitialized submodules
Closes #888
1 parent 7d5eadd commit f2813ca

6 files changed

Lines changed: 26 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2626
- BoM: descriptive error when using `kicad` format and no options found.
2727
- DRC/ERC: Configurable logo (#889)
2828
- iBoM: `mark_when_checked` option (#881)
29+
- KiRi: Support for uninitialized submodules (#888)
2930
- Report: `buried_vias_count` for KiCad 10
3031

3132
### Fixed

docs/source/Changelog.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ Added
4848
found.
4949
- DRC/ERC: Configurable logo (#889)
5050
- iBoM: ``mark_when_checked`` option (#881)
51+
- KiRi: Support for uninitialized submodules (#888)
5152
- Report: ``buried_vias_count`` for KiCad 10
5253

5354
Fixed

kibot/kiplot.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,15 @@ def _run_command(command, change_to):
155155
return run(command, check=True, stdout=PIPE, stderr=STDOUT, cwd=change_to)
156156

157157

158-
def run_command(command, change_to=None, just_raise=False, use_x11=False, err_msg=None, err_lvl=FAILED_EXECUTE):
158+
def run_command(command, change_to=None, just_raise=False, use_x11=False, err_msg=None, err_lvl=FAILED_EXECUTE,
159+
force_en=False):
159160
logger.debug('- Executing: '+GS.pasteable_cmd(command))
160161
if change_to is not None:
161162
logger.debug('- CWD: '+change_to)
163+
old_lang = None
164+
if force_en:
165+
old_lang = os.environ['LANG']
166+
os.environ['LANG'] = 'en'
162167
try:
163168
if use_x11 and not GS.on_windows:
164169
logger.debug('Using Xvfb to run the command')
@@ -173,6 +178,10 @@ def run_command(command, change_to=None, just_raise=False, use_x11=False, err_ms
173178
if err_msg is not None:
174179
err_msg = err_msg.format(ret=e.returncode)
175180
GS.exit_with_error(err_msg, err_lvl, e)
181+
finally:
182+
if old_lang is not None:
183+
os.environ['LANG'] = old_lang
184+
176185
msg = try_decode_utf8(res.stdout, 'output from command', logger)
177186
debug_output(msg)
178187
return msg.rstrip()

kibot/misc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@
345345
W_IBOMNOCHK = '(W177) '
346346
W_PREREDEF = '(W178) '
347347
W_BURIEDVIAS = '(W179) '
348+
W_BADGITREPO = '(W180) '
348349
# Somehow arbitrary, the colors are real, but can be different
349350
PCB_MAT_COLORS = {'fr1': "937042", 'fr2': "949d70", 'fr3': "adacb4", 'fr4': "332B16", 'fr5': "6cc290"}
350351
PCB_FINISH_COLORS = {'hal': "8b898c", 'hasl': "8b898c", 'imag': "8b898c", 'enig': "cfb96e", 'enepig': "cfb96e",

kibot/out_any_diff.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ def add_to_cache(self, name, hash):
7070
def run_git(self, cmd, cwd=None, just_raise=False):
7171
if cwd is None:
7272
cwd = self.repo_dir
73-
return run_command([self.git_command]+cmd, change_to=cwd, just_raise=just_raise)
73+
return run_command([self.git_command]+cmd, change_to=cwd, just_raise=just_raise, force_en=True)
7474

7575
def git_dirty(self, file=None):
7676
ops = ['status', '--porcelain', '-uno']

kibot/out_kiri.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@
2828
pass
2929
import os
3030
from shutil import copy2, rmtree
31+
from subprocess import CalledProcessError
3132
from .error import KiPlotConfigurationError
3233
from .gs import GS
3334
from .kicad.color_theme import load_color_theme
3435
from .kiplot import load_any_sch
3536
from .layer import Layer
36-
from .misc import W_NOTHCMP
37+
from .misc import W_NOTHCMP, W_BADGITREPO, try_decode_utf8
3738
from .out_any_diff import AnyDiffOptions, has_repo
3839
from .macros import macros, document, output_class # noqa: F401
3940
from . import log
@@ -297,7 +298,16 @@ def run(self, name):
297298
git_tmp_wd = GS.mkdtemp('kiri-checkout')
298299
logger.debug('Checking out '+hash+' to '+git_tmp_wd)
299300
self.run_git(['worktree', 'add', '--detach', '--force', git_tmp_wd, hash])
300-
self.run_git(['submodule', 'update', '--init', '--recursive'], cwd=git_tmp_wd)
301+
try:
302+
self.run_git(['submodule', 'update', '--init', '--recursive'], cwd=git_tmp_wd, just_raise=True)
303+
except CalledProcessError as e:
304+
if b'No url found for submodule' in e.output:
305+
# Just an uninitialized submodule, report it and continue, see #888
306+
logger.warning(W_BADGITREPO+f"Broken git repo: {e}")
307+
msg = try_decode_utf8(e.output, 'output from command', logger)
308+
logger.warning(W_BADGITREPO+msg)
309+
else:
310+
raise
301311
# Generate SVGs for the schematic
302312
name_sch = self.do_cache(self.sch_rel_name, git_tmp_wd, hash)
303313
# Generate SVGs for the PCB

0 commit comments

Comments
 (0)