JuliaInterop / JuliaCall

Embed Julia in R
https://non-contradiction.github.io/JuliaCall/index.html
Other
267 stars 36 forks source link

Setup script affected by Julia 1.4 artifact downloading #128

Open JackDunnNZ opened 4 years ago

JackDunnNZ commented 4 years ago

In Julia 1.4, the artifact download process prints to stdout by default (a change from 1.3 where it was silent by default). This means that the first run of julia during the setup process might clutter stdout with other input and affect the values that are read from stdout during the setup script.

As an example, I have replaced the default system image with a custom system image containing a package that depends on some artifact. If I delete .julia/artifacts and start Julia, the first thing it does during initialization is download the missing artifact, which pollutes stdout and corrupts the setup process.

To reproduce, the steps to generate a simple system image like this are:

pkg> add PackageCompiler
julia> using PackageCompiler
pkg> activate temp
pkg> add MbedTLS
julia> create_sysimage(:MbedTLS, replace_default=true)

then remove the artifacts directory rm -rf .julia/artifacts and start julia again, where you get:

$ julia1.4.0
Downloading artifact: MbedTLS
######################################################################## 100.0%##O=#  #                                _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.4.0 (2020-03-21)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

To show how it affects JuliaCall, if I delete the artifacts directory again, and then try to run julia_setup I get the following:

> JuliaCall::julia_setup()
################################################################################################# 100.0%################################################################################################# 100.0%
sh: Downloading artifact: MbedTLS/julia: No such file or directory
Error in system2(file.path(.julia$bin_dir, "julia"), shQuote(command),  :
  error in running command
> JuliaCall:::.julia$bin_dir
[1] "Downloading artifact: MbedTLS"

It seems like one fix might be to take the last line of the output rather than the full output, but I don't know enough about the package to know what the best fix is. It doesn't seem like there is a global flag in Julia to disable this output.

Non-Contradiction commented 4 years ago

Thanks for the feedback! I just pushed two commits, which should fix the bug. Could you try the master to see whether the fix works? Thanks!

JackDunnNZ commented 4 years ago

Thanks for the quick response! Unfortunately it didn't quite work:

> JuliaCall::julia_setup()
############################################################################################################################################################# 100.0%############################################################################################################################################################# 100.0%
    /Applications/Julia-1.4.0.app/Contents/Resources/julia/bin/julia: No such file or directory
Error in system2(file.path(.julia$bin_dir, "julia"), shQuote(command),  :
  error in running command

Here is the content of the captured output, it looks like there are some terminal escape sequences there that are messing with things:

[1] "Downloading artifact: MbedTLS"
[2] "\033[?25l\033[1A\033[2K\033[?25h/Applications/Julia-1.4.0.app/Contents/Resources/julia/bin"
Non-Contradiction commented 4 years ago

Thanks for the report! I tried to find a reliable way to remove the escape sequences but failed. To avoid the problem altogether, I just pushed a commit that does twice the job. Since the artifact downloading should not affect the second result, the bug should be fixed. And it works for my windows machine. The only downside is that this adds setup time ~0.5s on my windows laptop.

Could you try the master to see whether it works? Thanks!

JackDunnNZ commented 4 years ago

Thanks, it seems to work!

I was just thinking and I wonder if another solution could be to write an extra line to the output stream before the real data, to ensure that the last line is only coming from the desired command?

e.g. println("\n", JULIA_HOME) instead of println(JULIA_HOME)

Just a thought in case you were concerned about the extra startup time. Either way, thanks for the quick fix!