From 11773e920da9d0523e9de1e1f2dd4d86b2f442cb Mon Sep 17 00:00:00 2001 From: "Salvador E. Tropea" Date: Thu, 22 Dec 2022 08:44:46 -0300 Subject: [PATCH] [Windows][Fixed] Avoid asuming bash is part of the system Related to #325 --- README.md | 6 +++++ kibot/dep_downloader.py | 4 +++ kibot/pre_any_replace.py | 5 +++- kibot/pre_pcb_replace.py | 2 ++ kibot/pre_sch_replace.py | 2 ++ kibot/pre_set_text_variables.py | 7 ++++- src/kibot-check | 47 +++++++++++++++++++++++++++++++++ 7 files changed, 71 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 15d8e193..6fbd5482 100644 --- a/README.md +++ b/README.md @@ -206,6 +206,12 @@ Notes: - Create PDF, PNG, PS and EPS formats for `pcb_print` - Create PNG, JPG and BMP images for `pcbdraw` +[**Bash**](https://www.gnu.org/software/bash/) [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://www.gnu.org/software/bash/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/bash) +- Optional to: + - Run external commands to create replacement text for `pcb_replace` + - Run external commands to create replacement text for `sch_replace` + - Run external commands to create replacement text for `set_text_variables` + [**Ghostscript**](https://www.ghostscript.com/) [![Tool](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/llave-inglesa-22x22.png)](https://www.ghostscript.com/) [![Debian](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/debian-openlogo-22x22.png)](https://packages.debian.org/bullseye/ghostscript) ![Auto-download](https://raw.githubusercontent.com/INTI-CMNB/KiBot/master/docs/images/auto_download-22x22.png) - Optional to: - Create outputs preview for `navigate_results` diff --git a/kibot/dep_downloader.py b/kibot/dep_downloader.py index 6e2d5fb1..42f489f8 100644 --- a/kibot/dep_downloader.py +++ b/kibot/dep_downloader.py @@ -84,6 +84,10 @@ Dependencies: debian: xvfb arch: xorg-server-xvfb no_cmd_line_version: true + - name: Bash + url: https://www.gnu.org/software/bash/ + debian: bash + arch: bash """ import importlib import os diff --git a/kibot/pre_any_replace.py b/kibot/pre_any_replace.py index 86864cfd..9fff0dd7 100644 --- a/kibot/pre_any_replace.py +++ b/kibot/pre_any_replace.py @@ -93,6 +93,7 @@ class Base_Replace(BasePreFlight): # noqa: F821 content = f.read() os.environ['KIBOT_' + type(self)._context + '_NAME'] = file o = self._value + bash_command = None for r in o.replace_tags: text = r.text if not text: @@ -100,7 +101,9 @@ class Base_Replace(BasePreFlight): # noqa: F821 if re_git.search(command): git_command = self.ensure_tool('git') command = re_git.sub(r'\1'+git_command+' ', command) - cmd = ['/bin/bash', '-c', command] + if not bash_command: + bash_command = self.ensure_tool('Bash') + cmd = [bash_command, '-c', command] logger.debugl(2, 'Running: {}'.format(cmd)) result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) if result.returncode: diff --git a/kibot/pre_pcb_replace.py b/kibot/pre_pcb_replace.py index 81bd8189..89503b08 100644 --- a/kibot/pre_pcb_replace.py +++ b/kibot/pre_pcb_replace.py @@ -7,6 +7,8 @@ Dependencies: - from: Git role: Find commit hash and/or date + - from: Bash + role: Run external commands to create replacement text """ from .gs import GS from .pre_any_replace import TagReplaceBase, Base_ReplaceOptions, Base_Replace diff --git a/kibot/pre_sch_replace.py b/kibot/pre_sch_replace.py index 103c94e7..c6b21dbc 100644 --- a/kibot/pre_sch_replace.py +++ b/kibot/pre_sch_replace.py @@ -7,6 +7,8 @@ Dependencies: - from: Git role: Find commit hash and/or date + - from: Bash + role: Run external commands to create replacement text """ import os from .gs import GS diff --git a/kibot/pre_set_text_variables.py b/kibot/pre_set_text_variables.py index 11d1117a..74806997 100644 --- a/kibot/pre_set_text_variables.py +++ b/kibot/pre_set_text_variables.py @@ -7,6 +7,8 @@ Dependencies: - from: Git role: Find commit hash and/or date + - from: Bash + role: Run external commands to create replacement text """ import json import os @@ -114,6 +116,7 @@ class Set_Text_Variables(BasePreFlight): # noqa: F821 os.environ['KIBOT_PCB_NAME'] = GS.pcb_file if GS.sch_file: os.environ['KIBOT_SCH_NAME'] = GS.sch_file + bash_command = None for r in o: text = r.text if not text and r.command: @@ -121,7 +124,9 @@ class Set_Text_Variables(BasePreFlight): # noqa: F821 if re_git.search(command): git_command = self.ensure_tool('git') command = re_git.sub(r'\1'+git_command.replace('\\', r'\\')+' ', command) - cmd = ['/bin/bash', '-c', command] + if not bash_command: + bash_command = self.ensure_tool('Bash') + cmd = [bash_command, '-c', command] result = run(cmd, stdout=PIPE, stderr=PIPE, universal_newlines=True) if result.returncode: logger.error('Failed to execute:\n{}\nreturn code {}'.format(r.command, result.returncode)) diff --git a/src/kibot-check b/src/kibot-check index 09e4c71f..3193ed52 100755 --- a/src/kibot-check +++ b/src/kibot-check @@ -19,6 +19,53 @@ import subprocess import sys deps = '{\ + "Bash": {\ + "arch": "bash",\ + "command": "bash",\ + "comments": [],\ + "deb_package": "bash",\ + "downloader": null,\ + "downloader_str": null,\ + "extra_arch": null,\ + "extra_deb": null,\ + "help_option": "--version",\ + "importance": 3,\ + "in_debian": true,\ + "is_kicad_plugin": false,\ + "is_python": false,\ + "name": "Bash",\ + "no_cmd_line_version": false,\ + "no_cmd_line_version_old": false,\ + "output": "pcb_replace",\ + "plugin_dirs": null,\ + "pypi_name": "Bash",\ + "roles": [\ + {\ + "desc": "Run external commands to create replacement text",\ + "mandatory": false,\ + "max_version": null,\ + "output": "pcb_replace",\ + "version": null\ + },\ + {\ + "desc": "Run external commands to create replacement text",\ + "mandatory": false,\ + "max_version": null,\ + "output": "sch_replace",\ + "version": null\ + },\ + {\ + "desc": "Run external commands to create replacement text",\ + "mandatory": false,\ + "max_version": null,\ + "output": "set_text_variables",\ + "version": null\ + }\ + ],\ + "tests": [],\ + "url": "https://www.gnu.org/software/bash/",\ + "url_down": null\ + },\ "Colorama": {\ "arch": "python-colorama",\ "command": "colorama",\