Skip to content

Commit

Permalink
make FileIO weak
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Feb 4, 2023
1 parent 84be7a1 commit 77a10eb
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 11 deletions.
7 changes: 4 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MarchingCubes = "299715c1-40a9-479a-aaf9-4a633d36f717"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Expand Down Expand Up @@ -42,14 +41,16 @@ julia = "1.6"
[weakdeps]
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"

[extensions]
FreeTypeExt = "FreeType"
FreeTypeExt = ["FreeType", "FileIO"]
ImageInTerminalExt = "ImageInTerminal"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
Expand All @@ -61,4 +62,4 @@ TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
TimerOutputs = "a759f4b9-e2f1-59dc-863e-4aeb61b1ea8f"

[targets]
test = ["Aqua", "DataFrames", "FreeType", "ImageInTerminal", "ImageMagick", "Random", "ReferenceTests", "StableRNGs", "Test", "TestImages", "TimerOutputs"]
test = ["Aqua", "DataFrames", "FileIO", "FreeType", "ImageInTerminal", "ImageMagick", "Random", "ReferenceTests", "StableRNGs", "Test", "TestImages", "TimerOutputs"]
8 changes: 7 additions & 1 deletion ext/FreeTypeExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
module FreeTypeExt

import UnicodePlots
isdefined(Base, :get_extension) ? (using FreeType) : (using ..FreeType)
@static if isdefined(Base, :get_extension)
using FreeType, FileIO
else
using ..FreeType, ..FileIO
end
using StaticArrays
using ColorTypes

Expand Down Expand Up @@ -99,6 +103,8 @@ function UnicodePlots.get_font_face(font = nothing, fallback = fallback_fonts())
face
end

UnicodePlots.save_png(args...; kw...) = FileIO.save(args...; kw...)

"""
Match a font using the user-specified search string. Each part of the search string
is searched in the family name first which has to match once to include the font
Expand Down
9 changes: 5 additions & 4 deletions src/UnicodePlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import ColorSchemes
import Requires
import NaNMath
import Contour
import FileIO

# composite types
export Plot,
Expand Down Expand Up @@ -127,9 +126,11 @@ function __init__()
Requires.@require ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" include(
"../ext/ImageInTerminalExt.jl",
)
Requires.@require FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43" include(
"../ext/FreeTypeExt.jl",
)
Requires.@require FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43" begin
Requires.@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" include(
"../ext/FreeTypeExt.jl",
)
end
end
nothing
end
Expand Down
3 changes: 2 additions & 1 deletion src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ end
# `FreeTypeExt` placeholders
function get_font_face end
function render_string! end
function save_png end

"""
png_image(p::Plot, font = nothing, pixelsize = 32, transparent = true, foreground = nothing, background = nothing, bounding_box = nothing, bounding_box_glyph = nothing)
Expand Down Expand Up @@ -596,7 +597,7 @@ function savefig(p::Plot, filename::AbstractString; color::Bool = false, kw...)
elseif ext == ".png"
# `png_image` can fail if fonts are not found: a warning has already been
# thrown there, so just bail out at this stage
(img = png_image(p; kw...)) nothing && FileIO.save(filename, img)
(img = png_image(p; kw...)) nothing && save_png(filename, img)
else
"extension \"$ext\" is unsupported: `savefig` only supports writing to `txt` or `png` files" |>
ArgumentError |>
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using ImageInTerminal, FreeType
using ImageInTerminal, FreeType, FileIO # weak deps, or @require
using UnicodePlots, Test

import UnicodePlots: lines!, points!, pixel!, nrows, ncols
Expand Down
2 changes: 1 addition & 1 deletion test/tst_quality.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
@testset "Aqua" begin
# JuliaTesting/Aqua.jl/issues/77
Aqua.test_all(UnicodePlots; ambiguities = false)
Aqua.test_all(UnicodePlots; ambiguities = false, project_toml_formatting = false)
Aqua.test_ambiguities(UnicodePlots)
end

0 comments on commit 77a10eb

Please sign in to comment.