Last active
May 29, 2025 13:14
-
-
Save disberd/c5a7a5e3e03e8f0d2ab451969ed84011 to your computer and use it in GitHub Desktop.
file to include for overriding Pkg downloads to use OS curl rather than Downloads.download
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import Pkg | |
| @info "Overriding Pkg.PlatformEngines.download to use OS's curl for artifacts" | |
| @eval Pkg.PlatformEngines function download( | |
| url::AbstractString, | |
| dest::AbstractString; | |
| verbose::Bool = false, | |
| headers::Vector{Pair{String,String}} = Pair{String,String}[], | |
| auth_header::Union{Pair{String,String}, Nothing} = nothing, | |
| io::IO=stderr_f(), | |
| progress::Union{Nothing,Function} = nothing, # (total, now) -> nothing | |
| ) | |
| if auth_header === nothing | |
| auth_header = get_auth_header(url, verbose=verbose) | |
| end | |
| if auth_header !== nothing | |
| push!(headers, auth_header) | |
| end | |
| for header in get_metadata_headers(url) | |
| push!(headers, header) | |
| end | |
| do_fancy = verbose && can_fancyprint(io) | |
| progress = if !isnothing(progress) | |
| progress | |
| elseif do_fancy | |
| bar = MiniProgressBar(header="Downloading", color=Base.info_color()) | |
| start_progress(io, bar) | |
| let bar=bar | |
| (total, now) -> begin | |
| bar.max = total | |
| bar.current = now | |
| # Downloads.download attatches the progress indicator to the header request too | |
| # which is only ~100 bytes, and will report as 0 - 100% progress immediately | |
| # then dip down to 0 before the actual download starts. So we only show the | |
| # progress bar once the real download starts. | |
| total > 1000 && show_progress(io, bar) | |
| end | |
| end | |
| else | |
| nothing | |
| end | |
| try | |
| if startswith(url, "https://pkg.julialang.org") || startswith(url, "https://github.com") | |
| # We override the default download command with this cursed function to use the OS's curl for requests to pkg.julialang.org | |
| cmd = `curl -sS -L -o $dest` | |
| for header in headers | |
| key, val = header | |
| push!(cmd.exec, "-H", "$key: $val") | |
| end | |
| push!(cmd.exec, url) | |
| run(cmd) | |
| else | |
| Downloads.download(url, dest; headers, progress) | |
| end | |
| finally | |
| do_fancy && end_progress(io, bar) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment