forked from devicons/devicon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/develop'
- Loading branch information
Showing
33 changed files
with
1,120 additions
and
421 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
.github/scripts/build_assets/drafts/check_devicon_object.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from typing import List | ||
|
||
# abandoned since it's not too hard to check devicon objects using our eyes | ||
# however, still keep in case we need it in the future | ||
|
||
def check_devicon_objects(icons: List[dict]): | ||
""" | ||
Check that the devicon objects added is up to standard. | ||
""" | ||
err_msgs = [] | ||
for icon in icons: | ||
if type(icon["name"]) != str: | ||
err_msgs.append("'name' must be a string, not: " + str(icon["name"])) | ||
|
||
try: | ||
for tag in icon["tags"]: | ||
if type(tag) != str: | ||
raise TypeError() | ||
except TypeError: | ||
err_msgs.append("'tags' must be an array of strings, not: " + str(icon["tags"])) | ||
break | ||
|
||
|
||
if type(icon["versions"]["svg"]) != list or len(icon["versions"]["svg"]) == 0: | ||
err_msgs.append("Icon name must be a string") | ||
|
||
if type(icon["versions"]["font"]) != list or len(icon["versions"]["svg"]) == 0: | ||
err_msgs.append("Icon name must be a string") | ||
|
||
if type(icon["color"]) != str or "#" not in icon["color"]: | ||
err_msgs.append("'color' must be a string in the format '#abcdef'") | ||
|
||
if type(icon["aliases"]) != list: | ||
err_msgs.append("'aliases' must be an array of dicts") | ||
|
||
if len(err_msgs) > 0: | ||
raise Exception("Error found in devicon.json: \n" + "\n".join(err_msgs)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from pathlib import Path | ||
import json | ||
|
||
|
||
# pycharm complains that build_assets is an unresolved ref | ||
# don't worry about it, the script still runs | ||
from build_assets import filehandler | ||
|
||
|
||
if __name__ == "__main__": | ||
""" | ||
Use as a cmd line script to check all the icons of the devicon.json. | ||
""" | ||
devicon_json_path = str(Path("./devicon.json").resolve()) | ||
icons_folder_path = str(Path("./icons").resolve()) | ||
with open(devicon_json_path) as json_file: | ||
devicon_json = json.load(json_file) | ||
svgs = filehandler.get_svgs_paths(devicon_json, icons_folder_path) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from typing import List | ||
import sys | ||
import xml.etree.ElementTree as et | ||
import time | ||
from pathlib import Path | ||
|
||
|
||
# pycharm complains that build_assets is an unresolved ref | ||
# don't worry about it, the script still runs | ||
from build_assets import filehandler, arg_getters | ||
from build_assets import github_env | ||
|
||
|
||
def main(): | ||
""" | ||
Check the quality of the svgs. | ||
If any error is found, set an environmental variable called ERR_MSGS | ||
that will contains the error messages. | ||
""" | ||
args = arg_getters.get_check_svgs_args() | ||
new_icons = filehandler.find_new_icons(args.devicon_json_path, args.icomoon_json_path) | ||
|
||
if len(new_icons) == 0: | ||
sys.exit("No files need to be uploaded. Ending script...") | ||
|
||
# print list of new icons | ||
print("SVGs being checked:", *new_icons, sep = "\n", end='\n\n') | ||
|
||
time.sleep(1) # do this so the logs stay clean | ||
try: | ||
# check the svgs | ||
svgs = filehandler.get_svgs_paths(new_icons, args.icons_folder_path, as_str=False) | ||
check_svgs(svgs) | ||
print("All SVGs found were good.\nTask completed.") | ||
except Exception as e: | ||
github_env.set_env_var("ERR_MSGS", str(e)) | ||
sys.exit(str(e)) | ||
|
||
|
||
def check_svgs(svg_file_paths: List[Path]): | ||
""" | ||
Check the width, height, viewBox and style of each svgs passed in. | ||
The viewBox must be '0 0 128 128'. | ||
If the svg has a width and height attr, ensure it's '128px'. | ||
The style must not contain any 'fill' declarations. | ||
If any error is found, they will be thrown. | ||
:param: svg_file_paths, the file paths to the svg to check for. | ||
""" | ||
# batch err messages together so user can fix everything at once | ||
err_msgs = [] | ||
for svg_path in svg_file_paths: | ||
tree = et.parse(svg_path) | ||
root = tree.getroot() | ||
namespace = "{http://www.w3.org/2000/svg}" | ||
err_msg = [f"{svg_path.name}:"] | ||
|
||
if root.tag != f"{namespace}svg": | ||
err_msg.append(f"-root is '{root.tag}'. Root must be an 'svg' element") | ||
|
||
if root.get("viewBox") != "0 0 128 128": | ||
err_msg.append("-'viewBox' is not '0 0 128 128' -> Set it or scale the file using https://www.iloveimg.com/resize-image/resize-svg") | ||
|
||
acceptable_size = [None, "128px", "128"] | ||
if root.get("height") not in acceptable_size: | ||
err_msg.append("-'height' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'") | ||
|
||
if root.get("width") not in acceptable_size: | ||
err_msg.append("-'width' is present in svg element but is not '128' or '128px' -> Remove it or set it to '128' or '128px'") | ||
|
||
if root.get("style") is not None and "enable-background" in root.get("style"): | ||
err_msg.append("-deprecated 'enable-background' in style attribute -> Remove it") | ||
|
||
if root.get("x") is not None: | ||
err_msg.append("-unneccessary 'x' attribute in svg element -> Remove it") | ||
|
||
if root.get("y") is not None: | ||
err_msg.append("-unneccessary 'y' attribute in svg element -> Remove it") | ||
|
||
style = root.findtext(f".//{namespace}style") | ||
if style != None and "fill" in style: | ||
err_msg.append("-contains style declaration using 'fill' -> Replace classes with the 'fill' attribute instead") | ||
|
||
if len(err_msg) > 1: | ||
err_msgs.append("\n".join(err_msg)) | ||
|
||
if len(err_msgs) > 0: | ||
raise Exception("Errors found in these files:\n" + "\n\n".join(err_msgs)) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.