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

Make Proutes *AMAZING*: Fix checks for @wsgiapp2, MultiView, and add request method #1488

Merged
merged 17 commits into from
Jan 22, 2015

Conversation

sontek
Copy link
Member

@sontek sontek commented Dec 15, 2014

Pyramid 1.5.2:

Name            Pattern                        View                     
----            -------                        ----                     
debugtoolbar    /_debug_toolbar/*subpath       <function decorator at 0x22656e0>
__static/       /static/*subpath               <function <pyramid.static.static_view object at 0x2257750> at 0x2265aa0>
__static2/      /static2/*subpath              <function <pyramid.static.static_view object at 0x2257810> at 0x2265cf8>
__pdt_images/   /pdt_images/*subpath           <function <pyramid.static.static_view object at 0x2257910> at 0x2265ed8>
a               /                              None                     
no_view_attached /                              None                     
route_and_view_attached /                              <function route_and_view_attached at 0x2271398>
only_post_on_route /route                         <function route_and_view_attached at 0x22715f0>
only_post_on_view /view                          <function route_and_view_attached at 0x22719b0>
method_intersection /intersection                  <function route_and_view_attached at 0x2271d70>
method_conflicts /conflicts                     <function route_and_view_attached at 0x22741b8>
multiview       /multiview                     <pyramid.config.views.MultiView object at 0x2275450>
class_based_view /classes                       <function ClassBasedView at 0x2274f50>
factory         /factory                       <unknown>                
not_post        /not_post                      <function route_and_view_attached at 0x22775f0>
not_post_only_get /not_post_only_get             <function route_and_view_attached at 0x22779b0>

Before this PR (i.e in master but not released):

Name                       Pattern                     View                                                              
----                       -------                     ----                                                              
debugtoolbar               /_debug_toolbar/*subpath    pyramid.router.decorator                                          
__static/                  /static/*subpath            pyramid.static.<pyramid.static.static_view object at 0x2f984d0>   
__static2/                 /static2/*subpath           pyramid.static.<pyramid.static.static_view object at 0x2f98590>   
__pdt_images/              /pdt_images/*subpath        pyramid.static.<pyramid.static.static_view object at 0x2f98690>   
a                          /                           None                                                              
no_view_attached           /                           None                                                              
route_and_view_attached    /                           dummy_starter.standard_views.route_and_view_attached              
only_post_on_route         /route                      dummy_starter.standard_views.route_and_view_attached              
only_post_on_view          /view                       dummy_starter.standard_views.route_and_view_attached              
method_intersection        /intersection               dummy_starter.standard_views.route_and_view_attached              
method_conflicts           /conflicts                  dummy_starter.standard_views.route_and_view_attached              
multiview                  /multiview                  dummy_starter.standard_views.hello_world                          
class_based_view           /classes                    dummy_starter.standard_views.ClassBasedView                       
factory                    /factory                    dummy_starter.standard_views.route_and_view_attached              
not_post                   /not_post                   dummy_starter.standard_views.route_and_view_attached              
not_post_only_get          /not_post_only_get          dummy_starter.standard_views.route_and_view_attached 

After:

Name                       Pattern                     View                                                    Method             
----                       -------                     ----                                                    ------             
debugtoolbar               /_debug_toolbar/*subpath    <wsgiapp>                                               *                  
__static/                  /static/*subpath            dummy_starter:static/                                   *                  
__static2/                 /static2/*subpath           /var/www/static/                                        *                  
__pdt_images/              /pdt_images/*subpath        pyramid_debugtoolbar:static/img/                        *                  
a                          /                           <unknown>                                               *                  
no_view_attached           /                           <unknown>                                               *                  
route_and_view_attached    /                           dummy_starter.standard_views.route_and_view_attached    *                  
only_post_on_route         /route                      dummy_starter.standard_views.route_and_view_attached    POST               
only_post_on_view          /view                       dummy_starter.standard_views.route_and_view_attached    POST               
method_intersection        /intersection               dummy_starter.standard_views.route_and_view_attached    POST               
method_conflicts           /conflicts                  dummy_starter.standard_views.route_and_view_attached    <route mismatch>   
multiview                  /multiview                  dummy_starter.standard_views.route_and_view_attached    GET,PATCH          
multiview                  /multiview                  dummy_starter.standard_views.hello_world                POST               
class_based_view           /classes                    dummy_starter.standard_views.ClassBasedView             POST               
factory                    /factory                    dummy_starter.standard_views.route_and_view_attached    *                  
not_post                   /not_post                   dummy_starter.standard_views.route_and_view_attached    !POST,*            
not_post_only_get          /not_post_only_get          dummy_starter.standard_views.route_and_view_attached    GET 

Outside of the more readable format there is now 2 command line arguments --glob and --format:

Glob lets you filter your routes:

$ proutes development.ini --glob='get_user*'
Name                      Pattern                                  View                                                 Method
----                      -------                                  ----                                                 ------
get_user_info             /profilesvc/v1/get_user_info             profilesvc.views.user_info.get_user_info             *
get_user_questions        /profilesvc/v1/get_user_questions        profilesvc.views.user_info.get_user_questions        *
get_user_qb_categories    /profilesvc/v1/get_user_qb_categories    profilesvc.views.user_info.get_user_qb_categories    *

Format allows you to choose which columns are visible:

$ proutes development.ini -f name,view,method --glob home
Name    View            Method              
----    ----            ------              
home    testapp.home    <route mismatch>

The format flag can also be placed in the ini with the [proutes] section:

[proutes]
format = name
         view
         method

This also fixes #1180

@sontek
Copy link
Member Author

sontek commented Dec 15, 2014

@mmerickel @mcdonc Please review. Just realized I probably broke py26 support but I'll fix that :)

@msabramo
Copy link
Contributor

I'm on my phone so didn't review thoroughly but maybe you want to mention in the PR title or description that this is for proutes?

@sontek sontek changed the title Fix checks for @wsgiapp2, MultiView, and add request method Make Proutes *AMAZING*: Fix checks for @wsgiapp2, MultiView, and add request method Dec 15, 2014
@msabramo
Copy link
Contributor

Now we're talking :)

@sontek
Copy link
Member Author

sontek commented Dec 23, 2014

@mmerickel Don't forget to review this amazing PR

@msabramo
Copy link
Contributor

This is cool; maybe my route and view names are too long, because one negative is that I had to shrink my font size way down in order to fit into the width of my laptop screen.

On the plus side, I might be able to get IT to get me a bigger monitor to run proutes.

@msabramo
Copy link
Contributor

If proutes allowed me to specify a glob pattern then I could have it only show certain routes and exclude the long ones.

@msabramo
Copy link
Contributor

Why is the change so big if all you did was add a method column? I think there must be more going on here than just that. Going to check my computer for spyware now.

E.g.:

    $ proutes development.ini --glob='user*'
    Name    Pattern                          View                                                                           Method
    ----    -------                          ----                                                                           ------
    user    /profilesvc/v1/user/{user_id}    pyramid.config.views.<pyramid.config.views.MultiView object at 0x106f72bd0>    *
    user    /profilesvc/v1/user/{user_id}    cornice.service.wrapper                                                        GET,HEAD
@msabramo
Copy link
Contributor

If proutes allowed me to specify a glob pattern then I could have it only show certain routes and exclude the long ones.

sontek#1

$ proutes development.ini --glob='user*'
Name    Pattern                          View                                                                           Method
----    -------                          ----                                                                           ------
user    /profilesvc/v1/user/{user_id}    pyramid.config.views.<pyramid.config.views.MultiView object at 0x106f72bd0>    *
user    /profilesvc/v1/user/{user_id}    cornice.service.wrapper                                                        GET,HEAD
$ proutes development.ini --glob='get_user*'
Name                      Pattern                                  View                                                 Method
----                      -------                                  ----                                                 ------
get_user_info             /profilesvc/v1/get_user_info             profilesvc.views.user_info.get_user_info             *
get_user_questions        /profilesvc/v1/get_user_questions        profilesvc.views.user_info.get_user_questions        *
get_user_qb_categories    /profilesvc/v1/get_user_qb_categories    profilesvc.views.user_info.get_user_qb_categories    *
$ proutes development.ini --glob='appstatus*'
Name                  Pattern                                View                                  Method
----                  -------                                ----                                  ------
appstatus.status      /status{optional_slash:/?}             smlib.appstatus.ServiceStatusViews    *
appstatus.packages    /status/packages{optional_slash:/?}    smlib.appstatus.ServiceStatusViews    *
appstatus.pid         /status/pid{optional_slash:/?}         smlib.appstatus.ServiceStatusViews    *

@sontek
Copy link
Member Author

sontek commented Dec 24, 2014

@msabramo The reason the diff is so big is because finding the request method is not completely straightforward, it can be defined at the route level, view level, be a list of methods, a single string, or not_ function. So tracking all this logic took a little bit of work.

While working on the request method I came up with some complex routing examples that exposed bugs in the original implementation as well so I fixed those as I went along.

@msabramo
Copy link
Contributor

Maybe if it's hard to reliably get the the method, that's an indication that something needs to be fixed in the API that proutes is using?

Fixing routing bugs might be another PR as well?

@mmerickel
Copy link
Member

Ok, finally took a look. I don't have much to say. This is awesome. Could the [proutes] format = section take the same format as the CLI instead of newline-separated? For example format = view, method? If not, why?

@sontek
Copy link
Member Author

sontek commented Jan 6, 2015

@mmerickel Was just trying to be consistent with things like pyramid.includes which use the newline format instead of csv, I could switch it though

…rt_more_features_in_routes

Conflicts:
	CHANGES.txt
@mmerickel
Copy link
Member

I guess I'd vote for supporting both then!

@msabramo
Copy link
Contributor

I don't know about supporting both of them. That probably will make things confusing and possibly harder to maintain.

I think I'd stick with the newline approach as that seems to be more typical of what is used in PasteDeploy ini files, including pyramid.includes, pipeline, kotti.configurators, etc.

@sontek: This has merge conflicts that need to resolved, even if @mmerickel agrees with sticking with the newline approach.

…rt_more_features_in_routes

Conflicts:
	CHANGES.txt
@sontek
Copy link
Member Author

sontek commented Jan 21, 2015

I fixed the conflict that YOU caused! ;).

I'm also not really wanting to support csv as all because its confusing to have multiple ways of doing something. I would think it would only make sense if we also support csv in things like includes and tweens

@mmerickel
Copy link
Member

I'm not sure why this feature is being compared to these other things that have only one way to specify them like pyramid.includes. There is no CLI equivalent. This is turning a CLI option into an INI format. In other tools (like pip for example) you specify your .pip/pip.conf then you define the setting equivalently to how it is input at the CLI prompt and then they use the same parsing code for both.

@msabramo
Copy link
Contributor

Well yeah but does pip use a csv command line argument or ini setting? I can't think of one.

I feel like it's more typical for CLI options to repeat the option than to have a single one with a CSV value.

But even if there is a ini file option and an equivalent CLI option, I feel like each one should use the one natural syntax for that medium and for ini files I think that's usually newlines (though I will admit that logger keys is a CSV but I think that's rarer). I don't think it's necessary for each to support the format of other

@mmerickel
Copy link
Member

This isn't separate features though like every other example (multiple options on the cli, pyramid.includes, kotti.configuration, pipeline, etc). This is a format string. I think logically they should be in a csv format rather than separated by newlines because that's describing the tabular format of the output on the console.

@msabramo
Copy link
Contributor

Pip is an interesting example. AFAICT, --extra-index-url <URL> doesn't accept CSV.

@msabramo
Copy link
Contributor

Interesting.

What if it were a format string?

E.g.:

format = {view} {name} {command}

@mmerickel
Copy link
Member

Yeah I can definitely see this evolving a bit, it's obviously a tiny format dsl. Hopefully we don't have to take it any further than the csv columns though. The CSV does indicate columns somewhat well.

@sontek
Copy link
Member Author

sontek commented Jan 21, 2015

Ok, I'm going to kill newline support and only do CSV. It'll be consistent between the ini and the cli

@mmerickel
Copy link
Member

I asked @bertjwregger to be a sane third party if you want him to as well since I realize I'm being like ultra pedantic here. Regardless, the PR is great and I'll merge it once a decision is made.

@sontek
Copy link
Member Author

sontek commented Jan 21, 2015

Yeah, I prefer more input! I don't really care that much either way, I'll use whatever gets merged :)

cc @mcdonc @tseaver @pauleveritt @blaflamme @cguardia :D

@digitalresistor
Copy link
Member

@mmerickel Can't even get my name right with the auto-complete ;-)

Will take a look at this tomorrow. I like the idea, and I like the output, will do a quick code review as well.

@mmerickel
Copy link
Member

Crap I was so close!

@sontek
Copy link
Member Author

sontek commented Jan 21, 2015

@mmerickel @bertjwregeer I noticed that it didn't link so I tried to guess what the actually name was and I couldn't remember either :D

@sontek
Copy link
Member Author

sontek commented Jan 22, 2015

@mmerickel There, it now supports every way someone might think of using it :)

mmerickel added a commit that referenced this pull request Jan 22, 2015
Make Proutes *AMAZING*: Fix checks for @wsgiapp2, MultiView, and add request method
@mmerickel mmerickel merged commit f5a78b1 into Pylons:master Jan 22, 2015
@mmerickel
Copy link
Member

Coolest thing ever. Merged.

@msabramo
Copy link
Contributor

Woo hoo!

@sontek: I want that pyramid command now.

$ pyramid route list

@msabramo
Copy link
Contributor

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

Successfully merging this pull request may close these issues.

proutes does not show static routes
5 participants