Skip to content

Package Options #458

@ChrisRackauckas

Description

@ChrisRackauckas

There are many cases where a package developer may want a user to be able to set package-wide options. For example, look at the NaN handling in ForwardDiff.jl

http://www.juliadiff.org/ForwardDiff.jl/latest/user/advanced.html#Fixing-NaN/Inf-Issues-1

In order to preserve performance in the majority of use cases, ForwardDiff disables this check by default. If your code is affected by this NaN behvaior, you can enable ForwardDiff's NaN-safe mode by setting the NANSAFE_MODE_ENABLED constant to true in ForwardDiff's source.

As of right now, the method that people are using is telling users to dirty their repo and modify a constant in the package code. That's pretty far from ideal. Another way this is sometimes done is via an environment variable which then sets a constant in a build, like in PyCall.jl:

ENV["PYTHON"] = "... path of the python program you want ..."
Pkg.build("PyCall")

which then saves a const in deps.jl. It seems that one way for users to do the ForwardDiff thing and have it be more approachable would be to have a fake package build that saves environment variables.

The last thing that can be done is globals can be set in __init__() which are then used in the package. But those would either be non-const or if they are const they would be in a Ref. So it's not good for something that would change dispatches like a type.

Solution

Of course, all of these are less than ideal. It would be nice to have one pre-compile-time options setup for packages that is query-able and used across the ecosystem. For example:

Pkg.options("ForwardDiff") # Prints an options doc
Pkg.set_option("ForwardDiff",:NANSAFE_MODE_ENABLED,false)

which then sets a constant in an options.jl file.

The reason it would be nice to have this baked into the package system is because then packages can directly do this for dependencies in the same namespacing manner that is done for normal dependency handling. There could be a spot in the manifest to set specific options. In some sense this is kind of like the options one would set in a Makefile.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions