How to use the cffconvert.Citation function in cffconvert

To help you get started, we’ve selected a few cffconvert examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adrn / makecite / makecite / cmdline.py View on Github external
----------
    package_name : str
        Name of the package.

    Returns
    -------
    bibtex : str or None
        Returns the BibTeX string or None if the package is not installed or doesn't provide one.
    """
    package = importlib.import_module(package_name)
    cff_file = os.path.join(package.__path__[0], 'CITATION.cff')
    citation_file = os.path.join(package.__path__[0], 'CITATION')
    if os.path.exists(cff_file):
        with open(cff_file) as f:
            cffstr = f.read()
        citation = Citation(cffstr=cffstr)
        bibtex = citation.as_bibtex()
    elif os.path.exists(citation_file):
        with open(citation_file) as f:
            citestr = f.read()
        match = re.search(cite_tag_pattr, citestr)
        if match is None:
            raise ValueError('Could not find any BibTeX entries in CITATION file')
        for i_end in range(match.end(), len(citestr)):
            bibtex = citestr[match.start():i_end]
            if bibtex.count('{') == bibtex.count('}'):
                break
        else:
            raise ValueError('Mismatched braces in BibTeX entry in CITATION file')
    else:
        bibtex = None
    return bibtex
github research-software-directory / research-software-directory / releases.py View on Github external
def generate_files(self):
        for release in self.releases:
            try:
                override = {
                    "doi": release["doi"],
                    "date-released": datetime.strptime(release["datePublished"], "%Y-%m-%d").date(),
                    "version": release["tag"]
                }
                remove = ["commit"]
                citation = Citation(url=release["url"], override=override, remove=remove)
                try:
                    release["files"] = dict({
                        "bibtex": citation.as_bibtex(),
                        "cff": citation.cffstr,
                        "codemeta": citation.as_codemeta(),
                        "endnote": citation.as_enw(),
                        "ris": citation.as_ris()
                    })
                    release["citability"] = "full"
                except Exception:
                    continue
            except Exception as e:
                if str(e).startswith("Error requesting file: "):
                    continue
                elif str(e).startswith("Provided CITATION.cff does not seem valid YAML."):
                    continue
github research-software-directory / research-software-directory / harvesting / releases.py View on Github external
def generate_files(self):
        for release in self.releases:
            try:
                override = {
                    "doi": release["doi"],
                    "date-released": datetime.strptime(release["datePublished"], "%Y-%m-%d").date(),
                    "version": release["tag"]
                }
                remove = ["commit"]
                citation = Citation(url=release["url"], override=override, remove=remove)
                try:
                    release["files"] = dict({
                        "bibtex": citation.as_bibtex(),
                        "codemeta": citation.as_codemeta(),
                        "cff": citation.cffstr,
                        "schema_dot_org": citation.as_schema_dot_org(),
                        "endnote": citation.as_enw(),
                        "ris": citation.as_ris()
                    })
                    release["citability"] = "full"
                except Exception:
                    continue
            except Exception as e:
                if str(e).startswith("Error requesting file: "):
                    continue
                elif str(e).startswith("Provided CITATION.cff does not seem valid YAML."):

cffconvert

Command line program to validate and convert CITATION.cff files.

Apache-2.0
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis

Popular cffconvert functions