Skip to main content

Read CFF formatted CITATION file from a GitHub url or local file and convert it to BibTeX, EndNote, RIS, Codemeta, .zenodo.json, or plain JSON

Project description

Badges

  • Zenodo DOI

  • Travis build status

  • PyPi Badge

  • CII Best Practices

  • SonarCloud Quality Gate

  • SonarCloud Code Coverage

  • Research Software Directory

cffconvert

Read CFF formatted CITATION file from a GitHub url and convert it to various formats, such as:

  1. BibTeX

  2. EndNote

  3. RIS

  4. codemeta

  5. plain JSON

  6. Zenodo JSON

Supported types of 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 does not support the full CFF spec yet.

For users

Install

There are a few options:

Option 1 (preferred): install in user space.

Ensure that the user space directory ~/.local/bin/ is on the PATH.

pip3 install --user cffconvert

Option 2 (not preferred): install in virtual environment

virtualenv -p /usr/bin/python3.5 myvenv3
source myvenv3/bin/activate
pip3 install cffconvert

Option 3 (not preferred): install globally

Note: this option needs sudo rights.

sudo -H pip3 install cffconvert

Option 4 (not preferred): install with conda

See https://stackoverflow.com/questions/41060382/using-pip-to-install-packages-to-anaconda-environment

conda install pip
pip install cffconvert

Option 5 (experimental): use cffconvert as a Google Cloud Function

cffconvert comes with an interface for running as a Google Cloud Function. We set it up here https://us-central1-cffconvert.cloudfunctions.net/cffconvert for the time being / as long as we have enough credits on the Google Cloud Function platform.

Really, all that does is get any supplied URL parameters, and use them as if they had been entered as command line arguments. For example, if you’d do

cffconvert --version

on the command line, now you enter https://us-central1-cffconvert.cloudfunctions.net/cffconvert?version to get the equivalent result.

Similarly, if you’d normally do

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

on the command line, the Google Cloud Function equivalent would be https://us-central1-cffconvert.cloudfunctions.net/cffconvert?url=https://github.com/xenon-middleware/xenon&outputformat=cff

To learn more about the other options, check https://us-central1-cffconvert.cloudfunctions.net/cffconvert?verbose

Option 5 (not preferred): install with setup.py in the user environment

python setup.py install --user

Command line interface

See cffconvert’s options:

cffconvert --help

Shows:

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.

Example usage, retrieve CITATION.cff from URL with curl, output as BibTeX:

curl https://raw.githubusercontent.com/citation-file-format/cff-converter-python/44a8ad35d94dd50a8b5924d8d26402ae0d162189/CITATION.cff > CITATION.cff
cffconvert -f bibtex

Results in:

@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}
}

Example usage, let cffconvert retrieve CITATION.cff from URL, output as codemeta.json:

cffconvert -f codemeta -u https://github.com/citation-file-format/cff-converter-python/tree/master -of codemeta.json

Contents of file 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"
}

Convert the contents of a local file CITATION.cff into the format used by .zenodo.json files (see Zenodo’s API docs), while ignoring any keys that are likely out of date:

cffconvert -f zenodo --ignore-suspect-keys

Results in (note absence of date-released, doi, and 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"
}

For developers

Install

# 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 .

Running tests

# (from the project root)

# run unit tests
pytest test/

# run tests against live system (GitHub)
pytest livetest/

For maintainers

Making a release

# 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/*

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cffconvert-1.2.1.tar.gz (18.0 kB view details)

Uploaded Source

File details

Details for the file cffconvert-1.2.1.tar.gz.

File metadata

  • Download URL: cffconvert-1.2.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.6.8

File hashes

Hashes for cffconvert-1.2.1.tar.gz
Algorithm Hash digest
SHA256 d43e5925b43ddc2140b50a87cca45cc8e8ed7e5426476c8d3d67f3753ea9a8db
MD5 2ecd0b3d884728191c4db3d5c2493cb9
BLAKE2b-256 08de7ae01e13c544a4b6888552459ca91faf8238efa97a169e82e80320600f9c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page