Dependency without dependency

Hey everyone, I have the following situation in my hands, and I’d like to get some perspective from the community:

Suppose I’m developing a package and I wish to provide the user with a function that requires a package like Flux.jl. Now, my package per se does not uses Flux, and I just wish to provide this function to the user such that he can use it “if” he has Flux.jl, for example:

using MyPackage
runfluxfunction()
# This returns an error.
using MyPackage
using Flux
runfluxfunction()
# This works.

I was wondering if it’s possible to do something like this, or if it’s bad practice for some reason. This would be really nice, cause this function might not be needed for every user, and I could leave Flux.jl out of as a dependency, which would make the precompilation faster.

See this package

it might solve your problem.

Tomas

4 Likes

You’ll also want to know about Proposal for first class support of conditional dependencies in Pkg · Issue #1285 · JuliaLang/Pkg.jl · GitHub

Won’t happen tomorrow though, just trying to drum up support.

4 Likes

Good to know there are option out there. I thought about using metaprogramming to do this. I mean, the function would be pretty much just a string that the end user could ‘eval’. But I guessed this was a “dont” for some reason. (I didn’t think it through too much).

I would go with Requires.jl. it’s quite straightforward.