Set dub settings via environment variables
It should be possible to set dub settings via environment variables.
The idea is to make the existing private class DubConfig either abstract or an interface
https://github.com/dlang/dub/blob/master/source/dub/dub.d#L1724
and add 2 new classes: DubJsonConfig & DubEnvConfig.
Not 100% sure:
- While the key is
registryUrlsin JSON file, it should be namedDUB_REGISTRY_URLSas environment variable? - There is also already an existing environment variable
DUB_REGISTRYwhich has the same effect asDUB_REGISTRY_URLS
What's the use case for this ?
The scenario is as following: dub is embedded into another build system, e.g. xmake. Dub specific settings like architecture, compiler, registry, ... can be set as xmake parameters. The dub plugin I wrote for xmake will write the settings into the dub settings.json within folder $HOME/.dub.
This is somehow inconvenient and also has a disadvantage. Recently a feature was added that the dub settings.json could also be included within a dub package root folder. Therefore the dub settings.json I will write, is ignored.
But if I am able to specify the values as environment variables, I can overwritte some of the settings while other settings are loaded from the settings.json located in dub package root folder.
Frankly, it doesn't sound like something that should be done via dub settings, but rather CLI arguments.
But my knowledge of xmake is rather poor, so what's the original reason to go with this approach ?
From your description, it sounds like a user using xmake would not be able to define his/her own settings file ?
It is a common pattern supported by most console clients I know (aws client, pip, npm). For reference here the npm help https://docs.npmjs.com/misc/config
Settings values can be set in a file (lowest priority), environment variables, command line args (highest priority).
With currently functionality dub provides, all scenarios can be supported but having the possibility to set all settings values in a common way on different layers makes the usage especially for build systems quite nice and easy.
I hope this feature makes it into dub. I'm currently using D as a replacement for python at my worksite and have single file programs run via the interpreter directive:
#!/usr/bin/env dub
/+ dub.sdl:
...
+/
For matlab and python, the environment variables MATLABPATH and PYTHONPATH can be used to add to the package search path. If there were something similar for dub, say DUBPATH, it would be useful.
Ideally the the commands:
export DUBPATH=/base/packages/dir:/project/packages/dir
./single_file.d
would be roughly equivalent to:
dub add-path /base/packages/dir
dub add-path /project/packages/dir
./single_file.d
Though the first version wouldn't have effects outside the current terminal session, which is nice.