JuliaPlots / UnicodePlots.jl

Unicode-based scientific plotting for working in the terminal
Other
1.45k stars 82 forks source link

redefinition warnings and error on exit when using with CairoMakie #334

Closed ExpandingMan closed 10 months ago

ExpandingMan commented 1 year ago

Whenever I import both UnicodePlots.jl and CairoMakie.jl, I get the following warnings

WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.

(when the second package is imported, order doesn't matter).

After getting these warnings, when you exist Julia, you get

Library == CNULL. done() called before init(), or done called two times?
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:35
 [2] ft_done()
   @ UnicodePlots.FreeTypeExt ~/.julia/packages/UnicodePlots/VGDaL/ext/FreeTypeExt.jl:421
 [3] _atexit()
   @ Base ./initdefs.jl:372

I assume there is some dependency of both packages that is behaving badly when imported twice. Anyone know where this might be coming from?

t-bltg commented 1 year ago

Hum, I've shamelessly copied a portion of FreeTypeAbstraction.jl in https://github.com/JuliaPlots/UnicodePlots.jl/pull/294 to reduce dependencies (user request at https://github.com/JuliaPlots/UnicodePlots.jl/issues/291).

However, the WARNING: redefinition is weird, since the code lives in https://github.com/JuliaPlots/UnicodePlots.jl/blob/master/ext/FreeTypeExt.jl now, which is a dedicated module.

Is it on 1.9.0-beta4 with package extensions - weak deps or on an earlier julia version (thus using Requires) ?

ExpandingMan commented 1 year ago

This is on 1.8.5.

t-bltg commented 1 year ago

Could you clarify what the reproducer is (with versions) ?

This doesn't give me anything, neither on 1.8.5, nor on 1.9.0-beta4 (linux):

$ julia
julia> using FreeType, FileIO  # optional, make sure `FreeTypeExt` from `UnicodePlots` will be loaded
julia> using CairoMakie
julia> using UnicodePlots  # the import order doesn't seem to matter
julia> exit(0)
$ # no warnings ?

On CairoMakie@0.10.2, UnicodePlots@3.4.0.

ExpandingMan commented 1 year ago

Here is a MWE, in a fresh environment, I get

◖◗ using UnicodePlots, CairoMakie
[ Info: Precompiling CairoMakie [13f3f980-e62b-5c42-98c6-ff1f3baf88f0]
WARNING: Makie.MakieLayout is deprecatedThe module `MakieLayout` has been removed and integrated into Makie, so simply replace all usage of `MakieLayout` with `Makie`.
  likely near none:1
WARNING: importing deprecated binding Makie.MakieLayout into CairoMakie.
WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.

Manifest.log Project.log

Here are the project and manifest of the environment... I had to change the extension to .log to trick github into letting me upload them, how silly.

This is on linux btw.

t-bltg commented 1 year ago

Hum, still nothing on my side on 1.8.5. Anything special in your startup.jl ? Maybe Revise ?

ExpandingMan commented 1 year ago

Revise and OhMyREPL. My startup.jl can be found here.

Perhaps Revise is improperly trying to redefine stuff for some reason?

t-bltg commented 1 year ago

Right, that's Revise interfering for whatever reason:

julia> VERSION
v"1.8.5"
julia> using Revise
julia> using UnicodePlots, CairoMakie
WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.
julia> UnicodePlots.FreeTypeExt
UnicodePlots.FreeTypeExt

But it doesn't occur on 1.9.0-beta4 (package extensions - weak deps):

julia> VERSION
v"1.9.0-beta4"
julia> using Revise
julia> using UnicodePlots, CairoMakie
julia> Base.get_extension(UnicodePlots, :FreeTypeExt)
FreeTypeExt
ExpandingMan commented 1 year ago

Hm... worth opening an issue with Revise maybe? I assume there must be something unusual happening, do you have an idea what might specifically be causing Revise to do this?

t-bltg commented 1 year ago

do you have an idea what might specifically be causing Revise to do this?

Nope no idea, I think UnicodePlots using Requires with multiple requirements is valid, and the offending code defining FT_LIB, VALID_FONTPATHS and friends in enclosed in a module, so it shouldn't happen.

Looks like __init__ is called twice somehow.

worth opening an issue with Revise maybe?

Ping @timholy if he has any clue on this (hoping he's not too busy :slightly_smiling_face: ).

asinghvi17 commented 1 year ago

From the error statement, it seems like CairoMakie is out of date.

Could you post the version of CairoMakie and Makie for which this happened? Perhaps upgrading may help here.

t-bltg commented 1 year ago

CairoMakie 0.10.2 is already the latest release (Makie 0.19.2), see the .log posted by @ExpandingMan.

ericphanson commented 1 year ago

I'm getting crashes in a complicated setup with PythonCall in a package for which UnicodePlots is an indirect dependency which seems to point at this:

#25 63.34 WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
#25 63.34 WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
#25 63.41 WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.
#25 84.61 WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
#25 84.61 WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
#25 84.66 WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.
#25 95.74 Library == CNULL. done() called before init(), or done called two times?
#25 97.03 Stacktrace:
#25 97.03  [1] error(s::String)
#25 97.07    @ Base ./error.jl:35
#25 97.07  [2] ft_done()
#25 97.07    @ UnicodePlots.FreeTypeExt ~/.julia/packages/UnicodePlots/VGDaL/ext/FreeTypeExt.jl:421
#25 97.07  [3] _atexit()
#25 97.07    @ Base ./initdefs.jl:372
#25 101.9 WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
#25 101.9 WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
#25 102.0 WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.
#25 113.8 Library == CNULL. done() called before init(), or done called two times?
#25 115.5 Stacktrace:
#25 115.5  [1] error(s::String)
#25 115.5    @ Base ./error.jl:35
#25 115.5  [2] ft_done()
#25 115.5    @ UnicodePlots.FreeTypeExt ~/.julia/packages/UnicodePlots/VGDaL/ext/FreeTypeExt.jl:421
#25 115.5  [3] _atexit()
#25 115.5    @ Base ./initdefs.jl:372
#25 120.2 WARNING: redefinition of constant FT_LIB. This may fail, cause incorrect answers, or produce other errors.
#25 120.2 WARNING: redefinition of constant VALID_FONTPATHS. This may fail, cause incorrect answers, or produce other errors.
#25 120.3 WARNING: redefinition of constant FT_FONTS. This may fail, cause incorrect answers, or produce other errors.
#25 131.4 Library == CNULL. done() called before init(), or done called two times?
#25 133.1 Stacktrace:
#25 133.1  [1] error(s::String)
#25 133.2    @ Base ./error.jl:35
#25 133.2  [2] ft_done()
#25 133.2    @ UnicodePlots.FreeTypeExt ~/.julia/packages/UnicodePlots/VGDaL/ext/FreeTypeExt.jl:421
#25 133.2  [3] _atexit()
#25 133.2    @ Base ./initdefs.jl:372
#25 134.2 fatal: error thrown and no exception handler available.
#25 134.2 InitError(mod=:C, error=ErrorException("no environment in the LOAD_PATH (["/root/.julia/environments/v1.8/Project.toml", "/usr/local/julia/share/julia/stdlib/v1.8"]) depends on CondaPkg"))
#25 134.3 error at ./error.jl:35
#25 134.3 _resolve_top_env at /root/.julia/packages/CondaPkg/j2Cct/src/resolve.jl:16
#25 134.3 #resolve#38 at /root/.julia/packages/CondaPkg/j2Cct/src/resolve.jl:404
#25 134.4 resolve at /root/.julia/packages/CondaPkg/j2Cct/src/resolve.jl:384
#25 134.4 envdir at /root/.julia/packages/CondaPkg/j2Cct/src/env.jl:70 [inlined]
#25 134.4 init_context at /root/.julia/packages/PythonCall/XgP8G/src/cpython/context.jl:56
#25 134.4 __init__ at /root/.julia/packages/PythonCall/XgP8G/src/cpython/CPython.jl:21
#25 134.4 jfptr___init___165614 at /deps.so (unknown line)
#25 134.4 _jl_invoke at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/gf.c:2367 [inlined]
#25 134.4 ijl_apply_generic at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/gf.c:2549
#25 134.4 jl_apply at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/julia.h:1839 [inlined]
#25 134.4 jl_module_run_initializer at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/toplevel.c:75
#25 134.4 _finish_julia_init at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/init.c:765
#25 134.4 julia_init at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/init.c:698
#25 134.4 jl_repl_entrypoint at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/src/jlapi.c:713
#25 134.4 main at /cache/build/default-amdci4-6/julialang/julia-release-1-dot-8/cli/loader_exe.c:59
#25 134.4 __libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
#25 134.4 unknown function (ip: 0x401098)
ericphanson commented 1 year ago

Actually I think the real error is unrelated (InitError(mod=:C, error=ErrorException("no environment in the LOAD_PATH ...) and this issue is just scary warning spam

t-bltg commented 1 year ago

I've opened an upstream report at https://github.com/timholy/Revise.jl/issues/736 with a minimal reproducer, since I believe this is an upstream Revise bug.