Packaging best practices for adding dependencies

Hi, I’m wondering whether it’s necessary or desirable to add dependencies which are in the standard library?
The example in the docs shows adding Random to a project.toml but is this necessary?

  1. Couldn’t you just add an import Random to the Module.jl without adding to [deps]?
  2. Are there any downsides to adding everything? Over-specifying dependencies.
  3. Should I add Base to deps if I import it and extend :+, :-, abs for a type?

To the best of my knowledge:

  1. The code loading stuff checks all imported packages against the Project.toml file. Another way to think about it is that a package’s Project.toml file is the “source of truth” defining its dependencies.
  2. You don’t have to add everything, just the immediate dependencies (e.g. if you need to import A and A depends on B: you just need to add A. Pkg will take care of handling recursive dependencies.

The long term plan is for standard libraries to behave like regular packages as much as possible.

1 Like