Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding script info to global_config during application setup #3734

Closed
adroullier opened this issue Oct 18, 2023 · 2 comments
Closed

Adding script info to global_config during application setup #3734

adroullier opened this issue Oct 18, 2023 · 2 comments

Comments

@adroullier
Copy link
Contributor

Pyramid startup scripts in python/bin directory (pserve, prequest, pshell) do not pass any special info to the wsgi app or "main()" function. As far as I know there is no way to find out how the wsgi application startup is triggered.

In some cases it makes sense to call different code whether the application is created as server (bin/pserve) or for a single request (bin/prequest). For example setting up internal caching modules, maintenance or other background functions.

Right now you have use extra environment variables, multiple wsgi configurations or other workarounds which are not really elegant solutions.

My proposal is to extend the scripts with additional context information which simply refer to the scripts name. The additional info is passed to the main function as part of global_config["__script__"] dict during wsgi setup.

For example, from a developers perspective it would look like:

from pyramid.config import Configurator

def main(global_config, **settings):
    config = Configurator()
    config.include('myapp.myconfig.includeme')
    
    # global_config.get("__script__") = either "prequest", "pserve", "pshell" or None 
    # signals how the application startup was triggered
    # if required handle application setup accordingly

I can provide a pull request if there a no objections. And the code change should have no impact on existings applications.

@mmerickel
Copy link
Member

I don't currently have a good vision on how this would be implemented - if it can be done in pyramid's shell scripts directly, and/or if plaster/plaster-pastedeploy would need to assist in some way but I'm happy to consider a PR to add this idea of marshaling a value through into the global_config.

@mmerickel
Copy link
Member

Fixed via #3735.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants