从github url或本地文件读取cff格式的引用文件,并将其转换为bibtex、endnote、ris、codemeta、.zenodo.json或纯json
cffconvert的Python项目详细描述
cffconvert
从github读取CFF formatted CITATION文件 URL并将其转换为各种格式,如:
- bibtex
- 尾注
- RIS
- 代码元
- 纯json
- Zenodo JSON
支持的github url类型:
- https://github.com/<org>/<repo>
- https://github.com/<org>/<repo>/tree/<sha>
- https://github.com/<org>/<repo>/tree/<tagname>
- https://github.com/<org>/<repo>/tree/<branchname>
cffconvert不支持完整的CFF spec 然而。
对于用户
安装
有几个选项:
选项1(首选):在用户空间中安装。
确保用户空间目录~/.local/bin/位于PATH上。
pip3 install --user cffconvert
选项2(不首选):在虚拟环境中安装
virtualenv -p /usr/bin/python3.5 myvenv3
source myvenv3/bin/activate
pip3 install cffconvert
选项3(不首选):全局安装
注意:此选项需要sudo权限。
sudo -H pip3 install cffconvert
选项4(不首选):使用conda安装
见https://stackoverflow.com/questions/41060382/using-pip-to-install-packages-to-anaconda-environment 选项5(实验性):使用cffconvert作为google云函数 cffconvert附带an interface以作为google云函数运行。我们在这里设置的
https://us-central1-cffconvert.cloudfunctions.net/cffconvert暂时/只要我们在谷歌云功能平台上有足够的积分。 实际上,所做的只是获取任何提供的url参数,并将它们当作命令行参数输入。例如,如果您这样做 在命令行中,现在输入
https://us-central1-cffconvert.cloudfunctions.net/cffconvert?version
以得到相同的结果。 同样,如果您通常这样做 在命令行中,google cloud的功能等价于
https://us-central1-cffconvert.cloudfunctions.net/cffconvert?url=https://github.com/xenon-middleware/xenon&outputformat=cff 要了解其他选项的更多信息,请选中
https://us-central1-cffconvert.cloudfunctions.net/cffconvert?verbose 选项5(不首选):在用户环境中使用setup.py安装
conda install pip
pip install cffconvert
cffconvert --version
cffconvert --url https://github.com/xenon-middleware/xenon --outputformat cff
python setup.py install --user
命令行界面
请参阅cffconvert选项:
cffconvert --help
显示:
Usage: cffconvert [OPTIONS] Options: -if, --infile TEXT Path to the CITATION.cff input file. -of, --outfile TEXT Path to the output file. -f, --outputformat TEXT Output format: bibtex|cff|codemeta|endnote|ris|zenodo -u, --url TEXT URL of the repo containing the CITATION.cff (currently only github.com is supported; may include branch name, commit sha, tag name). For example: 'https://github.com/citation- file-format/cff-converter-python' or 'https://github.com/citation-file-format/cff- converter-python/tree/master' --validate Validate the CITATION.cff found at the URL or supplied through '--infile' -ig, --ignore-suspect-keys If True, ignore any keys from CITATION.cff that are likely out of date, such as 'commit', 'date-released', 'doi', and 'version'. --verbose Provide feedback on what was entered. --version Print version and exit. --help Show this message and exit.
示例用法,使用curl从url检索引文.cff,输出为bibtex:
curl https://raw.githubusercontent.com/citation-file-format/cff-converter-python/44a8ad35d94dd50a8b5924d8d26402ae0d162189/CITATION.cff > CITATION.cff cffconvert -f bibtex
结果:
@misc{YourReferenceHere, author={ Jurriaan H. Spaaks and Tom Klaver }, title={cff-converter-python}, month={1}, year={2018}, doi={10.5281/zenodo.1162057}, url={https://github.com/citation-file-format/cff-converter-python}}
示例用法,让cffconvert从url检索引文.cff,输出为codemeta.json:
cffconvert -f codemeta -u https://github.com/citation-file-format/cff-converter-python/tree/master -of codemeta.json
文件内容codemeta.json:
{"@context":["https://doi.org/10.5063/schema/codemeta-2.0","http://schema.org"],"@type":"SoftwareSourceCode","author":[{"@type":"Person","affiliation":{"@type":"Organization","legalName":"Netherlands eScience Center"},"familyName":"Spaaks","givenName":"Jurriaan H."},{"@type":"Person","affiliation":{"@type":"Organization","legalName":"Netherlands eScience Center"},"familyName":"Klaver","givenName":"Tom"},{"@type":"Person","affiliation":{"@type":"Organization","legalName":"Netherlands eScience Center"},"familyName":"Verhoeven","givenName":"Stefan"}],"codeRepository":"https://github.com/citation-file-format/cff-converter-python","datePublished":"2018-05-22","identifier":"https://doi.org/10.5281/zenodo.1162057","keywords":["citation","bibliography","cff","CITATION.cff"],"license":"http://www.apache.org/licenses/LICENSE-2.0","name":"cffconvert","version":"0.0.5"}
将本地文件CITATION.cff的内容转换为.zenodo.json文件使用的格式(请参见 Zenodo’s API docs),同时忽略任何可能过期的键:
cffconvert -f zenodo --ignore-suspect-keys
结果(注意不存在date-released、doi和version):
{"creators": [{"affiliation": "Netherlands eScience Center", "name": "Spaaks, Jurriaan H."}, {"affiliation": "Netherlands eScience Center", "name": "Klaver, Tom"}, {"affiliation": "Netherlands eScience Center", "name": "Verhoeven, Stefan"}], "keywords": ["citation", "bibliography", "cff", "CITATION.cff"], "license": {"id": "Apache-2.0"}, "title": "cffconvert"}
对于开发人员
安装
# get a copy of the cff-converter-python software git clone https://github.com/citation-file-format/cff-converter-python.git # change directory into cff-converter-python cd cff-converter-python # make a Python3.5 virtual environment named .venv35 virtualenv -p /usr/bin/python3.5 .venv35 # activate the virtual environment source ./.venv35/bin/activate # install any packages that cff-converter-python needs pip install -r requirements.txt # install any packages used for development such as for testing pip install -r requirements-dev.txt # install the cffconvert package using symlinks pip install --editable .
运行测试
# (from the project root) # run unit tests pytest test/ # run tests against live system (GitHub) pytest livetest/