Skip to content

Commit 49a8ea0

Browse files
committed
more robust parsing, added some comments
1 parent af1fd98 commit 49a8ea0

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/compas_invocations2/grasshopper.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import shutil
1212
import tempfile
1313
from pathlib import Path
14+
from typing import List
1415

1516
import invoke
1617
import requests
@@ -84,7 +85,8 @@ def _get_package_name(toml_file: str) -> str:
8485

8586

8687
def _sanitize_dependency(dep: str) -> str:
87-
# Remove upper bound constraints (e.g., ", <3" or ",<3") as Rhino doesn't support them
88+
# HACK: Remove upper bound constraints (e.g., ", <3" or ",<3") as Rhino currenly doesn't support them
89+
# https://discourse.mcneel.com/t/python-dependencies-with-ordered-comparison-syntax/212304
8890
sanitized = re.split(r"\s*,\s*[<>=]", dep)[0]
8991
sanitized = sanitized.split("#")[0].strip() # Remove inline comments
9092
return sanitized
@@ -100,16 +102,16 @@ def _get_deps_from_requirements(req_filepath: str) -> str:
100102
return dependencies
101103

102104

103-
def _get_dependencies(base_folder: str) -> str:
105+
def _get_dependencies(base_folder: str) -> List[str]:
104106
toml_filepath = os.path.join(base_folder, "pyproject.toml")
105107
with open(toml_filepath, "r") as f:
106108
toml = tomlkit.load(f)
107109

108-
dependencies = toml.get("project").get("dependencies")
110+
dependencies = toml.get("project", {}).get("dependencies")
109111
if dependencies:
110112
return [_sanitize_dependency(dep) for dep in dependencies]
111113

112-
dynamic_deps = toml.get("tool").get("setuptools").get("dynamic").get("dependencies")
114+
dynamic_deps = toml.get("tool", {}).get("setuptools", {}).get("dynamic", {}).get("dependencies")
113115
if dynamic_deps and "file" in dynamic_deps:
114116
req_filepath = os.path.join(base_folder, dynamic_deps["file"])
115117
return _get_deps_from_requirements(req_filepath)
@@ -273,9 +275,10 @@ def update_gh_header(ctx, version: str = None, venv: str = None, dev: bool = Fal
273275
for env in envs.split(";"):
274276
new_header.append(f"# env: {env.strip()}\n")
275277
if dev:
276-
dependencies = _get_dependencies(ctx.base_folder)
277-
new_header.append(f"# r: {', '.join(dependencies)}\n")
278278
new_header.append(f"# env: {os.path.join(ctx.base_folder, 'src')}\n")
279+
dependencies = _get_dependencies(ctx.base_folder)
280+
if dependencies:
281+
new_header.append(f"# r: {', '.join(dependencies)}\n")
279282

280283
for file in Path(ctx.ghuser_cpython.source_dir).glob("**/code.py"):
281284
try:

0 commit comments

Comments
 (0)