mirror of
https://github.com/konpa/devicon.git
synced 2025-08-12 09:34:36 +02:00
Python now print traceback
This commit is contained in:
1
.github/scripts/build_assets/filehandler.py
vendored
1
.github/scripts/build_assets/filehandler.py
vendored
@@ -214,6 +214,7 @@ def get_added_modified_svgs(files_changed_json_path: str):
|
|||||||
:return: a list of the svg file paths that were added/modified in this pr.
|
:return: a list of the svg file paths that were added/modified in this pr.
|
||||||
"""
|
"""
|
||||||
files_dict = get_json_file_content(files_changed_json_path)
|
files_dict = get_json_file_content(files_changed_json_path)
|
||||||
|
print(files_dict)
|
||||||
svgs = []
|
svgs = []
|
||||||
for file in files_dict["added"]:
|
for file in files_dict["added"]:
|
||||||
path = Path(file)
|
path = Path(file)
|
||||||
|
33
.github/scripts/build_assets/github_env.py
vendored
33
.github/scripts/build_assets/github_env.py
vendored
@@ -1,33 +0,0 @@
|
|||||||
import os
|
|
||||||
import platform
|
|
||||||
|
|
||||||
|
|
||||||
def set_env_var(key: str, value: str, delimiter: str='~'):
|
|
||||||
"""
|
|
||||||
Set the GitHub env variable of 'key' to 'value' using
|
|
||||||
the method specified here:
|
|
||||||
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
|
||||||
Support both Windows and Ubuntu machines provided by GitHub Actions.
|
|
||||||
|
|
||||||
:param: key, the name of the env variable.
|
|
||||||
:param: value, the value of the env variable.
|
|
||||||
:param: delimiter, the delimiter that you want to use
|
|
||||||
to write to the file. Only applicable if the 'value' contains
|
|
||||||
'\n' character aka a multiline string.
|
|
||||||
"""
|
|
||||||
if platform.system() == "Windows":
|
|
||||||
if "\n" in value:
|
|
||||||
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%')
|
|
||||||
os.system(f'echo "{value}" >> %GITHUB_ENV%')
|
|
||||||
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%')
|
|
||||||
else:
|
|
||||||
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%')
|
|
||||||
elif platform.system() == "Linux":
|
|
||||||
if "\n" in value:
|
|
||||||
os.system(f'echo "{key}<<{delimiter}" >> $GITHUB_ENV')
|
|
||||||
os.system(f'echo "{value}" >> $GITHUB_ENV')
|
|
||||||
os.system(f'echo "{delimiter}" >> $GITHUB_ENV')
|
|
||||||
else:
|
|
||||||
os.system(f'echo "{key}={value}" >> $GITHUB_ENV')
|
|
||||||
else:
|
|
||||||
raise Exception("This function doesn't support this platform: " + platform.system())
|
|
@@ -1,6 +1,19 @@
|
|||||||
from typing import List
|
from typing import List
|
||||||
import xml.etree.ElementTree as et
|
import xml.etree.ElementTree as et
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import os
|
||||||
|
import platform
|
||||||
|
import sys
|
||||||
|
import traceback
|
||||||
|
|
||||||
|
|
||||||
|
def exit_with_err(err: Exception):
|
||||||
|
"""
|
||||||
|
Exit the current step and display the err.
|
||||||
|
:param: err, the error/exception encountered.
|
||||||
|
"""
|
||||||
|
traceback.print_exc()
|
||||||
|
sys.exit(str(err))
|
||||||
|
|
||||||
|
|
||||||
def check_svgs(svg_file_paths: List[Path]):
|
def check_svgs(svg_file_paths: List[Path]):
|
||||||
@@ -50,4 +63,35 @@ def check_svgs(svg_file_paths: List[Path]):
|
|||||||
err_msgs.append("\n".join(err_msg))
|
err_msgs.append("\n".join(err_msg))
|
||||||
|
|
||||||
if len(err_msgs) > 0:
|
if len(err_msgs) > 0:
|
||||||
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
|
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs))
|
||||||
|
|
||||||
|
|
||||||
|
def set_env_var(key: str, value: str, delimiter: str='~'):
|
||||||
|
"""
|
||||||
|
Set the GitHub env variable of 'key' to 'value' using
|
||||||
|
the method specified here:
|
||||||
|
https://docs.github.com/en/free-pro-team@latest/actions/reference/workflow-commands-for-github-actions#setting-an-environment-variable
|
||||||
|
Support both Windows and Ubuntu machines provided by GitHub Actions.
|
||||||
|
|
||||||
|
:param: key, the name of the env variable.
|
||||||
|
:param: value, the value of the env variable.
|
||||||
|
:param: delimiter, the delimiter that you want to use
|
||||||
|
to write to the file. Only applicable if the 'value' contains
|
||||||
|
'\n' character aka a multiline string.
|
||||||
|
"""
|
||||||
|
if platform.system() == "Windows":
|
||||||
|
if "\n" in value:
|
||||||
|
os.system(f'echo "{key}<<{delimiter}" >> %GITHUB_ENV%')
|
||||||
|
os.system(f'echo "{value}" >> %GITHUB_ENV%')
|
||||||
|
os.system(f'echo "{delimiter}" >> %GITHUB_ENV%')
|
||||||
|
else:
|
||||||
|
os.system(f'echo "{key}={value}" >> %GITHUB_ENV%')
|
||||||
|
elif platform.system() == "Linux":
|
||||||
|
if "\n" in value:
|
||||||
|
os.system(f'echo "{key}<<{delimiter}" >> $GITHUB_ENV')
|
||||||
|
os.system(f'echo "{value}" >> $GITHUB_ENV')
|
||||||
|
os.system(f'echo "{delimiter}" >> $GITHUB_ENV')
|
||||||
|
else:
|
||||||
|
os.system(f'echo "{key}={value}" >> $GITHUB_ENV')
|
||||||
|
else:
|
||||||
|
raise Exception("This function doesn't support this platform: " + platform.system())
|
10
.github/scripts/check_svgs_monthly.py
vendored
10
.github/scripts/check_svgs_monthly.py
vendored
@@ -1,11 +1,10 @@
|
|||||||
from pathlib import Path
|
import traceback
|
||||||
import json
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
# pycharm complains that build_assets is an unresolved ref
|
# pycharm complains that build_assets is an unresolved ref
|
||||||
# don't worry about it, the script still runs
|
# don't worry about it, the script still runs
|
||||||
from build_assets import filehandler, arg_getters
|
from build_assets import filehandler, arg_getters
|
||||||
from build_assets import svg_checker
|
from build_assets import util
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -17,10 +16,11 @@ def main():
|
|||||||
try:
|
try:
|
||||||
devicon_json = filehandler.get_json_file_content(args.devicon_json_path)
|
devicon_json = filehandler.get_json_file_content(args.devicon_json_path)
|
||||||
svgs = filehandler.get_svgs_paths(devicon_json, args.icons_folder_path)
|
svgs = filehandler.get_svgs_paths(devicon_json, args.icons_folder_path)
|
||||||
svg_checker.check_svgs(svgs)
|
util.check_svgs(svgs)
|
||||||
print("All SVGs found were good. Task completed.")
|
print("All SVGs found were good. Task completed.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(str(e))
|
util.exit_with_err(e)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
8
.github/scripts/check_svgs_on_pr.py
vendored
8
.github/scripts/check_svgs_on_pr.py
vendored
@@ -5,7 +5,7 @@ import time
|
|||||||
# pycharm complains that build_assets is an unresolved ref
|
# pycharm complains that build_assets is an unresolved ref
|
||||||
# don't worry about it, the script still runs
|
# don't worry about it, the script still runs
|
||||||
from build_assets import filehandler, arg_getters
|
from build_assets import filehandler, arg_getters
|
||||||
from build_assets import github_env, svg_checker
|
from build_assets import util
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -19,11 +19,11 @@ def main():
|
|||||||
# check the svgs
|
# check the svgs
|
||||||
svgs = filehandler.get_added_modified_svgs(args.files_changed_json_path)
|
svgs = filehandler.get_added_modified_svgs(args.files_changed_json_path)
|
||||||
print("SVGs to check: ", *svgs, sep='\n')
|
print("SVGs to check: ", *svgs, sep='\n')
|
||||||
svg_checker.check_svgs(svgs)
|
util.check_svgs(svgs)
|
||||||
print("All SVGs found were good. Task completed.")
|
print("All SVGs found were good. Task completed.")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
github_env.set_env_var("SVG_ERR_MSGS", str(e))
|
util.set_env_var("SVG_ERR_MSGS", str(e))
|
||||||
sys.exit(str(e))
|
util.exit_with_err(e)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
5
.github/scripts/icomoon_build.py
vendored
5
.github/scripts/icomoon_build.py
vendored
@@ -6,6 +6,7 @@ from selenium.common.exceptions import TimeoutException
|
|||||||
# don't worry about it, the script still runs
|
# don't worry about it, the script still runs
|
||||||
from build_assets.SeleniumRunner import SeleniumRunner
|
from build_assets.SeleniumRunner import SeleniumRunner
|
||||||
from build_assets import filehandler, arg_getters
|
from build_assets import filehandler, arg_getters
|
||||||
|
from build_assets import util
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -32,9 +33,9 @@ def main():
|
|||||||
filehandler.rename_extracted_files(args.download_path)
|
filehandler.rename_extracted_files(args.download_path)
|
||||||
print("Task completed.")
|
print("Task completed.")
|
||||||
except TimeoutException as e:
|
except TimeoutException as e:
|
||||||
sys.exit("Selenium Time Out Error: \n" + str(e))
|
util.exit_with_err("Selenium Time Out Error: \n" + str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(str(e))
|
util.exit_with_err(e)
|
||||||
finally:
|
finally:
|
||||||
runner.close()
|
runner.close()
|
||||||
|
|
||||||
|
5
.github/scripts/icomoon_peek.py
vendored
5
.github/scripts/icomoon_peek.py
vendored
@@ -8,6 +8,7 @@ import xml.etree.ElementTree as et
|
|||||||
# don't worry about it, the script still runs
|
# don't worry about it, the script still runs
|
||||||
from build_assets.SeleniumRunner import SeleniumRunner
|
from build_assets.SeleniumRunner import SeleniumRunner
|
||||||
from build_assets import filehandler, arg_getters
|
from build_assets import filehandler, arg_getters
|
||||||
|
from build_assets import util
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -39,9 +40,9 @@ def main():
|
|||||||
runner.upload_svgs(svgs, screenshot_folder)
|
runner.upload_svgs(svgs, screenshot_folder)
|
||||||
print("Task completed.")
|
print("Task completed.")
|
||||||
except TimeoutException as e:
|
except TimeoutException as e:
|
||||||
sys.exit("Selenium Time Out Error: \n" + str(e))
|
util.exit_with_err("Selenium Time Out Error: \n" + str(e))
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
sys.exit(str(e))
|
util.exit_with_err(e)
|
||||||
finally:
|
finally:
|
||||||
runner.close()
|
runner.close()
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user