Skip to content

Commit

Permalink
allow minor rhino version. invoke.Exit needs to be raised
Browse files Browse the repository at this point in the history
  • Loading branch information
chenkasirer committed Jan 28, 2025
1 parent 0929c62 commit a207a9d
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/compas_invocations2/grasshopper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ def _clear_directory(path_to_dir):
elif os.path.isdir(file_path):
shutil.rmtree(file_path)
except Exception as e:
invoke.Exit(f"Failed to delete {file_path}: {e}")
raise invoke.Exit(f"Failed to delete {file_path}: {e}")


def _get_version_from_toml(toml_file: str) -> str:
pyproject_data = toml.load(toml_file)
version = pyproject_data.get("tool", {}).get("bumpversion", {}).get("current_version", None)
if not version:
invoke.Exit("Failed to get version from pyproject.toml. Please provide a version number.")
raise invoke.Exit("Failed to get version from pyproject.toml. Please provide a version number.")
return version


Expand Down Expand Up @@ -98,20 +98,23 @@ def yakerize(
target_rhino: str = "rh8",
) -> bool:
"""Create a Grasshopper YAK package from the current project."""
if target_rhino not in ["rh6", "rh7", "rh8"]:
invoke.Exit("Invalid target Rhino version. Must be one of: rh6, rh7, rh8")

# https://developer.rhino3d.com/guides/yak/the-anatomy-of-a-package/
if target_rhino.split("_")[0] not in ["rh6", "rh7", "rh8"]:
raise invoke.Exit(
f"""Invalid target Rhino version `{target_rhino}`. Must be one of: rh6, rh7, rh8.
Minor version is optional and can be appended with a '_' (e.g. rh8_15)."""
)
gh_components_dir = gh_components_dir or _get_user_object_path(ctx)
if not gh_components_dir:
invoke.Exit("Please provide the path to the directory containing the .ghuser files.")
raise invoke.Exit("Please provide the path to the directory containing the .ghuser files.")

readme_path = readme_path or os.path.join(ctx.base_folder, "README.md")
if not os.path.exists(readme_path):
invoke.Exit(f"Readme file not found at {readme_path}. Please provide a valid path.")
raise invoke.Exit(f"Readme file not found at {readme_path}. Please provide a valid path.")

license_path = license_path or os.path.join(ctx.base_folder, "LICENSE")
if not os.path.exists(license_path):
invoke.Exit(f"License file not found at {license_path}. Please provide a valid path.")
raise invoke.Exit(f"License file not found at {license_path}. Please provide a valid path.")

version = version or _get_version_from_toml(os.path.join(ctx.base_folder, "pyproject.toml"))
target_dir = os.path.join(ctx.base_folder, "dist", "yak_package")
Expand Down Expand Up @@ -147,7 +150,7 @@ def yakerize(
try:
yak_exe_path = _download_yak_executable(target_parent)
except ValueError:
invoke.Exit("Failed to download the yak executable")
raise invoke.Exit("Failed to download the yak executable")
else:
yak_exe_path = os.path.abspath(yak_exe_path)

Expand All @@ -156,9 +159,9 @@ def yakerize(
# not using `ctx.run()` here to get properly formatted output (unicode+colors)
os.system(f"{yak_exe_path} build --platform any")
except Exception as e:
invoke.Exit(f"Failed to build the yak package: {e}")
raise invoke.Exit(f"Failed to build the yak package: {e}")
if not any([f.endswith(".yak") for f in os.listdir(target_dir)]):
invoke.Exit("No .yak file was created in the build directory.")
raise invoke.Exit("No .yak file was created in the build directory.")

# filename is what tells YAK the target Rhino version..?
taget_file = next((f for f in os.listdir(target_dir) if f.endswith(".yak")))
Expand All @@ -173,16 +176,16 @@ def publish_yak(ctx, yak_file: str, test_server: bool = False):
"""Publish a YAK package to the YAK server."""

if not os.path.exists(yak_file) or not os.path.isfile(yak_file):
invoke.Exit(f"Yak file not found at {yak_file}. Please provide a valid path.")
raise invoke.Exit(f"Yak file not found at {yak_file}. Please provide a valid path.")
if not yak_file.endswith(".yak"):
invoke.Exit("Invalid file type. Must be a .yak file.")
raise invoke.Exit("Invalid file type. Must be a .yak file.")

with chdir(ctx.base_folder):
with tempfile.TemporaryDirectory("actions.publish_yak") as action_dir:
try:
_download_yak_executable(action_dir)
except ValueError:
invoke.Exit("Failed to download the yak executable")
raise invoke.Exit("Failed to download the yak executable")

yak_exe_path: str = os.path.join(action_dir, "yak.exe")
if test_server:
Expand Down

0 comments on commit a207a9d

Please sign in to comment.