django12factor icon indicating copy to clipboard operation
django12factor copied to clipboard

Custom loader

Open doismellburning opened this issue 10 years ago • 11 comments

Very much a WIP, but to allow type coercion, setting of defaults, etc.

doismellburning avatar Jan 15 '15 23:01 doismellburning

@avengerpenguin, @mekhami, @haraball, @jdelic, @carlio, @jvc26 - as users of/contributors to d12f, I'd be very interested in your thoughts and opinions of this feature proposal please!

doismellburning avatar Jan 17 '15 14:01 doismellburning

(Oh, also if you have advice on a) why that code block isn't rendering b) good tools for syntax/style checking of RST, that'd be amazing please)

doismellburning avatar Jan 17 '15 14:01 doismellburning

I think "For example:" needs 2 colons after to get the code bock to render. Not sure though as I don't use the ..code-block directive in my stuff.

carlio avatar Jan 17 '15 15:01 carlio

Heh cheers, I thought that, but it seems identical to earlier codeblocks in my rst...

doismellburning avatar Jan 17 '15 15:01 doismellburning

Possible alternative syntax:

custom_settings = EVL(
  ("LISTEN_PORT", 8080, int),
  ("OTHER_VAL", "default"),
)

Not sure if that is nicer or not, basically just removes lots of EVL, but could lead to parsing faff.

carlio avatar Jan 17 '15 15:01 carlio

Yeah I'm not sure how much I like the syntax, but I've not found a happier alternative - tuples make it a pain to have optional arguments; dicts might be better, but basically I've taken a leaf from Django's url...

doismellburning avatar Jan 17 '15 15:01 doismellburning

Fun observations: DATABASE_URL is a bit of a faff because it breaks the "setting name == env var name" assumption.

For customisable defaults you can do something like:

evl = EVL(
    "DATABASE_URL", 
    parser=dj_database_url.parse,
    default=dj_database_url.parse("your://url")
)
DATABASES['default'] = evl.load_value()

which is icky but I'm not sure how best to improve it

doismellburning avatar Feb 07 '15 15:02 doismellburning

Coverage Status

Coverage remained the same at 100.0% when pulling 3d69fc3ed87d3e2db30ff51ad51b4db16fb94a82 on feature/custom-loader into 75c1d75bb831f539530fee42e245c88f9844b71e on master.

coveralls avatar Apr 25 '15 22:04 coveralls

Coverage Status

Changes Unknown when pulling d8d7bbede3ac9c63fb0b4ec4200bc1fda8608ce1 on feature/custom-loader into * on master*.

coveralls avatar Aug 09 '16 21:08 coveralls

Is there anything I can do to move this PR, or django12factor in general, forward?

I have stopped using it for now and switched to a combination of os.environ.get(), dj-database-url and custom helper functions for parsing env vars, but it seems to be a waste of time if people keep reinventing this, even if it's quite simple.

rfleschenberg avatar Nov 18 '16 10:11 rfleschenberg

I realize this idea is somewhat radical, but do you think we could have a "just a bunch of functions" API?

DEBUG = d12f_bool('DEBUG', default=True)

SECRET_KEY = d12f_string('SECRET_KEY', require=True)  # raise an exception if not set.

DATABASES['default'] = d12f_database_url('DATABASE_URL', default='your://url')

LOGGING = d12f_logging()

WHATEVER = d12f_custom('MY_ENV_VAR', parser=lambda s: s.lower())

rfleschenberg avatar Nov 18 '16 14:11 rfleschenberg