Skip to content
Merged
Changes from 2 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
41 changes: 35 additions & 6 deletions easybuild/tools/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import copy
import getpass
import glob
import functools
import os
import random
import re
Expand Down Expand Up @@ -377,16 +378,34 @@ def download_repo(repo=GITHUB_EASYCONFIGS_REPO, branch='master', account=GITHUB_
return extracted_path


def fetch_easyblocks_from_pr(pr, path=None, github_user=None):
"""Fetch patched easyconfig files for a particular PR."""
return fetch_files_from_pr(pr, path, github_user, github_repo=GITHUB_EASYBLOCKS_REPO)
def pr_files_cache(func):
"""
Decorator to cache result of fetch_files_from_pr.
"""
cache = {}

@functools.wraps(func)
def cache_aware_func(pr, *args, **kwargs):
"""Retrieve cached resul, or fetch files from PR & cache result."""
# cache key is combination of all function arguments (incl. optional ones)
key = tuple([pr] + [kwargs[key] for key in sorted(kwargs.keys())])

def fetch_easyconfigs_from_pr(pr, path=None, github_user=None):
"""Fetch patched easyconfig files for a particular PR."""
return fetch_files_from_pr(pr, path, github_user, github_repo=GITHUB_EASYCONFIGS_REPO)
if key in cache and all(os.path.exists(x) for x in cache[key]):
_log.debug("Using cached value for fetch_files_from_pr for PR #%s (%s)", pr, kwargs)
return cache[key]
else:
res = func(pr, *args, **kwargs)
cache[key] = res
return res

# expose clear/update methods of cache to wrapped function
cache_aware_func.clear_cache = cache.clear
cache_aware_func.update_cache = cache.update

return cache_aware_func


@pr_files_cache
def fetch_files_from_pr(pr, path=None, github_user=None, github_repo=None):
"""Fetch patched files for a particular PR."""

Expand Down Expand Up @@ -496,6 +515,16 @@ def fetch_files_from_pr(pr, path=None, github_user=None, github_repo=None):
return files


def fetch_easyblocks_from_pr(pr, path=None, github_user=None):
"""Fetch patched easyconfig files for a particular PR."""
return fetch_files_from_pr(pr, path, github_user, github_repo=GITHUB_EASYBLOCKS_REPO)


def fetch_easyconfigs_from_pr(pr, path=None, github_user=None):
"""Fetch patched easyconfig files for a particular PR."""
return fetch_files_from_pr(pr, path, github_user, github_repo=GITHUB_EASYCONFIGS_REPO)


def create_gist(txt, fn, descr=None, github_user=None, github_token=None):
"""Create a gist with the provided text."""

Expand Down