# -*- coding: utf-8 -*-
from distutils.core import setup

packages = \
['drf_viewset_profiler']

package_data = \
{'': ['*']}

install_requires = \
['Cython>=0.29,<0.30', 'line_profiler>=2.1,<3.0']

setup_kwargs = {
    'name': 'drf-viewset-profiler',
    'version': '0.2.0',
    'description': 'Lib to profile all methods from a viewset line by line',
    'long_description': '[![PyPI latest](https://img.shields.io/pypi/v/drf-viewset-profiler.svg)](https://pypi.python.org/pypi/drf-viewset-profiler)\n[![Build Status](https://travis-ci.org/fvlima/drf-viewset-profiler.svg?branch=master)](https://travis-ci.org/fvlima/drf-viewset-profiler)\n\n# drf-viewset-profiler\n\nDecorator to profile all methods from a viewset (and its serializer) line by line. For all methods that were called during a request, an output\nwill be generated showing the number of hits, time (in seconds), lines and the content of each line of a method that was executed\n\n## Installation\n\n`pip install drf-viewset-profiler`\n\nNote: due to a problem with `line_profiler` installation, it\'s necessary to follow these instructions [1] to install, or just do `pip install Cython` and force to install this lib again\n\n1 - https://github.com/rkern/line_profiler#installation\n\n## Usage\n\nDecorate the viewset that will be profiled\n\n```python\nfrom drf_viewset_profiler import line_profiler_viewset\n\n@line_profiler_viewset\nclass SomeViewSet(ViewSet):\n    queryset = Model.objects.all()\n```\n\nSet the middleware config in settings.py\n\n```python\nMIDDLEWARE = [\n    ...\n    "drf_viewset_profiler.middleware.LineProfilerViewSetMiddleware"\n]\n```\n\nMake requests in this viewset to profile and measure the time in seconds wasted\n\n## Configuration\n\n```python\nDRF_VIEWSET_PROFILER = {\n    "DEFAULT_OUTPUT_GENERATION_TYPE": "drf_viewset_profiler.output.FileOutput",\n    "DEFAULT_OUTPUT_LOCATION": "",\n    "ENABLE_SERIALIZER_PROFILER": True\n}\n```\n\n#### DEFAULT_OUTPUT_GENERATION_TYPE\n- drf_viewset_profiler.output.FileOutput: generates the output in a txt file with the name of the profiled viewset\n- drf_viewset_profiler.output.StdOutput: generates the output in the console (default)\n\nIt\'s possible to customize by extending the BaseOuput class\n\n#### DEFAULT_OUTPUT_LOCATION\n- the location to generate the output file with the name of the view that will profiled (default is empty)\n\n#### ENABLE_SERIALIZER_PROFILER\n- profile the methods from the serializer vinculated with the viewset (default is True)\n\n#### Output example\n\n```\nTotal time: 1.7e-05 s\nFile: /.pyenv/versions/3.7.4/envs/drf-viewset-profiler/lib/python3.7/site-packages/django/views/generic/base.py\nFunction: _allowed_methods at line 113\n\nLine #      Hits         Time  Per Hit   % Time  Line Contents\n==============================================================\n113                                               def _allowed_methods(self):\n114         1         17.0     17.0    100.0          return [m.upper() for m in self.http_method_names if hasattr(self, m)]\n\nTotal time: 0.000158 s\nFile: /.pyenv/versions/3.7.4/envs/drf-viewset-profiler/lib/python3.7/site-packages/rest_framework/generics.py\nFunction: get_serializer at line 103\n\nLine #      Hits         Time  Per Hit   % Time  Line Contents\n==============================================================\n103                                               def get_serializer(self, *args, **kwargs):\n104                                                   """\n105                                                   Return the serializer instance that should be used for validating and\n106                                                   deserializing input, and for serializing output.\n107                                                   """\n108         1         15.0     15.0      9.5          serializer_class = self.get_serializer_class()\n109         1         12.0     12.0      7.6          kwargs[\'context\'] = self.get_serializer_context()\n110         1        131.0    131.0     82.9          return serializer_class(*args, **kwargs)\n\nTotal time: 4e-06 s\nFile: /.pyenv/versions/3.7.4/envs/drf-viewset-profiler/lib/python3.7/site-packages/rest_framework/generics.py\nFunction: get_serializer_class at line 112\n\nLine #      Hits         Time  Per Hit   % Time  Line Contents\n==============================================================\n112                                               def get_serializer_class(self):\n113                                                   """\n114                                                   Return the class to use for the serializer.\n115                                                   Defaults to using `self.serializer_class`.\n116  \n117                                                   You may want to override this if you need to provide different\n118                                                   serializations depending on the incoming request.\n119  \n120                                                   (Eg. admins get full serialization, others get basic serialization)\n121                                                   """\n122         1          3.0      3.0     75.0          assert self.serializer_class is not None, (\n123                                                       "\'%s\' should either include a `serializer_class` attribute, "\n124                                                       "or override the `get_serializer_class()` method."\n125                                                       % self.__class__.__name__\n126                                                   )\n127  \n128         1          1.0      1.0     25.0          return self.serializer_class  \n\n...\n\nTotal time: 1.5491 s\nFile: /drf-viewset-profiler/test-drf-project/testapp/views.py\nFunction: create at line 52\n\nLine #      Hits         Time  Per Hit   % Time  Line Contents\n==============================================================\n    52                                               def create(self, request):\n    53         1          4.0      4.0      0.0          import time\n    54         1    1505235.0 1505235.0     97.2          time.sleep(1.5)\n    55         1      43866.0  43866.0      2.8          return super().create(request)  \n```  \n\n## Contribute\n\n- Clone this repository\n- Install poetry (pip install poetry)\n- run `poetry install`\n- run `pre-commit install`\n- Create your branch, make changes and open the pull request\n',
    'author': 'Frederico V Lima',
    'author_email': 'frederico.vieira@gmail.com',
    'maintainer': None,
    'maintainer_email': None,
    'url': 'https://github.com/fvlima/drf-viewset-profiler',
    'packages': packages,
    'package_data': package_data,
    'install_requires': install_requires,
    'python_requires': '>=3.6,<4.0',
}


setup(**setup_kwargs)
