Skip to content

Commit

Permalink
[Quick Start][Any Diff] Avoid including when nothing to compare
Browse files Browse the repository at this point in the history
  • Loading branch information
set-soft committed Oct 16, 2024
1 parent d044d53 commit 25e22f8
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 45 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
the result.
- PcbDraw: problems with 0 ohms THT resistors (#689)

### Changed
- Quick Start:
- Diff/KiRi: Avoid creating when we don't have at least 2 to compare


## [1.8.1] - 2024-09-25
### Fixed
Expand Down
47 changes: 28 additions & 19 deletions docs/source/Changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ Fixed
compress the result.
- PcbDraw: problems with 0 ohms THT resistors (#689)

Changed
~~~~~~~

- Quick Start:

- Diff/KiRi: Avoid creating when we don’t have at least 2 to compare

[1.8.1] - 2024-09-25
--------------------

Expand Down Expand Up @@ -168,6 +175,8 @@ Fixed:
fills, that could generate huge lines in the generated PCB, not
supported by KiCad. (#660)

.. _changed-1:

Changed:
~~~~~~~~

Expand Down Expand Up @@ -297,7 +306,7 @@ Fixed
- Expansion of variables in fields could fail if the KiCad config
wasn’t initialized

.. _changed-1:
.. _changed-2:

Changed
~~~~~~~
Expand Down Expand Up @@ -327,7 +336,7 @@ Added
- Navigate results: A header and navigation bar (#582)
- BoM: support for SVG format in the logos (#383)

.. _changed-2:
.. _changed-3:

Changed
~~~~~~~
Expand Down Expand Up @@ -524,7 +533,7 @@ Added
- Added a new mode where we can control the added/removed colors
(#551)

.. _changed-3:
.. _changed-4:

Changed
~~~~~~~
Expand Down Expand Up @@ -749,7 +758,7 @@ Added
- ``quote_all``: forces quotes to all values in the CSV output. (See
#456)

.. _changed-4:
.. _changed-5:

Changed
~~~~~~~
Expand Down Expand Up @@ -929,7 +938,7 @@ Fixed

- ref_y coordinate not used. (#419)

.. _changed-5:
.. _changed-6:

Changed:
~~~~~~~~
Expand Down Expand Up @@ -1184,7 +1193,7 @@ Added

- Option to control the *SVG precision* (units scale)

.. _changed-6:
.. _changed-7:

Changed
~~~~~~~
Expand Down Expand Up @@ -1329,7 +1338,7 @@ Fixed
- Position: Components wrongly separated by side when the side column
wasn’t the last column (#313)

.. _changed-7:
.. _changed-8:

Changed
~~~~~~~
Expand Down Expand Up @@ -1432,7 +1441,7 @@ Fixed
when VAR isn’t defined. The old code tried to make it an absolute
path.

.. _changed-8:
.. _changed-9:

Changed
~~~~~~~
Expand Down Expand Up @@ -1495,7 +1504,7 @@ Fixed
orientation.
- svg_pcb_print: page orientation for portrait.

.. _changed-9:
.. _changed-10:

Changed
~~~~~~~
Expand Down Expand Up @@ -1655,7 +1664,7 @@ Added
- Support for ``--subst-models`` option for KiCad 6’s kicad2step.
(#137)

.. _changed-10:
.. _changed-11:

Changed
~~~~~~~
Expand Down Expand Up @@ -1746,7 +1755,7 @@ Added
- Basic KiCost support (**experimental**).
- Basic internal BoM and KiCost integration (**experimental**).

.. _changed-11:
.. _changed-12:

Changed
~~~~~~~
Expand Down Expand Up @@ -1858,7 +1867,7 @@ Added
- KiAuto time-out control.
- Now you can import outputs from another config file.

.. _changed-12:
.. _changed-13:

Changed
~~~~~~~
Expand Down Expand Up @@ -1905,7 +1914,7 @@ Added
- A filter to rotate footprints in the position file (#28).
- The step output now can download missing 3D models.

.. _changed-13:
.. _changed-14:

Changed
~~~~~~~
Expand Down Expand Up @@ -2018,7 +2027,7 @@ Fixed
[0.6.2] - 2020-08-25
--------------------

.. _changed-14:
.. _changed-15:

Changed
~~~~~~~
Expand Down Expand Up @@ -2051,7 +2060,7 @@ Added

- More robust behavior on GUI dependent commands.

.. _changed-15:
.. _changed-16:

Changed
~~~~~~~
Expand Down Expand Up @@ -2103,7 +2112,7 @@ Added
- ``error_number`` -> ``number``
- ``regexp`` -> ``regex``

.. _changed-16:
.. _changed-17:

Changed
~~~~~~~
Expand All @@ -2123,7 +2132,7 @@ Changed
[0.5.0] - 2020-07-11
--------------------

.. _changed-17:
.. _changed-18:

Changed
~~~~~~~
Expand Down Expand Up @@ -2229,7 +2238,7 @@ Added
- Better debug information when a BoM fails to be generated.
- Support for compressed YAML files.

.. _changed-18:
.. _changed-19:

Changed
~~~~~~~
Expand Down Expand Up @@ -2271,7 +2280,7 @@ Fixed
[0.2.4] - 2020-05-19
--------------------

.. _changed-19:
.. _changed-20:

Changed
~~~~~~~
Expand Down
15 changes: 15 additions & 0 deletions kibot/out_any_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# License: GPL-3.0
# Project: KiBot (formerly KiPlot)
import os
from subprocess import CalledProcessError
from .gs import GS
from .kiplot import run_command
from .out_base import VariantOptions
Expand All @@ -14,6 +15,20 @@
logger = log.get_logger()


def has_repo(git_command, file):
try:
run_command([git_command, 'ls-files', '--error-unmatch', file], change_to=os.path.dirname(file), just_raise=True)
except CalledProcessError:
logger.debug("File `{}` not inside a repo".format(file))
return 0
try:
res = run_command([git_command, 'log', '--oneline', '--', file], change_to=os.path.dirname(file), just_raise=True)
except CalledProcessError:
logger.debug("Failed to get log for `{}`".format(file))
return 0
return len(res.split('\n'))


class AnyDiffOptions(VariantOptions):
def __init__(self):
with document:
Expand Down
15 changes: 3 additions & 12 deletions kibot/out_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from .layer import Layer
from .misc import DIFF_TOO_BIG, FAILED_EXECUTE
from .registrable import RegOutput
from .out_any_diff import AnyDiffOptions
from .out_any_diff import AnyDiffOptions, has_repo
from .macros import macros, document, output_class # noqa: F401
from . import log

Expand Down Expand Up @@ -579,20 +579,11 @@ def config(self, parent):
def layer2dict(la):
return {'layer': la.layer, 'suffix': la.suffix, 'description': la.description}

@staticmethod
def has_repo(git_command, file):
try:
run_command([git_command, 'ls-files', '--error-unmatch', file], change_to=os.path.dirname(file), just_raise=True)
except CalledProcessError:
logger.debug("File `{}` not inside a repo".format(file))
return False
return True

@staticmethod
def get_conf_examples(name, layers):
outs = []
git_command = GS.check_tool(name, 'Git')
if GS.pcb_file and Diff.has_repo(git_command, GS.pcb_file):
if GS.pcb_file and has_repo(git_command, GS.pcb_file) > 1:
gb = {}
gb['name'] = 'basic_{}_pcb'.format(name)
gb['comment'] = 'PCB diff between the last two changes'
Expand All @@ -602,7 +593,7 @@ def get_conf_examples(name, layers):
gb['options'] = {'old': 'KIBOT_LAST-1', 'old_type': 'git', 'new': 'HEAD', 'new_type': 'git',
'cache_dir': os.path.abspath('.cache'), 'add_link_id': True}
outs.append(gb)
if GS.sch_file and Diff.has_repo(git_command, GS.sch_file):
if GS.sch_file and has_repo(git_command, GS.sch_file) > 1:
gb = {}
gb['name'] = 'basic_{}_sch'.format(name)
gb['comment'] = 'Schematic diff between the last two changes'
Expand Down
19 changes: 5 additions & 14 deletions kibot/out_kiri.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@
pass
import os
from shutil import copy2, rmtree
from subprocess import CalledProcessError
from .error import KiPlotConfigurationError
from .gs import GS
from .kicad.color_theme import load_color_theme
from .kiplot import load_any_sch, run_command
from .kiplot import load_any_sch
from .layer import Layer
from .misc import W_NOTHCMP
from .out_any_diff import AnyDiffOptions
from .out_any_diff import AnyDiffOptions, has_repo
from .macros import macros, document, output_class # noqa: F401
from . import log

Expand Down Expand Up @@ -368,23 +367,15 @@ def __init__(self):
def layer2dict(la):
return {'layer': la.layer, 'suffix': la.suffix, 'description': la.description}

@staticmethod
def has_repo(git_command, file):
try:
run_command([git_command, 'ls-files', '--error-unmatch', file], change_to=os.path.dirname(file), just_raise=True)
except CalledProcessError:
logger.debug("File `{}` not inside a repo".format(file))
return False
return True

@staticmethod
def get_conf_examples(name, layers):
outs = []
git_command = GS.check_tool(name, 'Git')
if not git_command or not GS.check_tool(name, 'KiDiff'):
return None
if (GS.pcb_file and GS.sch_file and KiRi.has_repo(git_command, GS.pcb_file) and
KiRi.has_repo(git_command, GS.sch_file)):
pcb_commits = has_repo(git_command, GS.pcb_file)
sch_commits = has_repo(git_command, GS.sch_file)
if GS.pcb_file and GS.sch_file and pcb_commits and sch_commits and (pcb_commits > 1 or sch_commits > 1):
ops = KiRiOptions()
ops.git_command = git_command
hashes, sch_dirty, pcb_dirty, _ = ops.collect_hashes()
Expand Down

0 comments on commit 25e22f8

Please sign in to comment.