anyone have a suggestion to do per-environment package 'constants' ?

28 views
Skip to first unread message

Jonathan Vanasco

unread,
Mar 26, 2012, 12:12:30 AM3/26/12
to pylons-discuss
99% of my per-environment setups are handled in the .ini file, and
available via the registry stash

I have a few 'variables' that I need defined within a package scope,
as I'm not going to have a request or event object handy. I put
variables in quotes, because they're more like constants in Perl --
they're only defined on init and never changed. ( basically they
control things like which amazon s3 buckets items are stored in ).

does anyone have a clue how i could handle this ?

Wyatt Baldwin

unread,
Mar 26, 2012, 1:48:27 AM3/26/12
to pylons-...@googlegroups.com

- You can access the registry via config.registry
- You could use get_current_registry
- You could make the registry global (http://pyramid.readthedocs.org/en/latest/narr/zca.html)
- get_appsettings might do the trick
 

Jonathan Vanasco

unread,
Mar 26, 2012, 1:48:10 PM3/26/12
to pylons-discuss
those work at runtime , but I'm trying to define something on the app
init

e.g.

lib/constants.py
========================
if PRODUCTION_MACHINE :
VAR_1 = '123'
VAR_2 = '123'
elif DEV_MACHINE :
VAR_1 = '456'
VAR_2 = '456'
========================

this is, of course, an illustrative example. this sort of stuff was
straightforward in Pylons.

Michael Merickel

unread,
Mar 26, 2012, 2:12:02 PM3/26/12
to pylons-...@googlegroups.com
To be clear, it was straightforward in pylons if you managed to avoid importing any of that code until after the app was initialized. We have a cookbook recipe already for emulating a django-style settings.py which you can freely modify for your needs if you wish. There are obvious reasons for avoiding this type of code in Pyramid's core, so at this point you're just asking for ways to deal with this in Python.


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To post to this group, send email to pylons-...@googlegroups.com.
To unsubscribe from this group, send email to pylons-discus...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.


Jonathan Vanasco

unread,
Mar 27, 2012, 10:08:58 AM3/27/12
to pylons-discuss
thanks!

the line "django-style settings.py" got me thinking. all i needed was
to create a settings.py module , and I can set an environment toggle
in there to look up in other packages.

On Mar 26, 2:12 pm, Michael Merickel <mmeri...@gmail.com> wrote:
> To be clear, it was straightforward in pylons if you managed to avoid
> importing any of that code until after the app was initialized. We have a
> cookbook recipe already for emulating a django-style settings.py which you
> can freely modify for your needs if you wish. There are obvious reasons for
> avoiding this type of code in Pyramid's core, so at this point you're just
> asking for ways to deal with this in Python.
>
Reply all
Reply to author
Forward
0 new messages