Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error on empty bib files #15

Merged
merged 8 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

[compat]
Bibliography = "0.2"
BibParser = "0.1"
Bibliography = "0.2"
DataStructures = "0.18"
HTTP = "0.9"
julia = "1.6"
Expand Down
9 changes: 7 additions & 2 deletions src/citations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@ function get_citation(pkg; badge=false)
if !isnothing(bib_path)
@debug "Reading CITATION.bib for $(pkg.name)"
try
import_bibtex(bib_path)
bib = import_bibtex(bib_path)
if isempty(bib)
@warn "The CITATION.bib file for $(pkg.name) is empty."
end

bib
catch e
@warn "There was an error reading the CITATION.bib file for $(pkg.name)" exception=e
end
Expand Down Expand Up @@ -47,7 +52,7 @@ function collect_citations(only_direct::Bool; badge=false)
end
end

return pkg_citations
return sort!(DataStructures.OrderedDict(pkg_citations))
end

function bibliography(pkg_citations)
Expand Down
1 change: 1 addition & 0 deletions src/tool_report.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function cite_package(name, bib; cite_commands)
isempty(bib) && return ""
if length(bib) == 1
key = only(keys(bib))
cmd = get(cite_commands, name, DEFAULT_CITE)
Expand Down
79 changes: 39 additions & 40 deletions test/cite_str.jl
Original file line number Diff line number Diff line change
@@ -1,40 +1,39 @@
const CITE_STR_JL =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the following packages: "*
"LabelledArrays.jl\\cite[LabelledArrays]{DifferentialEquations.jl-2017}, "*
"QuadGK.jl\\cite[QuadGK]{quadgk}, Symbolics.jl\\cite[Symbolics]{gowda2021high}, "*
"RecursiveArrayTools.jl\\cite[RecursiveArrayTools]{DifferentialEquations.jl-2017}, "*
"ArrayInterface.jl\\cite[ArrayInterface]{DifferentialEquations.jl-2017} and "*
"AbstractAlgebra.jl\\cite[AbstractAlgebra]{AbstractAlgebra.jl-2017}."

const CITE_STR_JL_AUTO =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the following packages: "*
"LabelledArrays.jl\\cite[LabelledArrays]{DifferentialEquations.jl-2017}, "*
"QuadGK.jl\\cite[QuadGK]{quadgk}, Symbolics.jl\\cite[Symbolics]{gowda2021high}, "*
"RecursiveArrayTools.jl\\cite[RecursiveArrayTools]{DifferentialEquations.jl-2017}, "*
"ArrayInterface.jl\\cite[ArrayInterface]{DifferentialEquations.jl-2017} and "*
"AbstractAlgebra.jl\\autocite[AbstractAlgebra]{AbstractAlgebra.jl-2017}."

const CITE_STR_JL_SINGLE =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the Symbolics.jl\\cite[Symbolics]{gowda2021high} package."

const CITE_STR_JL_SINGLE_TT =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the \\texttt{Symbolics.jl}\\cite[Symbolics]{gowda2021high} package."


const CITE_STR =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the following packages: "*
"LabelledArrays\\cite[LabelledArrays]{DifferentialEquations.jl-2017}, "*
"QuadGK\\cite[QuadGK]{quadgk}, Symbolics\\cite[Symbolics]{gowda2021high}, "*
"RecursiveArrayTools\\cite[RecursiveArrayTools]{DifferentialEquations.jl-2017}, "*
"ArrayInterface\\cite[ArrayInterface]{DifferentialEquations.jl-2017} and "*
"AbstractAlgebra\\cite[AbstractAlgebra]{AbstractAlgebra.jl-2017}."

const CITE_BADGE =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the Plots.jl\\cite[Plots]{https://doi.org/10.5281/zenodo.4725317} "*
"and WriteVTK.jl\\cite[WriteVTK]{https://doi.org/10.5281/zenodo.4692172} packages."
const CITE_STR_JL =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the following packages: "*
"ArrayInterface.jl\\cite[ArrayInterface]{DifferentialEquations.jl-2017}, "*
"LabelledArrays.jl\\cite[LabelledArrays]{DifferentialEquations.jl-2017}, "*
"QuadGK.jl\\cite[QuadGK]{quadgk}, "*
"RecursiveArrayTools.jl\\cite[RecursiveArrayTools]{DifferentialEquations.jl-2017} and "*
"Symbolics.jl\\cite[Symbolics]{gowda2021high}."

const CITE_STR_JL_AUTO =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the following packages: "*
"ArrayInterface.jl\\cite[ArrayInterface]{DifferentialEquations.jl-2017}, "*
"LabelledArrays.jl\\cite[LabelledArrays]{DifferentialEquations.jl-2017}, "*
"QuadGK.jl\\cite[QuadGK]{quadgk}, "*
"RecursiveArrayTools.jl\\cite[RecursiveArrayTools]{DifferentialEquations.jl-2017} and "*
"Symbolics.jl\\autocite[Symbolics]{gowda2021high}."

const CITE_STR_JL_SINGLE =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the Symbolics.jl\\cite[Symbolics]{gowda2021high} package."

const CITE_STR_JL_SINGLE_TT =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the \\texttt{Symbolics.jl}\\cite[Symbolics]{gowda2021high} package."

const CITE_STR =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the following packages: "*
"ArrayInterface\\cite[ArrayInterface]{DifferentialEquations.jl-2017}, "*
"LabelledArrays\\cite[LabelledArrays]{DifferentialEquations.jl-2017}, "*
"QuadGK\\cite[QuadGK]{quadgk}, "*
"RecursiveArrayTools\\cite[RecursiveArrayTools]{DifferentialEquations.jl-2017} and "*
"Symbolics\\cite[Symbolics]{gowda2021high}."

const CITE_BADGE =
"This work was done in \\cite[Julia v$VERSION]{Julia-2017} "*
"and made use of the Plots.jl\\cite[Plots]{https://doi.org/10.5281/zenodo.4725317} "*
"and WriteVTK.jl\\cite[WriteVTK]{https://doi.org/10.5281/zenodo.5068937} packages."
6 changes: 2 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ include("cite_str.jl")
@test "Symbolics" ∈ pkgs
@test "RecursiveArrayTools" ∈ pkgs
@test "ArrayInterface" ∈ pkgs
@test "AbstractAlgebra" ∈ pkgs
# There is an error in the CITATION.bib for Distributions
@test_broken haskey(citations, "Distributions")
end
Expand All @@ -35,7 +34,6 @@ include("cite_str.jl")
bib = bibliography(citations)
@test haskey(bib, "DifferentialEquations.jl-2017")
@test haskey(bib, "quadgk")
@test haskey(bib, "AbstractAlgebra.jl-2017")
@test haskey(bib, "gowda2021high")
end

Expand All @@ -48,7 +46,6 @@ include("cite_str.jl")

@test haskey(bib, "DifferentialEquations.jl-2017")
@test haskey(bib, "quadgk")
@test haskey(bib, "AbstractAlgebra.jl-2017")
@test haskey(bib, "gowda2021high")
end

Expand All @@ -68,7 +65,7 @@ include("cite_str.jl")
str = make_sentence(citations, jl=false)
@test str == CITE_STR

str = make_sentence(citations, cite_commands=Dict{String,String}("AbstractAlgebra"=>"\\autocite"))
str = make_sentence(citations, cite_commands=Dict{String,String}("Symbolics"=>"\\autocite"))
@test str == CITE_STR_JL_AUTO

@testset "Clipboard" begin
Expand All @@ -89,6 +86,7 @@ include("cite_str.jl")
@test_broken clipboard() == CITE_STR
end
end

@testset "PkgCite using badge" begin
zenodo_env = "badge_env"
Pkg.activate(zenodo_env)
Expand Down
Loading