-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
349 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# Inspired by pybamm.citations | ||
# https://github.com/pybamm-team/PyBaMM | ||
|
||
from multiprocessing import Array | ||
import flavio | ||
import sys | ||
from itertools import compress | ||
import ctypes | ||
import yaml | ||
import pkgutil | ||
|
||
|
||
class CitationScope: | ||
|
||
def __enter__(self): | ||
self._citations_global = flavio.citations | ||
flavio.citations = Citations() | ||
return flavio.citations | ||
|
||
def __exit__(self, type, value, traceback): | ||
flavio.citations = self._citations_global | ||
|
||
|
||
class Citations: | ||
|
||
collect = CitationScope | ||
__all_citations = set(yaml.safe_load( | ||
pkgutil.get_data('flavio', 'data/citations.yml') | ||
)) | ||
|
||
def __init__(self, initial_citations=[]): | ||
self._initial_citations = set(initial_citations) | ||
self._all_citations = { | ||
k:i for i,k in | ||
enumerate(sorted(self.__all_citations | self._initial_citations)) | ||
} | ||
self._array = Array(ctypes.c_bool, len(self._all_citations)) | ||
for inspire_key in self._initial_citations: | ||
self.register(inspire_key) | ||
|
||
def __iter__(self): | ||
for citation in self.set: | ||
yield citation | ||
|
||
def __str__(self): | ||
return ",".join(self.set) | ||
|
||
@property | ||
def set(self): | ||
return set(compress(sorted(self._all_citations.keys()), self._array)) | ||
|
||
@property | ||
def string(self): | ||
return str(self) | ||
|
||
def register(self, inspire_key): | ||
try: | ||
self._array[self._all_citations[inspire_key]] = True | ||
except KeyError: | ||
from flavio.util import get_datapath | ||
yaml_path = get_datapath('flavio', 'data/citations.yml') | ||
raise KeyError( | ||
f'The inspire key must be contained in {yaml_path}. ' | ||
f'The key `{inspire_key}` was not found there.' | ||
) | ||
|
||
|
||
def clear(self): | ||
self._array[:] = [False]*len(self._array) | ||
|
||
def reset(self): | ||
self.clear() | ||
for inspire_key in self._initial_citations: | ||
self.register(inspire_key) | ||
|
||
|
||
sys.modules[__name__] = Citations(["Straub:2018kue"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
- Antonelli:2010yf | ||
- Asatrian:2003vq | ||
- Awramik:2003rn | ||
- Beneke:2001at | ||
- Beneke:2003az | ||
- Beneke:2004dp | ||
- Benson:2003kp | ||
- Bernard:2009zm | ||
- Bjorn:2016zlr | ||
- Bobeth:2013uxa | ||
- Boer:2014kda | ||
- Bourrely:2008za | ||
- Brignole:2004ah | ||
- Brivio:2017vri | ||
- Brod:2010hi | ||
- Buras:2006gb | ||
- Buras:2015yba | ||
- Caprini:1997mu | ||
- Chobanova:2017rkj | ||
- Cirigliano:2007ga | ||
- Descotes-Genon:2015hea | ||
- Falkowski:2019hvp | ||
- Freitas:2014hra | ||
- Gambino:2011cq | ||
- Gonzalez-Alonso:2018omy | ||
- Gorbahn:2006bm | ||
- Greub:2008cy | ||
- Guadagnoli:2016erb | ||
- Gubernari:2018wyi | ||
- Huber:2015sra | ||
- Inami:1980fz | ||
- Kitano:2002mt | ||
- Kozachuk:2017mdk | ||
- Kruger:2002gf | ||
- Kuno:1999jp | ||
- Melikhov:2004mk | ||
- Misiak:2006ab | ||
- Misiak:2015xwa | ||
- Pich:2013lsa | ||
- Seidel:2004jh | ||
- Straub:2015ica | ||
- fakename:2020abc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#! /usr/bin/env python3 | ||
|
||
"""Standalone helper script to update the list of citations referenced in the | ||
flavio source code.""" | ||
|
||
import argparse | ||
import logging | ||
import sys | ||
import yaml | ||
import pkgutil | ||
logging.basicConfig(level=logging.INFO) | ||
|
||
def main(argv): | ||
parser = argparse.ArgumentParser(description='Update the list of citations referenced in the flavio source code.') | ||
args = parser.parse_args() | ||
|
||
from flavio.util import get_datapath, extract_citations | ||
|
||
filename = get_datapath('flavio', 'data/citations.yml') | ||
with open(filename, 'w') as f: | ||
f.write(yaml.dump(sorted(extract_citations()))) | ||
logging.info(f"Saved updated citations to {filename}") | ||
|
||
if __name__ == '__main__': | ||
main(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.