Skip to content

Commit

Permalink
Add error_helper submodule
Browse files Browse the repository at this point in the history
  • Loading branch information
30350n committed Jan 23, 2024
1 parent ff6780a commit 9b6b46b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@
[submodule "pcb2blender_importer/blender_addon_utils"]
path = pcb2blender_importer/blender_addon_utils
url = https://github.com/30350n/blender_addon_utils
[submodule "_error_helper"]
path = _error_helper
url = https://github.com/30350n/error_helper
1 change: 1 addition & 0 deletions _error_helper
Submodule _error_helper added at 642f2e
39 changes: 9 additions & 30 deletions generate_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@
from git import Repo
from pytest import main as pytest

from ._error_helper import *

RELEASE_DIRECTORY = Path("release")
ARCHIVE_DIRECTORY = RELEASE_DIRECTORY / "archive"

def generate_release():
info("running autopep8 ... ", end="")
autopep8(["", "--recursive", "--in-place", "."])
if Repo().is_dirty():
error("repo is dirty (stash changes before generating a release)")
return error("repo is dirty (stash changes before generating a release)")

if Repo().head.is_detached:
error("repo is in detached head state")
return error("repo is in detached head state")
if "up to date" not in Repo().git.status():
error("current commit is not pushed")
return error("current commit is not pushed")
if Repo().tags[-1].commit != Repo().commit():
error("current commit is not tagged")
return error("current commit is not tagged")

with patch.object(sys, "argv", ["", "-q"]):
info("running pytest ...")
if (exit_code := pytest()) != 0:
error(f"tests failed with {exit_code}")
return error(f"tests failed with {exit_code}")

info(f"generating release for {Repo().tags[-1]} ... ")

Expand All @@ -52,7 +54,7 @@ def generate_release():
Path(__file__).parent / "pcb2blender_importer",
)

success("done.")
success("generated release!")

def generate_kicad_addon(path, metadata, icon_path=None, extra_files=[]):
repo = Repo()
Expand All @@ -79,7 +81,7 @@ def generate_kicad_addon(path, metadata, icon_path=None, extra_files=[]):
metadata_version = {
"version": version[1:],
"status": "stable",
"kicad_version": kicad_version[1:]
"kicad_version": kicad_version[1:],
}

metadata["versions"] = [metadata_version]
Expand Down Expand Up @@ -207,28 +209,5 @@ def get_package_version(path):
},
}

COLOR_INFO = "\033[94m"
COLOR_HINT = "\033[2;3m"
COLOR_SUCCESS = "\033[92m"
COLOR_WARNING = "\033[93m"
COLOR_ERROR = "\033[91m"
COLOR_END = "\033[0m"

def info(msg, end="\n"):
print(f"{COLOR_INFO}{msg}{COLOR_END}", end=end, flush=True)

def hint(msg):
print(f"{COLOR_HINT}({msg}){COLOR_END}")

def success(msg):
print(f"{COLOR_SUCCESS}{msg}{COLOR_END}")

def warning(msg):
print(f"{COLOR_WARNING}warning: {msg}{COLOR_END}")

def error(msg):
print(f"\n{COLOR_ERROR}error: {msg}{COLOR_END}", file=sys.stderr)
exit()

if __name__ == "__main__":
generate_release()

0 comments on commit 9b6b46b

Please sign in to comment.