prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Tox (including Travis) not testing cythonized variants
  As described in ``README.rst``, Falcon can be cythonized for ~20% performance gain (or actually even more). Installing Falcon from *sdist* into an environment with Cython does the trick:
  
  ```python
  >>> import falcon
  >>> falcon.api  # As we can see, falcon.api is coming from the dynamically-linked (cythonized) library api.so
  <module 'falcon.api' from '/home/vytas/.virtualenvs/fresh/local/lib/python2.7/site-packages/falcon/api.so'>
  ```
  
  However, this does not hold under Tox ``py27_cython`` and ``py36_cython`` environments, including runs in Travis, as the properly cythonized Falcon is shadowed by the local source directory. This could potentially be worked around by changing dir in Tox, but apparently pytest is even more stubborn as it is correctly determining the root dir of tests, and changing to it.
  
  See also discussions here:
  * https://github.com/tox-dev/tox/issues/54
  * https://github.com/tox-dev/tox/issues/514
  
  The last comment on the latter also explains the possible patterns to work this around: https://github.com/tox-dev/tox/issues/514#issuecomment-327779367 (links to the useful https://docs.pytest.org/en/latest/goodpractices.html#choosing-a-test-layout-import-rules ).
  
  
  </issue>
  <code>
  [start of falcon/cmd/print_routes.py]
  1 #!/usr/bin/env python
  2 # Copyright 2013 by Rackspace Hosting, Inc.
  3 #
  4 # Licensed under the Apache License, Version 2.0 (the "License");
  5 # you may not use this file except in compliance with the License.
  6 # You may obtain a copy of the License at
  7 #
  8 #    http://www.apache.org/licenses/LICENSE-2.0
  9 #
  10 # Unless required by applicable law or agreed to in writing, software
  11 # distributed under the License is distributed on an "AS IS" BASIS,
  12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 # See the License for the specific language governing permissions and
  14 # limitations under the License.
  15 """
  16 Script that prints out the routes of an API instance.
  17 """
  18 
  19 from __future__ import print_function
  20 
  21 from functools import partial
  22 import inspect
  23 
  24 import falcon
  25 
  26 
  27 def print_routes(api, verbose=False):  # pragma: no cover
  28     """
  29     Initial call.
  30 
  31     :param api: The falcon.API or callable that returns an instance to look at.
  32     :type api: falcon.API or callable
  33     :param verbose: If the output should be verbose.
  34     :type verbose: bool
  35     """
  36     traverse(api._router._roots, verbose=verbose)
  37 
  38 
  39 def traverse(roots, parent='', verbose=False):
  40     """
  41     Recursive call which also handles printing output.
  42 
  43     :param api: The falcon.API or callable that returns an instance to look at.
  44     :type api: falcon.API or callable
  45     :param parent: The parent uri path to the current iteration.
  46     :type parent: str
  47     :param verbose: If the output should be verbose.
  48     :type verbose: bool
  49     """
  50     for root in roots:
  51         if root.method_map:
  52             print('->', parent + '/' + root.raw_segment)
  53             if verbose:
  54                 for method, func in root.method_map.items():
  55                     if func.__name__ != 'method_not_allowed':
  56                         if isinstance(func, partial):
  57                             real_func = func.func
  58                         else:
  59                             real_func = func
  60 
  61                         source_file = inspect.getsourcefile(real_func)
  62 
  63                         print('-->{0} {1}:{2}'.format(
  64                             method,
  65                             source_file,
  66                             source_file[1]
  67                         ))
  68 
  69         if root.children:
  70             traverse(root.children, parent + '/' + root.raw_segment, verbose)
  71 
  72 
  73 def main():
  74     """
  75     Main entrypoint.
  76     """
  77     import argparse
  78 
  79     parser = argparse.ArgumentParser(
  80         description='Example: print-api-routes myprogram:app')
  81     parser.add_argument(
  82         '-v', '--verbose', action='store_true',
  83         help='Prints out information for each method.')
  84     parser.add_argument(
  85         'api_module',
  86         help='The module and api to inspect. Example: myapp.somemodule:api',
  87     )
  88     args = parser.parse_args()
  89 
  90     try:
  91         module, instance = args.api_module.split(':', 1)
  92     except ValueError:
  93         parser.error(
  94             'The api_module must include a colon between '
  95             'the module and instnace')
  96     api = getattr(__import__(module, fromlist=[True]), instance)
  97     if not isinstance(api, falcon.API):
  98         if callable(api):
  99             api = api()
  100             if not isinstance(api, falcon.API):
  101                 parser.error(
  102                     '{0} did not return a falcon.API instance'.format(
  103                         args.api_module))
  104         else:
  105             parser.error(
  106                 'The instance must be of falcon.API or be '
  107                 'a callable without args that returns falcon.API')
  108     print_routes(api, verbose=args.verbose)
  109 
  110 
  111 if __name__ == '__main__':
  112     main()
  113
  [end of falcon/cmd/print_routes.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/falcon/cmd/print_routes.py b/falcon/cmd/print_routes.py
  --- a/falcon/cmd/print_routes.py
  +++ b/falcon/cmd/print_routes.py
  @@ -58,13 +58,19 @@
                           else:
                               real_func = func
   
  -                        source_file = inspect.getsourcefile(real_func)
  -
  -                        print('-->{0} {1}:{2}'.format(
  -                            method,
  -                            source_file,
  -                            source_file[1]
  -                        ))
  +                        try:
  +                            source_file = inspect.getsourcefile(real_func)
  +                            source_lines = inspect.getsourcelines(real_func)
  +                            source_info = '{}:{}'.format(source_file,
  +                                                         source_lines[1])
  +                        except TypeError:
  +                            # NOTE(vytas): If Falcon is cythonized, all default
  +                            # responders coming from cythonized modules will
  +                            # appear as built-in functions, and raise a
  +                            # TypeError when trying to locate the source file.
  +                            source_info = '[unknown file]'
  +
  +                        print('-->' + method, source_info)
   
           if root.children:
               traverse(root.children, parent + '/' + root.raw_segment, verbose)
  @@ -92,7 +98,7 @@
       except ValueError:
           parser.error(
               'The api_module must include a colon between '
  -            'the module and instnace')
  +            'the module and instance')
       api = getattr(__import__(module, fromlist=[True]), instance)
       if not isinstance(api, falcon.API):
           if callable(api):
  
verification_info: {"golden_diff": "diff --git a/falcon/cmd/print_routes.py b/falcon/cmd/print_routes.py\n--- a/falcon/cmd/print_routes.py\n+++ b/falcon/cmd/print_routes.py\n@@ -58,13 +58,19 @@\n                         else:\n                             real_func = func\n \n-                        source_file = inspect.getsourcefile(real_func)\n-\n-                        print('-->{0} {1}:{2}'.format(\n-                            method,\n-                            source_file,\n-                            source_file[1]\n-                        ))\n+                        try:\n+                            source_file = inspect.getsourcefile(real_func)\n+                            source_lines = inspect.getsourcelines(real_func)\n+                            source_info = '{}:{}'.format(source_file,\n+                                                         source_lines[1])\n+                        except TypeError:\n+                            # NOTE(vytas): If Falcon is cythonized, all default\n+                            # responders coming from cythonized modules will\n+                            # appear as built-in functions, and raise a\n+                            # TypeError when trying to locate the source file.\n+                            source_info = '[unknown file]'\n+\n+                        print('-->' + method, source_info)\n \n         if root.children:\n             traverse(root.children, parent + '/' + root.raw_segment, verbose)\n@@ -92,7 +98,7 @@\n     except ValueError:\n         parser.error(\n             'The api_module must include a colon between '\n-            'the module and instnace')\n+            'the module and instance')\n     api = getattr(__import__(module, fromlist=[True]), instance)\n     if not isinstance(api, falcon.API):\n         if callable(api):\n", "issue": "Tox (including Travis) not testing cythonized variants\nAs described in ``README.rst``, Falcon can be cythonized for ~20% performance gain (or actually even more). Installing Falcon from *sdist* into an environment with Cython does the trick:\r\n\r\n```python\r\n>>> import falcon\r\n>>> falcon.api  # As we can see, falcon.api is coming from the dynamically-linked (cythonized) library api.so\r\n<module 'falcon.api' from '/home/vytas/.virtualenvs/fresh/local/lib/python2.7/site-packages/falcon/api.so'>\r\n```\r\n\r\nHowever, this does not hold under Tox ``py27_cython`` and ``py36_cython`` environments, including runs in Travis, as the properly cythonized Falcon is shadowed by the local source directory. This could potentially be worked around by changing dir in Tox, but apparently pytest is even more stubborn as it is correctly determining the root dir of tests, and changing to it.\r\n\r\nSee also discussions here:\r\n* https://github.com/tox-dev/tox/issues/54\r\n* https://github.com/tox-dev/tox/issues/514\r\n\r\nThe last comment on the latter also explains the possible patterns to work this around: https://github.com/tox-dev/tox/issues/514#issuecomment-327779367 (links to the useful https://docs.pytest.org/en/latest/goodpractices.html#choosing-a-test-layout-import-rules ).\r\n\n", "before_files": [{"content": "#!/usr/bin/env python\n# Copyright 2013 by Rackspace Hosting, Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\"\"\"\nScript that prints out the routes of an API instance.\n\"\"\"\n\nfrom __future__ import print_function\n\nfrom functools import partial\nimport inspect\n\nimport falcon\n\n\ndef print_routes(api, verbose=False):  # pragma: no cover\n    \"\"\"\n    Initial call.\n\n    :param api: The falcon.API or callable that returns an instance to look at.\n    :type api: falcon.API or callable\n    :param verbose: If the output should be verbose.\n    :type verbose: bool\n    \"\"\"\n    traverse(api._router._roots, verbose=verbose)\n\n\ndef traverse(roots, parent='', verbose=False):\n    \"\"\"\n    Recursive call which also handles printing output.\n\n    :param api: The falcon.API or callable that returns an instance to look at.\n    :type api: falcon.API or callable\n    :param parent: The parent uri path to the current iteration.\n    :type parent: str\n    :param verbose: If the output should be verbose.\n    :type verbose: bool\n    \"\"\"\n    for root in roots:\n        if root.method_map:\n            print('->', parent + '/' + root.raw_segment)\n            if verbose:\n                for method, func in root.method_map.items():\n                    if func.__name__ != 'method_not_allowed':\n                        if isinstance(func, partial):\n                            real_func = func.func\n                        else:\n                            real_func = func\n\n                        source_file = inspect.getsourcefile(real_func)\n\n                        print('-->{0} {1}:{2}'.format(\n                            method,\n                            source_file,\n                            source_file[1]\n                        ))\n\n        if root.children:\n            traverse(root.children, parent + '/' + root.raw_segment, verbose)\n\n\ndef main():\n    \"\"\"\n    Main entrypoint.\n    \"\"\"\n    import argparse\n\n    parser = argparse.ArgumentParser(\n        description='Example: print-api-routes myprogram:app')\n    parser.add_argument(\n        '-v', '--verbose', action='store_true',\n        help='Prints out information for each method.')\n    parser.add_argument(\n        'api_module',\n        help='The module and api to inspect. Example: myapp.somemodule:api',\n    )\n    args = parser.parse_args()\n\n    try:\n        module, instance = args.api_module.split(':', 1)\n    except ValueError:\n        parser.error(\n            'The api_module must include a colon between '\n            'the module and instnace')\n    api = getattr(__import__(module, fromlist=[True]), instance)\n    if not isinstance(api, falcon.API):\n        if callable(api):\n            api = api()\n            if not isinstance(api, falcon.API):\n                parser.error(\n                    '{0} did not return a falcon.API instance'.format(\n                        args.api_module))\n        else:\n            parser.error(\n                'The instance must be of falcon.API or be '\n                'a callable without args that returns falcon.API')\n    print_routes(api, verbose=args.verbose)\n\n\nif __name__ == '__main__':\n    main()\n", "path": "falcon/cmd/print_routes.py"}]}