Skip to content

Commit 77a10eb

Browse files
committed
make FileIO weak
1 parent 84be7a1 commit 77a10eb

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

Project.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
1111
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
1212
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
1313
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
14-
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
1514
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1615
MarchingCubes = "299715c1-40a9-479a-aaf9-4a633d36f717"
1716
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
@@ -42,14 +41,16 @@ julia = "1.6"
4241
[weakdeps]
4342
FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43"
4443
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
44+
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
4545

4646
[extensions]
47-
FreeTypeExt = "FreeType"
47+
FreeTypeExt = ["FreeType", "FileIO"]
4848
ImageInTerminalExt = "ImageInTerminal"
4949

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

6364
[targets]
64-
test = ["Aqua", "DataFrames", "FreeType", "ImageInTerminal", "ImageMagick", "Random", "ReferenceTests", "StableRNGs", "Test", "TestImages", "TimerOutputs"]
65+
test = ["Aqua", "DataFrames", "FileIO", "FreeType", "ImageInTerminal", "ImageMagick", "Random", "ReferenceTests", "StableRNGs", "Test", "TestImages", "TimerOutputs"]

ext/FreeTypeExt.jl

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
module FreeTypeExt
55

66
import UnicodePlots
7-
isdefined(Base, :get_extension) ? (using FreeType) : (using ..FreeType)
7+
@static if isdefined(Base, :get_extension)
8+
using FreeType, FileIO
9+
else
10+
using ..FreeType, ..FileIO
11+
end
812
using StaticArrays
913
using ColorTypes
1014

@@ -99,6 +103,8 @@ function UnicodePlots.get_font_face(font = nothing, fallback = fallback_fonts())
99103
face
100104
end
101105

106+
UnicodePlots.save_png(args...; kw...) = FileIO.save(args...; kw...)
107+
102108
"""
103109
Match a font using the user-specified search string. Each part of the search string
104110
is searched in the family name first which has to match once to include the font

src/UnicodePlots.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import ColorSchemes
1818
import Requires
1919
import NaNMath
2020
import Contour
21-
import FileIO
2221

2322
# composite types
2423
export Plot,
@@ -127,9 +126,11 @@ function __init__()
127126
Requires.@require ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254" include(
128127
"../ext/ImageInTerminalExt.jl",
129128
)
130-
Requires.@require FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43" include(
131-
"../ext/FreeTypeExt.jl",
132-
)
129+
Requires.@require FreeType = "b38be410-82b0-50bf-ab77-7b57e271db43" begin
130+
Requires.@require FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" include(
131+
"../ext/FreeTypeExt.jl",
132+
)
133+
end
133134
end
134135
nothing
135136
end

src/show.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,6 +401,7 @@ end
401401
# `FreeTypeExt` placeholders
402402
function get_font_face end
403403
function render_string! end
404+
function save_png end
404405

405406
"""
406407
png_image(p::Plot, font = nothing, pixelsize = 32, transparent = true, foreground = nothing, background = nothing, bounding_box = nothing, bounding_box_glyph = nothing)
@@ -596,7 +597,7 @@ function savefig(p::Plot, filename::AbstractString; color::Bool = false, kw...)
596597
elseif ext == ".png"
597598
# `png_image` can fail if fonts are not found: a warning has already been
598599
# thrown there, so just bail out at this stage
599-
(img = png_image(p; kw...)) nothing && FileIO.save(filename, img)
600+
(img = png_image(p; kw...)) nothing && save_png(filename, img)
600601
else
601602
"extension \"$ext\" is unsupported: `savefig` only supports writing to `txt` or `png` files" |>
602603
ArgumentError |>

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using ImageInTerminal, FreeType
1+
using ImageInTerminal, FreeType, FileIO # weak deps, or @require
22
using UnicodePlots, Test
33

44
import UnicodePlots: lines!, points!, pixel!, nrows, ncols

test/tst_quality.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@testset "Aqua" begin
22
# JuliaTesting/Aqua.jl/issues/77
3-
Aqua.test_all(UnicodePlots; ambiguities = false)
3+
Aqua.test_all(UnicodePlots; ambiguities = false, project_toml_formatting = false)
44
Aqua.test_ambiguities(UnicodePlots)
55
end

0 commit comments

Comments
 (0)