Skip to content

Commit

Permalink
Fix GitHub source link in scenario.json (#1762)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkly authored Aug 11, 2023
1 parent 46547d7 commit 8e83dc5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/helm/benchmark/scenarios/scenario.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass, field, replace
from typing import List, Optional, Tuple
import re
from pathlib import PurePath
import inspect

from helm.common.object_spec import ObjectSpec, create_object
Expand Down Expand Up @@ -200,10 +200,14 @@ class Scenario(ABC):
"""Where the scenario subclass for `self` is defined."""

def __post_init__(self) -> None:
# Assume `/.../src/helm/benchmark/...`
path = inspect.getfile(type(self))
# Strip out prefix in absolute path and replace with GitHub link.
self.definition_path = re.sub(r"^.*\/src/", "https://github.com/stanford-crfm/helm/blob/main/src/", path)
parts = list(PurePath(inspect.getfile(type(self))).parts)
path = parts.pop()
parts.reverse()
for part in parts:
path = part + "/" + path
if part == "helm":
break
self.definition_path = "https://github.com/stanford-crfm/helm/blob/main/src/" + path

@abstractmethod
def get_instances(self) -> List[Instance]:
Expand Down
6 changes: 6 additions & 0 deletions src/helm/benchmark/scenarios/test_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def test_render_lines(self):
"}",
]

def test_definition_path(self):
assert (
self.scenario.definition_path
== "https://github.com/stanford-crfm/helm/blob/main/src/helm/benchmark/scenarios/simple_scenarios.py"
)


def test_input_equality():
input1 = Input(text="input1")
Expand Down

0 comments on commit 8e83dc5

Please sign in to comment.