Skip to content

Commit

Permalink
reduce using
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Nov 12, 2024
1 parent 962cc6d commit 6ee9f65
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 42 deletions.
20 changes: 11 additions & 9 deletions PlotsBase/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ version = "0.1"

[deps]
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Downloads = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
FFMPEG = "c87230d0-a227-11e9-1b43-d7ebe4e7570a"
FixedPointNumbers = "53c48c17-4a7d-5ca2-90c5-79b7896eea93"
JLFzf = "1019f520-868f-41f5-a6de-eb00f4b6a39c"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Measures = "442fdcdd-2543-5da2-b0f3-8c86c306513e"
NaNMath = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3"
Expand All @@ -27,31 +24,33 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
RecipesPipeline = "01d81517-befc-4cb6-b9ec-a95719d0359c"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Scratch = "6c6a2e73-6563-6170-7368-637461726353"
Showoff = "992d4aef-0814-514b-bc4d-f2e9a6c4116f"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
UnicodeFun = "1cfade01-22cf-5700-b092-accc4b62d6e1"
UnitfulLatexify = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"
Unzip = "41fe7b60-77ed-43a1-b4f0-825fd5a5650d"

[weakdeps]
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
GR = "28b8d3ca-fb5f-59d9-8090-bfdbd6d07a71"
Gaston = "4b11ee91-296f-5714-9832-002c20994614"
GeometryBasics = "5c1252a2-5f33-56bf-86c9-59e7332b4326"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
ImageInTerminal = "d8c32880-2388-543b-8c61-d9f865259254"
Latexify = "23fbe1c1-3f47-55db-b15f-69d7ec21a316"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
PlotlyKaleido = "f2990250-8cf9-495f-b13a-cce12b45703c"
PythonPlot = "274fc56d-3b97-40fa-a1cd-1b4a50311bf9"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulLatexify = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"

[extensions]
FileIOExt = "FileIO"
Expand All @@ -61,12 +60,12 @@ GeometryBasicsExt = "GeometryBasics"
HDF5Ext = "HDF5"
IJuliaExt = "IJulia"
ImageInTerminalExt = "ImageInTerminal"
PGFPlotsXExt = "PGFPlotsX"
PGFPlotsXExt = ["Contour", "Latexify", "LaTeXStrings", "PGFPlotsX"]
PlotlyJSExt = "PlotlyJS"
PlotlyKaleidoExt = "PlotlyKaleido"
PythonPlotExt = "PythonPlot"
UnicodePlotsExt = "UnicodePlots"
UnitfulExt = "Unitful"
UnitfulExt = ["LaTeXStrings", "Unitful", "UnitfulLatexify"]

[compat]
Base64 = "1"
Expand Down Expand Up @@ -98,7 +97,6 @@ REPL = "1"
RecipesBase = "1.3.1"
RecipesPipeline = "1"
Reexport = "1"
RelocatableFolders = "1"
Scratch = "1"
Showoff = "1"
SparseArrays = "1"
Expand All @@ -114,6 +112,7 @@ julia = "1.10"
[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Contour = "d38c429a-6771-53c6-b99e-75d170b6e991"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
FilePathsBase = "48062228-2e41-5def-b9a4-89aafe57970f"
Expand All @@ -125,6 +124,8 @@ Gtk = "4c0ca9eb-093a-5379-98c5-f87ac0bbbf44"
HDF5 = "f67ccb44-e63f-5c2f-98bd-6dc0ccc4ba2f"
Images = "916415d5-f1e6-5110-898d-aaa5f9f070e0"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
Latexify = "76f85450-5226-5b5a-8eaa-529ad045b433"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925"
PlotlyJS = "f0f68f2c-4968-5e81-91da-67840de0976a"
Expand All @@ -138,7 +139,8 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
TestImages = "5e47fb64-e119-507b-a336-dd2b206d9990"
UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228"
Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"
UnitfulLatexify = "45397f5d-5981-4c77-b2b3-fc36d6e9b728"
VisualRegressionTests = "34922c18-7c2a-561c-bac1-01e79b2c4c92"

[targets]
test = ["Aqua", "Colors", "Distributions", "FileIO", "FilePathsBase", "FreeType", "Gaston", "GeometryBasics", "GR", "Gtk", "HDF5", "Images", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyKaleido", "PythonPlot", "RDatasets", "SentinelArrays", "StableRNGs", "StaticArrays", "Test", "TestImages", "UnicodePlots", "Unitful", "VisualRegressionTests"]
test = ["Aqua", "Colors", "Contour", "Distributions", "FileIO", "FilePathsBase", "FreeType", "Gaston", "GeometryBasics", "GR", "Gtk", "HDF5", "Images", "Latexify", "LaTeXStrings", "LibGit2", "OffsetArrays", "PGFPlotsX", "PlotlyJS", "PlotlyKaleido", "PythonPlot", "RDatasets", "SentinelArrays", "StableRNGs", "StaticArrays", "Test", "TestImages", "UnicodePlots", "Unitful", "UnitfulLatexify", "VisualRegressionTests"]
2 changes: 1 addition & 1 deletion PlotsBase/ext/GRExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2290,7 +2290,7 @@ function PlotsBase._display(plt::Plot{GRBackend})
GR.emergencyclosegks()
println(
"\033]1337;File=inline=1;preserveAspectRatio=0:",
base64encode(open(read, filepath)),
Base64.base64encode(open(read, filepath)),
"\a",
)
rm(filepath)
Expand Down
6 changes: 3 additions & 3 deletions PlotsBase/ext/IJuliaExt.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module IJuliaExt

import PlotsBase: PlotsBase, Plot
using Base64
import Base64

# NOTE: cannot use import IJulia
const IJulia =
Expand All @@ -28,7 +28,7 @@ function _ijulia_display_dict(plt::Plot)
out[mime] = sprint(show, MIME(mime), plt)
elseif output_type :png
mime = "image/png"
out[mime] = base64encode(show, MIME(mime), plt)
out[mime] = Base64.base64encode(show, MIME(mime), plt)
elseif output_type :svg
mime = "image/svg+xml"
out[mime] = sprint(show, MIME(mime), plt)
Expand All @@ -38,7 +38,7 @@ function _ijulia_display_dict(plt::Plot)
PlotsBase._ijulia__extra_mime_info!(plt, out)
elseif output_type :pdf
mime = "application/pdf"
out[mime] = base64encode(show, MIME(mime), plt)
out[mime] = Base64.base64encode(show, MIME(mime), plt)
else
error("Unsupported output type $output_type")
end
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/src/Commons/Commons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ using ..ColorTypes: alpha
using ..RecipesBase
using ..Statistics
using ..NaNMath
using ..Unzip
using ..Printf
using ..Unzip

const width = Measures.width
const height = Measures.height
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/src/Fonts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,4 @@ end # module

# -----------------------------------------------------------------------------

@reexport using .Fonts
Reexport.@reexport using .Fonts
44 changes: 27 additions & 17 deletions PlotsBase/src/PlotsBase.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,32 @@ if isdefined(Base, :Experimental) && isdefined(Base.Experimental, Symbol("@max_m
@eval Base.Experimental.@max_methods 1
end

using Pkg, Dates, Printf, Statistics, Base64, LinearAlgebra, SparseArrays, Random
using PrecompileTools, Preferences, Reexport, RelocatableFolders
using Base.Meta
@reexport using RecipesBase
@reexport using PlotThemes
@reexport using PlotUtils

import PrecompileTools
import LinearAlgebra
import SparseArrays
import Preferences
import UnicodeFun
import Statistics
import StatsBase
import Downloads
import Reexport
import Measures
import NaNMath
import Showoff
import Random
import Base64
import Printf
import Dates
import Unzip
import JLFzf
import JSON
import Pkg

Reexport.@reexport using RecipesBase
Reexport.@reexport using PlotThemes
Reexport.@reexport using PlotUtils

import RecipesBase: plot, plot!, animate, is_explicit, grid
import RecipesPipeline:
Expand All @@ -34,14 +54,6 @@ import RecipesPipeline:
pop_kw!,
Volume,
is3d
import UnicodeFun
import StatsBase
import Downloads
import Measures
import Showoff
import Unzip
import JLFzf
import JSON

#! format: off
export
Expand Down Expand Up @@ -113,8 +125,6 @@ export
resetfontsizes

#! format: on
import NaNMath

const _project = Pkg.Types.read_package(normpath(@__DIR__, "..", "Project.toml"))
const _version = _project.version
const _compat = _project.compat
Expand Down Expand Up @@ -160,7 +170,7 @@ include("init.jl")
include("users.jl")

# COV_EXCL_START
@setup_workload begin
PrecompileTools.@setup_workload begin
backend(:none)
n = length(_examples)
imports = sizehint!(Expr[], n)
Expand All @@ -179,7 +189,7 @@ include("users.jl")
$func()
end)
end
@compile_workload begin
PrecompileTools.@compile_workload begin
backend(:none)
eval.(imports)
eval.(examples)
Expand Down
6 changes: 3 additions & 3 deletions PlotsBase/src/animation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,12 @@ end
# write out html to view the gif
function Base.show(io::IO, ::MIME"text/html", agif::AnimatedGif)
html = if (ext = file_extension(agif.filename)) == "gif"
"<img src=\"data:image/gif;base64,$(base64encode(read(agif.filename)))\" />"
"<img src=\"data:image/gif;base64,$(Base64.base64encode(read(agif.filename)))\" />"
elseif ext == "apng"
"<img src=\"data:image/png;base64,$(base64encode(read(agif.filename)))\" />"
"<img src=\"data:image/png;base64,$(Base64.base64encode(read(agif.filename)))\" />"
elseif ext in ("mov", "mp4", "webm")
mimetype = ext == "mov" ? "video/quicktime" : "video/$ext"
"<video autoplay controls><source src=\"data:$mimetype;base64,$(base64encode(read(agif.filename)))\" type = \"$mimetype\"></video>"
"<video autoplay controls><source src=\"data:$mimetype;base64,$(Base64.base64encode(read(agif.filename)))\" type = \"$mimetype\"></video>"
else
error("Cannot show animation with extension $ext: $agif")
end
Expand Down
8 changes: 4 additions & 4 deletions PlotsBase/src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ end
# "Preferences that are accessed during compilation are automatically marked as compile-time preferences"
# ==> this must always be done during precompilation, otherwise
# the cache will not invalidate when preferences change
const DEFAULT_BACKEND = lowercase(load_preference(PlotsBase, "default_backend", "gr"))
const DEFAULT_BACKEND = lowercase(Preferences.load_preference(PlotsBase, "default_backend", "gr"))

function default_backend()
# environment variable preempts the `Preferences` based mechanism
Expand All @@ -78,18 +78,18 @@ function set_default_backend!(
kw...,
)
if backend nothing
delete_preferences!(PlotsBase, "default_backend"; force, kw...)
Preferences.delete_preferences!(PlotsBase, "default_backend"; force, kw...)
else
# NOTE: `_check_installed` already throws a warning
if (value = lowercase(string(backend))) |> PlotsBase._check_installed nothing
set_preferences!(PlotsBase, "default_backend" => value; force, kw...)
Preferences.set_preferences!(PlotsBase, "default_backend" => value; force, kw...)
end
end
nothing
end

function diagnostics(io::IO = stdout)
origin = if has_preference(PlotsBase, "default_backend")
origin = if Preferences.has_preference(PlotsBase, "default_backend")
"`Preferences`"
elseif haskey(ENV, "PLOTSBASE_DEFAULT_BACKEND")
"environment variable"
Expand Down
2 changes: 1 addition & 1 deletion PlotsBase/src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ function _show(io::IO, ::MIME"text/html", plt::Plot)
print(
io,
"<img src=\"data:image/png;base64,",
base64encode(show, MIME("image/png"), plt),
Base64.base64encode(show, MIME("image/png"), plt),
"\" />",
)
elseif output_type :svg
Expand Down
6 changes: 6 additions & 0 deletions PlotsBase/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ using FileIO
using Dates
using Test

# backends weakdeps
import UnitfulLatexify
import Latexify
import Contour
import

function available_channels()
juliaup = "https://julialang-s3.julialang.org/juliaup"
for i 1:6
Expand Down
3 changes: 1 addition & 2 deletions PlotsBase/test/test_quality.jl
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
@testset "Auto QUality Assurance" begin
# JuliaTesting/Aqua.jl/issues/77
# TODO: fix :Contour, :Latexify and :LaTeXStrings stale imports in Plots 2.0
# :CondaPkg stale deps show up when running CI
Aqua.test_all(
PlotsBase;
stale_deps = (;
ignore = [:CondaPkg, :Contour, :UnitfulLatexify, :LaTeXStrings, :Latexify]
ignore = [:CondaPkg, :LaTeXStrings]
),
persistent_tasks = false,
ambiguities = false,
Expand Down

0 comments on commit 6ee9f65

Please sign in to comment.