从github url或本地文件读取cff格式的引用文件,并将其转换为bibtex、endnote、ris、codemeta、.zenodo.json或纯json

cffconvert的Python项目详细描述


徽章

  • Zenodo DOI
  • Travis build status
  • PyPi Badge
  • CII Best Practices
  • SonarCloud Quality Gate
  • SonarCloud Code Coverage
  • Research Software Directory

cffconvert

从github读取CFF formatted CITATION文件 URL并将其转换为各种格式,如:

  1. bibtex
  2. 尾注
  3. RIS
  4. 代码元
  5. 纯json
  6. Zenodo JSON

支持的github url类型:

  1. https://github.com/<org>/<repo>
  2. https://github.com/<org>/<repo>/tree/<sha>
  3. https://github.com/<org>/<repo>/tree/<tagname>
  4. 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

conda install pip
pip install cffconvert

选项5(实验性):使用cffconvert作为google云函数

cffconvert附带an interface以作为google云函数运行。我们在这里设置的 https://us-central1-cffconvert.cloudfunctions.net/cffconvert暂时/只要我们在谷歌云功能平台上有足够的积分。

实际上,所做的只是获取任何提供的url参数,并将它们当作命令行参数输入。例如,如果您这样做

cffconvert --version

在命令行中,现在输入 https://us-central1-cffconvert.cloudfunctions.net/cffconvert?version 以得到相同的结果。

同样,如果您通常这样做

cffconvert --url https://github.com/xenon-middleware/xenon --outputformat cff

在命令行中,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安装

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-releaseddoiversion):

{"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/

对于维护人员

发布
# make sure the release notes are up to date
# run the live tests and unit tests, make sure they pass
# git push everything, merge into master as appropriate
# verify that everything has been pushed and merged by testing as follows
cd$(mktemp -d)
git clone https://github.com/citation-file-format/cff-converter-python.git
cd cff-converter-python
virtualenv -p /usr/bin/python3.5 myvenv3
source myvenv3/bin/activate
pip install -r requirements.txt
pip install -r requirements-dev.txt
pytest test/
pytest livetest/

# register with PyPI test instance https://test.pypi.org
# remove these directories if you have them
rm -rf dist
rm -rf cffconvert-egg.info
# make a source distribution:
python setup.py sdist
# install the 'upload to pypi/testpypi tool' aka twine
pip install twine
# upload the contents of the source distribtion we just made
twine upload --repository-url https://test.pypi.org/legacy/ dist/*

# checking the package
# pip install --user --index-url https://test.pypi.org/simple/ cffconvert
# check that the package works as it should when installed from pypitest
# FINAL STEP: upload to PyPI
twine upload dist/*

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
与ReentrantLock相比,java ReentrantReadWriteLock的性能非常差   java如何使用Maven Android Studio正确导入?   安卓将ADB添加到我的Java PC应用程序   反射Java getDeclaredConstructor失败,来自JUnit的NoSuchMethodException   JSP上siteedit标记库的java替代   JavaSpring环境概要文件和JPA   java中是否有一个类似于StringBuilder的类,唯一的区别是它具有固定的长度?   JavaMathContext。小数点32 vs MathContext。小数点64,使用哪一个,为什么?   java使用spring在Ibm Websphere MQ中实现重试逻辑   java调用SpriteBatch。开始()和结束()   java有一种从文本中读取文本的方法。文件,并将其设置为pom中的maven属性。xml专家?   java让sitemesh使用struts2   Java Swing:在现有窗口上定位对话框   使用带有MemSql的JPA本机查询的java Select json列