Skip to content

Commit 4571a77

Browse files
only update sha on changes (#850)
* only update sha on changes * handle git hash of functions * comment git_hash function * pre-commit * ignore another warning --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent c37d953 commit 4571a77

5 files changed

Lines changed: 35 additions & 9 deletions

File tree

.github/workflows/update_website_content.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
steps:
2424
- uses: actions/checkout@v3
2525
with:
26-
fetch-depth: 1
26+
fetch-depth: 0
2727
path: openproblems
2828

2929
- name: Checkout website repo

openproblems/api/hash.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@ def get_module(fun):
3232
return fun.__module__
3333

3434

35-
def git_hash(file):
36-
"""Get the git commit hash associated with a file."""
37-
return _run(
38-
["git", "log", "-n", "1", "--pretty=format:%H", "--", file],
39-
cwd=os.path.dirname(__file__),
40-
)
35+
def git_hash(obj):
36+
"""Get the git commit hash associated with the latest change to a file."""
37+
if isinstance(obj, str) and os.path.isfile(obj):
38+
# if it's a file, run git log to get the hash
39+
return _run(
40+
["git", "log", "-n", "1", "--pretty=format:%H", "--", obj],
41+
cwd=os.path.dirname(__file__),
42+
)
43+
elif hasattr(obj, "__file__"):
44+
# if it's a module, get the associated file
45+
return git_hash(obj.__file__)
46+
elif callable(obj):
47+
# if it's a function, get the associated module
48+
return git_hash(importlib.import_module(get_module(obj)))
4149

4250

4351
def docker_token(image_name):

pytest.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ filterwarnings =
1313
ignore:`Model\.state_updates` will be removed in a future version\.:UserWarning
1414
ignore:Tensorflow not installed. ParametricUMAP will be unavailable:ImportWarning
1515
ignore:Deprecated call to `pkg_resources\.declare_namespace:DeprecationWarning
16+
ignore:pkg_resources is deprecated as an API:DeprecationWarning
1617
always:Container failed with AssertionError\. Retrying [0-9]* more time:RuntimeWarning

test/test_core_cli.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
from openproblems.api.hash import docker_labels_from_api
2+
from openproblems.api.hash import git_hash
23
from openproblems.api.main import main
34
from openproblems.api.utils import print_output
45

6+
import importlib
57
import numpy as np
68
import openproblems
79
import os
@@ -159,6 +161,20 @@ def test_hash_docker_api():
159161
assert labels["bio.openproblems.build"] in ["github_actions", "local"]
160162

161163

164+
@parameterized.parameterized.expand(
165+
[
166+
(openproblems.tasks.label_projection.datasets.zebrafish_labs,),
167+
(openproblems.tasks.label_projection.methods.knn_classifier_log_cp10k,),
168+
],
169+
name_func=utils.name.name_test,
170+
)
171+
def test_git_hash(func):
172+
h1 = git_hash(func)
173+
module = importlib.import_module(func.__wrapped__.__module__)
174+
assert git_hash(module) == h1
175+
assert git_hash(module.__file__) == h1
176+
177+
162178
@parameterized.parameterized.expand(
163179
[
164180
(dataset, method, metric)

workflow/parse_metadata.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import openproblems
3+
import openproblems.api.hash
34
import pathlib
45
import re
56
import sys
@@ -27,7 +28,7 @@ def get_task_description(task):
2728
def write_task_json(task, outdir: pathlib.Path):
2829
data = {
2930
"task_id": openproblems.utils.get_member_id(task),
30-
"commit_sha": workflow_utils.get_sha(),
31+
"commit_sha": openproblems.api.hash.git_hash(task),
3132
"task_name": task._task_name,
3233
"task_summary": task._task_summary,
3334
"task_description": get_task_description(task),
@@ -43,7 +44,7 @@ def _write_function_json(task, outdir: pathlib.Path, functions, function_type: s
4344
function.metadata.update(
4445
{
4546
"task_id": openproblems.utils.get_member_id(task),
46-
"commit_sha": workflow_utils.get_sha(),
47+
"commit_sha": openproblems.api.hash.git_hash(function),
4748
f"{function_type}_id": openproblems.utils.get_member_id(function),
4849
"implementation_url": (
4950
"https://github.com/openproblems-bio/openproblems/"

0 commit comments

Comments
 (0)