Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions hub/builders/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,15 @@ def generate_digest(file_path: str) -> str:

return f"sha256:{sha256_hash.hexdigest()}"

def download_github_license(repo_url: str, target_path: str, license_files=None):
def download_github_license(repo_url: str, target_path: str, license_files=None, license_text=None):
# Recipe-supplied verbatim text wins. Used when the upstream repo carries
# the license in a source-file header rather than a standalone LICENSE file.
if license_text:
target_file = Path(target_path)
target_file.parent.mkdir(parents=True, exist_ok=True)
target_file.write_text(license_text, encoding="utf-8")
return

parts = urlparse(repo_url).path.strip("/").split("/")
if len(parts) < 2:
raise ValueError("Invalid GitHub repo URL")
Expand Down Expand Up @@ -118,9 +126,15 @@ def build_plugins(file_paths, build_dir, registry_dir):
"modes": recipe["runtime"]["modes"],
}

if "github" in recipe['source']["repo"]:
license_text = recipe.get("license", {}).get("text")
if license_text or "github" in recipe['source']["repo"]:
license_files = recipe.get("license", {}).get("files")
download_github_license(recipe["source"]["repo"], f"{plugin_dir}/LICENSE", license_files)
download_github_license(
recipe["source"]["repo"],
f"{plugin_dir}/LICENSE",
license_files=license_files,
license_text=license_text,
)

for runtime in build_runtimes:
runtime_dir = f"{plugin_dir}/runtime/{runtime}"
Expand Down
11 changes: 10 additions & 1 deletion hub/validate/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,17 @@ def validate_output_mode(field, value, error):
'type': 'list',
'schema': {'type': 'string'},
'minlength': 1,
'required': False,
# TODO check if license exists
}
},
# Verbatim license text. Use when the upstream repo carries the
# license in a source-file header rather than a standalone LICENSE
# file. Mutually exclusive in practice with `files` — when both are
# present, `text` wins.
'text': {
'type': 'string',
'required': False,
},
}
},
'source': {
Expand Down