1
Fork 0
mirror of https://github.com/Steffo99/emblematic.git synced 2024-11-21 14:24:18 +00:00

Reformat code

This commit is contained in:
Steffo 2023-11-19 02:43:24 +01:00
parent d64bb15df0
commit 59289e68af
Signed by: steffo
GPG key ID: 2A24051445686895
4 changed files with 13 additions and 14 deletions

View file

@ -1,7 +1,6 @@
from . import compose from . import compose
from . import files from . import files
__all__ = ( __all__ = (
"compose", "compose",
"files", "files",

View file

@ -4,13 +4,14 @@ Command-line interface for :mod:`emblematic`.
Implemented with :mod:`click`. Implemented with :mod:`click`.
""" """
import click
import bs4
import pathlib import pathlib
import cairosvg
from .files import get_svgs import bs4
import cairosvg
import click
from .compose import compose_basic from .compose import compose_basic
from .files import get_svgs
@click.group() @click.group()
@ -83,7 +84,7 @@ def basic(bg_file, icon_paths, icon_fill, output_dir, width, height, keep_svg):
icon_doc = bs4.BeautifulSoup(icon_file, features="lxml-xml") icon_doc = bs4.BeautifulSoup(icon_file, features="lxml-xml")
icon = icon_doc.svg icon = icon_doc.svg
icon.path.attrs["fill"] = icon_fill icon.path.attrs["fill"] = icon_fill
click.echo("", nl=False) click.echo("", nl=False)
svg_doc = compose_basic(background=bg, icon=icon, width=width, height=height).prettify() svg_doc = compose_basic(background=bg, icon=icon, width=width, height=height).prettify()
@ -91,7 +92,7 @@ def basic(bg_file, icon_paths, icon_fill, output_dir, width, height, keep_svg):
with open(output_svg_path, mode="w") as output_file: with open(output_svg_path, mode="w") as output_file:
click.echo(output_svg_path, nl=False) click.echo(output_svg_path, nl=False)
output_file.write(svg_doc) output_file.write(svg_doc)
click.echo("", nl=False) click.echo("", nl=False)
svg_bytes = bytes(svg_doc, encoding="utf8") svg_bytes = bytes(svg_doc, encoding="utf8")
png_bytes = cairosvg.svg2png(bytestring=svg_bytes) png_bytes = cairosvg.svg2png(bytestring=svg_bytes)
@ -103,6 +104,5 @@ def basic(bg_file, icon_paths, icon_fill, output_dir, width, height, keep_svg):
click.echo() click.echo()
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View file

@ -14,19 +14,19 @@ def compose_basic(background: bs4.Tag, icon: bs4.Tag, width: int, height: int) -
raise ValueError("bg is not a <svg> tag.") raise ValueError("bg is not a <svg> tag.")
if icon.name != "svg": if icon.name != "svg":
raise ValueError("fg is not a <svg> tag.") raise ValueError("fg is not a <svg> tag.")
background = background.__copy__() background = background.__copy__()
background.attrs["id"] = "emblematic-background" background.attrs["id"] = "emblematic-background"
background.attrs["width"] = "100%" background.attrs["width"] = "100%"
background.attrs["height"] = "100%" background.attrs["height"] = "100%"
icon = icon.__copy__() icon = icon.__copy__()
icon.attrs["id"] = "emblematic-icon" icon.attrs["id"] = "emblematic-icon"
icon.attrs["width"] = "63%" icon.attrs["width"] = "63%"
icon.attrs["height"] = "63%" icon.attrs["height"] = "63%"
icon.attrs["preserveAspectRatio"] = "xMidYMid meet" icon.attrs["preserveAspectRatio"] = "xMidYMid meet"
icon.attrs["transform"] = f"translate({width * 0.37 / 2}, {height * 0.37 / 2})" icon.attrs["transform"] = f"translate({width * 0.37 / 2}, {height * 0.37 / 2})"
doc = bs4.BeautifulSoup(f""" doc = bs4.BeautifulSoup(f"""
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}"> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 {width} {height}">
</svg> </svg>
@ -36,7 +36,7 @@ def compose_basic(background: bs4.Tag, icon: bs4.Tag, width: int, height: int) -
container.append(icon) container.append(icon)
return doc return doc
__all__ = ( __all__ = (
"compose_basic", "compose_basic",

View file

@ -13,7 +13,7 @@ def get_svgs(path: pathlib.Path):
raise ValueError("Given path does not exist.") raise ValueError("Given path does not exist.")
if not path.is_dir(): if not path.is_dir():
return [path] return [path]
return list(path.glob("**/*.svg")) return list(path.glob("**/*.svg"))