Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use challenge level archives instead of phase level for pack README #22

Merged
merged 4 commits into from
Jan 2, 2024
Merged
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
6 changes: 0 additions & 6 deletions grand_challenge_forge/forge.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from grand_challenge_forge.generation_utils import (
ci_to_civ,
create_civ_stub_file,
extract_slug,
)
from grand_challenge_forge.schemas import validate_pack_context
from grand_challenge_forge.utils import cookiecutter_context as cc
Expand Down Expand Up @@ -105,11 +104,6 @@ def generate_upload_to_archive_script(
):
context = deepcopy(context)

# Cannot always use filters in directory names so generate it here
context["phase"]["archive"]["slug"] = extract_slug(
context["phase"]["archive"]["url"]
)

script_dir = (
output_directory
/ f"upload-to-archive-{context['phase']['archive']['slug']}"
Expand Down
17 changes: 0 additions & 17 deletions grand_challenge_forge/generation_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import os
import re
import shutil
import uuid
from pathlib import Path
Expand All @@ -22,22 +21,6 @@ def is_file(component_interface):
] == "File" and not component_interface["relative_path"].endswith(".json")


def extract_slug(url):
# Define a regex pattern to match the slug in the URL
pattern = r"/([^/]+)/*$"

# Use re.search to find the match
match = re.search(pattern, url)

# If a match is found, extract and return the slug
if match:
slug = match.group(1)
return slug
else:
# Return None or handle the case where no match is found
return None


def create_civ_stub_file(*, target_dir, component_interface):
"""Creates a stub based on a component interface"""
target_dir.parent.mkdir(parents=True, exist_ok=True)
Expand Down
5 changes: 0 additions & 5 deletions grand_challenge_forge/partials/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ def register_simple_filter(func):
return func


@register_simple_filter
def extract_slug(url):
return generation_utils.extract_slug(url)


@register_simple_filter
def is_json(arg):
return generation_utils.is_json(arg)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# sh (and their template counter parts) should always be lf their line endings
*.sh text=lf eol=lf
*.sh.j2 text=lf eol=lf
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# 📦 {{cookiecutter.challenge.slug}} challenge pack
Thank you for hosting your challenge on Grand-Challenge.org. We appreciate it!
Thank you for hosting your challenge on Grand-Challenge.org, we appreciate it!

## Content

This Challenge Pack is a collection of challenge-tailored examples to help you on your
way to hosting your {{cookiecutter.challenge.slug}} challenge.
way to host your {{cookiecutter.challenge.slug}} challenge.

It contains the following:
* ️🦾 An example script to _automate uploading_ data to an archive
* 🦿 An example _submission algorithm_ that can be uploaded to run as a submission in a challenge-phase
* 🦿 An example _submission algorithm_ that can be uploaded to run as a submission in a challenge phase
* 🧮 An example _evaluation method_ that evaluates algorithm submissions and generates performance
metrics for ranking

Expand All @@ -23,8 +23,8 @@ Challenge phases pull their data from archives to test submissions on.

Your challenge has the following archives:

{% for phase in cookiecutter.challenge.phases -%}
* {{phase.archive.url}}
{% for archive in cookiecutter.challenge.archives -%}
* {{archive.url}}
{% endfor %}

---
Expand Down
66 changes: 30 additions & 36 deletions grand_challenge_forge/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,31 @@

logger = logging.getLogger(__name__)

ARCHIVE_SCHEMA = {
"type": "object",
"properties": {
"slug": {"type": "string"},
"url": {"type": "string"},
},
"required": ["slug", "url"],
}

COMPONENT_INTERFACE_SCHEMA = {
"type": "object",
"properties": {
"slug": {"type": "string"},
"relative_path": {"type": "string"},
"kind": {"type": "string"},
"super_kind": {"type": "string"},
},
"required": [
"slug",
"relative_path",
"kind",
"super_kind",
],
}


PACK_CONTEXT_SCHEMA = {
"type": "object",
Expand All @@ -15,60 +40,29 @@
"type": "object",
"properties": {
"slug": {"type": "string"},
"archives": {"type": "array", "items": ARCHIVE_SCHEMA},
"phases": {
"type": "array",
"items": {
"type": "object",
"properties": {
"slug": {"type": "string"},
"archive": {
"type": "object",
"properties": {"url": {"type": "string"}},
"required": ["url"],
},
"archive": ARCHIVE_SCHEMA,
"inputs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"slug": {"type": "string"},
"relative_path": {"type": "string"},
"kind": {"type": "string"},
"super_kind": {"type": "string"},
},
"required": [
"slug",
"relative_path",
"kind",
"super_kind",
],
},
"items": COMPONENT_INTERFACE_SCHEMA,
},
"outputs": {
"type": "array",
"items": {
"type": "object",
"properties": {
"slug": {"type": "string"},
"relative_path": {"type": "string"},
"kind": {"type": "string"},
"super_kind": {"type": "string"},
},
"required": [
"slug",
"relative_path",
"kind",
"super_kind",
],
},
"items": COMPONENT_INTERFACE_SCHEMA,
},
},
"required": ["slug", "archive", "inputs", "outputs"],
"additionalProperties": True, # Allow additional properties
},
},
},
"required": ["slug", "phases"],
"required": ["slug", "phases", "archives"],
},
},
"required": ["challenge"],
Expand Down
3 changes: 1 addition & 2 deletions tests/test_pack_generation.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from grand_challenge_forge.forge import generate_challenge_pack
from grand_challenge_forge.generation_utils import extract_slug
from tests.utils import pack_context_factory


Expand All @@ -24,5 +23,5 @@ def test_for_pack_content(tmp_path):
assert (
pack_dir
/ phase["slug"]
/ f"upload-to-archive-{extract_slug(phase['archive']['url'])}"
/ f"upload-to-archive-{phase['archive']['slug']}"
).exists
16 changes: 16 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,25 @@
DEFAULT_PACK_CONTEXT_STUB = {
"challenge": {
"slug": "challenge-slug",
"archives": [
{
"slug": "archive-slug",
"url": "https://grand-challenge.org/archives/archive-slug/"
},
{
"slug": "another-archive-slug",
"url": "https://grand-challenge.org/archives/another-archive-slug/"
},
{
"slug": "yet-another-archive-slug",
"url": "https://grand-challenge.org/archives/yet-another-archive-slug/"
}
],
"phases": [
{
"slug": "phase-slug",
"archive": {
"slug": "archive-slug",
"url": "https://grand-challenge.org/archives/archive-slug/"
},
"inputs": [
Expand Down Expand Up @@ -68,6 +83,7 @@
{
"slug": "another-phase-slug",
"archive": {
"slug": "another-archive-slug",
"url": "https://grand-challenge.org/archives/another-archive-slug/"
},
"inputs": [
Expand Down