dub icon indicating copy to clipboard operation
dub copied to clipboard

Set dub settings via environment variables

Open andre2007 opened this issue 6 years ago • 5 comments

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 registryUrls in JSON file, it should be named DUB_REGISTRY_URLS as environment variable?
  • There is also already an existing environment variable DUB_REGISTRY which has the same effect as DUB_REGISTRY_URLS

andre2007 avatar Jul 26 '19 12:07 andre2007

What's the use case for this ?

Geod24 avatar Dec 20 '19 09:12 Geod24

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.

andre2007 avatar Dec 20 '19 10:12 andre2007

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 ?

Geod24 avatar Dec 22 '19 20:12 Geod24

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.

andre2007 avatar Dec 23 '19 15:12 andre2007

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.

cpiker avatar May 05 '21 08:05 cpiker