environment variables without CONFIGGLUE_ string

Asked by John

Hi,

I'm not sure if this project is still being maintained, but it seems to be the
only Python library available which facilitates passing options to a program
using a combination of config files, environment variables and command line
options in structured and consistent way. For that, I congratulate the authors
on a job well done.

But I have a question / feature request ?

I notice that it is possible to override options using environment variables
using the uppercase of the long option name, but only if the environment
variable name is preceded by the string "CONFIGGLUE_".

For example, if my program takes an option called "--password" the user can
specify this by setting the environment variable "CONFIGGLUE_PASSWORD".

Would it be possible to allow the use of variables without the
prefix "CONFIGGLUE_" or at least make the feature configurable? The behaviour
is hard-coded in configglue/glue,py as follows:

    env_value = os.environ.get("CONFIGGLUE_{0}".format(
      long_name(option).upper()))

The user should need to know nothing of the specific libraries being used by an
application, so it is un-intuitive for them to use the string "CONFIGGLUE_".
I would like the user to be able specify the environment variable name
exactly as shown in the help message (i.e. the "meta" variable name).

Here is an example:

  #!/usr/bin/env python

  from configglue import (schema, app)

  class MySchema(schema.Schema):
    password = schema.StringOption()

  app = app.App(MySchema)

  import pprint
  pprint.pprint(app.config.glue.schema_parser.values('__main__'))

With the above code the help looks like this...

  $ ./app.py -h
  Usage: app.py [options]

  Options:
    -h, --help show this help message and exit
    --validate validate configuration
    --password=PASSWORD
  $

Yet, to specify the "password" option using an environment variable,
the user has to use the variable "CONFIGGLUE_PASSWORD". For example:

  $ CONFIGGLUE_PASSWORD=p ./app.py
  {'password': 'p'}
  $
  $ PASSWORD=p ./app.py
  {'password': ''} # i.e. PASSWORD not used
  $

As a local fix, simply hacking out the string "CONFIGGLUE_" from glue.py
seems to do the trick, but I'm seeking a long term solution.

  $ PASSWORD=p ./app.py
  {'password': 'p'} # success !
  $

Question information

Language:
English Edit question
Status:
Expired
For:
configglue Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Launchpad Janitor (janitor) said :
#1

This question was expired because it remained in the 'Open' state without activity for the last 15 days.