Skip to content

Commit

Permalink
Refactor QA setup
Browse files Browse the repository at this point in the history
  • Loading branch information
aleksihakli committed Jan 22, 2020
1 parent d066597 commit 3d28203
Show file tree
Hide file tree
Showing 17 changed files with 160 additions and 113 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[run]
branch = True
source = silk
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var/
*.egg-info/
.installed.cfg
*.egg
.eggs

# Installer logs
pip-log.txt
Expand Down
84 changes: 42 additions & 42 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
language: python
dist: xenial
sudo: false
language: python
cache: pip
python:
- '3.5'
- '3.6'
- '3.7'
- '3.8'
env:
- DJANGO="Django>=2.2,<2.3.0" DB=postgresql DB_NAME=travis_ci_test
- DJANGO="Django>=3.0" DB=postgresql DB_NAME=travis_ci_test
- DJANGO="Django>=2.2,<2.3.0" DB=sqlite3 DB_NAME=db.sqlite3
- DJANGO="Django>=3.0" DB=sqlite3 DB_NAME=db.sqlite3
- DJANGO="Django>=2.2,<2.3.0" DB=mysql DB_NAME=mysql_db
- DJANGO="Django>=3.0" DB=mysql DB_NAME=mysql_db
matrix:
exclude:
- python: '3.5'
env: DJANGO="Django>=3.0" DB=postgresql DB_NAME=travis_ci_test
- python: '3.5'
env: DJANGO="Django>=3.0" DB=sqlite3 DB_NAME=db.sqlite3
- python: '3.5'
env: DJANGO="Django>=3.0" DB=mysql DB_NAME=mysql_db
fast_finish: true
- 3.5
- 3.6
- 3.7
- 3.8
services:
- mysql
- postgresql
install:
- travis_retry pip install -q $DJANGO
- travis_retry pip install -r requirements.txt
- travis_retry pip install -r project/test-requirements.txt
- if [[ "$DB" = "postgresql" ]]; then pip install psycopg2; fi
- if [[ "$DB" = "postgresql" ]]; then psql -c 'create database travis_ci_test;' -U
postgres; fi
- if [[ "$DB" = "mysql" ]]; then pip install mysqlclient; fi
- if [[ "$DB" = "mysql" ]]; then mysql -e 'create database mysql_db;'; fi
script:
- "./project/run_tests.sh"
deploy:
provider: pypi
user: jazzband
server: https://jazzband.co/projects/django-silk/upload
password:
secure: VqpIq4gsetWZFDG7XV72Tg+7zx0zRLcLXlLKM6XVN5LqARx4MVgNWD/lJvf5EWqvXPqcx6DAQN5c5nd35swWjET2XnAR0HO5Bc8F1U/gaHOlvdZBuOSb0PIzl1uPl4JHtwiRJckZELB/O8M8RgJzulZd+28TL37dsH+0baFZ05c=
distributions: sdist bdist_wheel
on:
tags: true
repo: jazzband/django-silk
- pip install tox-travis codecov
- if [[ "$DB" = "mysql" ]]; then mysql -e "create database mysql_db;"; fi
- if [[ "$DB" = "postgresql" ]]; then psql -c "create database travis_ci_test;" -U postgres; fi
script: tox
after_success: codecov
env:
- DJANGO=2.2 DATABASE=sqlite3
- DJANGO=2.2 DATABASE=mysql
- DJANGO=2.2 DATABASE=postgresql
- DJANGO=3.0 DATABASE=sqlite3
- DJANGO=3.0 DATABASE=mysql
- DJANGO=3.0 DATABASE=postgresql
jobs:
exclude:
- python: 3.5
env: DJANGO=3.0 DATABASE=sqlite3
- python: 3.5
env: DJANGO=3.0 DATABASE=mysql
- python: 3.5
env: DJANGO=3.0 DATABASE=postgresql
include:
- stage: deploy
env:
python: 3.6
script: skip
deploy:
provider: pypi
user: jazzband
server: https://jazzband.co/projects/django-silk/upload
distributions: sdist bdist_wheel
password:
secure: VqpIq4gsetWZFDG7XV72Tg+7zx0zRLcLXlLKM6XVN5LqARx4MVgNWD/lJvf5EWqvXPqcx6DAQN5c5nd35swWjET2XnAR0HO5Bc8F1U/gaHOlvdZBuOSb0PIzl1uPl4JHtwiRJckZELB/O8M8RgJzulZd+28TL37dsH+0baFZ05c=
skip_existing: true
on:
tags: true
repo: jazzband/django-silk
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FROM python:3.6-alpine
MAINTAINER Jazz Band
MAINTAINER Jazzband

# Some system dependencies
RUN apk update -qq && apk add build-base jpeg-dev zlib-dev
Expand All @@ -9,8 +9,8 @@ RUN mkdir -p $APP_HOME

WORKDIR $APP_HOME

COPY project/test-requirements.txt ./
RUN pip3 install -r test-requirements.txt
COPY project/requirements.txt ./
RUN pip3 install -r requirements.txt

COPY setup.py setup.cfg README.md ./
COPY silk silk
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Silk is a live profiling and inspection tool for the Django framework. Silk inte

Silk has been tested with:

* Django: 2.2, 3.0
* Django: 1.11, 2.2, 3.0
* Python: 3.5, 3.6, 3.7, 3.8

## Installation
Expand Down Expand Up @@ -503,7 +503,7 @@ In order to setup local development you should first install all the dependencie
root of the `project` directory:

```bash
pip install -r test-requirements.txt
pip install -r requirements.txt
```

You will also need to install `silk`'s dependencies. From the root of the git repository:
Expand Down
12 changes: 4 additions & 8 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import pkg_resources

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
#sys.path.insert(0, os.path.abspath('.'))

# -- General configuration ------------------------------------------------

# If your documentation needs a minimal Sphinx version, state it here.
#needs_sphinx = '1.0'

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
Expand All @@ -37,7 +34,6 @@
source_suffix = '.rst'

# The encoding of source files.
#source_encoding = 'utf-8-sig'

# The master toctree document.
master_doc = 'index'
Expand All @@ -50,10 +46,10 @@
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '0.3'
# The full version, including alpha/beta/rc tags.
release = '0.3'
release = pkg_resources.get_distribution("django-silk").version
# The short X.Y version.
version = '.'.join(release.split('.')[:2])

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
16 changes: 8 additions & 8 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Configuration
======
=============

Authentication/Authorisation
----
Authentication and Authorisation
--------------------------------

By default anybody can access the Silk user interface by heading to `/silk/`. To enable your Django
auth backend place the following in `settings.py`:
Expand All @@ -25,8 +25,8 @@ You can customise this using the following in ``settings.py``:
SILKY_PERMISSIONS = my_custom_perms
Request/Response bodies
----
Request and Response bodies
---------------------------

By default, Silk will save down the request and response bodies for each request for future viewing
no matter how large. If Silk is used in production under heavy volume with large bodies this can have
Expand All @@ -39,7 +39,7 @@ a huge impact on space/time performance. This behaviour can be configured with f
Meta-Profiling
-----
--------------

Sometimes its useful to be able to see what effect Silk is having on the request/response time. To do this add
the following to your `settings.py`:
Expand All @@ -54,8 +54,8 @@ Silk will then record how long it takes to save everything down to the database

Note that in the above screenshot, this means that the request took 29ms (22ms from Django and 7ms from Silk)

Limiting request/response data
----
Limiting request and response data
----------------------------------

To make sure silky garbage collects old request/response data, a config var can be set to limit the number of request/response rows it stores.

Expand Down
2 changes: 1 addition & 1 deletion docs/quickstart.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Run ``syncdb`` to create Silk's database tables:
And voila! Silk will begin intercepting requests and queries which you can inspect by visiting ``/silk/``

Other Installation Options
-------
--------------------------

You can download a release from `github <https://github.com/jazzband/django-silk/releases>`_ and then install using pip:

Expand Down
6 changes: 3 additions & 3 deletions docs/troubleshooting.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
Troubleshooting
==========
===============

The below details common problems when using Silk, most of which have been derived from the solutions to github issues.

Unicode
------
-------

Silk saves down the request and response bodies of each HTTP request by default. These bodies are often UTF encoded and hence it is important that Silk's database tables are also UTF encoded. Django has no facility for enforcing this and instead assumes that the configured database defaults to UTF.

Expand All @@ -19,7 +19,7 @@ Then it's likely your database is not configured correctly for UTF encoding.
See this `github issue <https://github.com/jazzband/django-silk/issues/21>`_ for more details and workarounds.

Middleware
------
----------

The middleware is placement sensitive. If the middleware before ``silk.middleware.SilkyMiddleware`` returns from ``process_request`` then ``SilkyMiddleware`` will never get the chance to execute. Therefore you must ensure that any middleware placed before never returns anything from ``process_request``. See the `django docs <https://docs.djangoproject.com/en/dev/topics/http/middleware/#process-request>`_ for more information on this.

Expand Down
9 changes: 6 additions & 3 deletions project/test-requirements.txt → project/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Pygments>=2.0,<2.1
pygments>=2.0,<2.1
simplejson==3.13.2
python-dateutil>=2.4,<2.5
requests==2.21.0
sqlparse==0.2.4
Jinja2==2.10
jinja2==2.10
autopep8==1.4.3
pytz>2014.2
mock==2.0.0
Pillow==5.4.1
pillow==5.4.1
factory-boy==2.9.2
freezegun==0.3.12
networkx==1.11
pydotplus==2.0.2
contextlib2==0.5.5
coverage==5.0.3
pytest-django==3.8.0
pytest-cov==2.8.1
6 changes: 0 additions & 6 deletions project/run_tests.sh

This file was deleted.

46 changes: 30 additions & 16 deletions project/tests/test_profile_parser.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,45 @@
# future
from __future__ import print_function
# std
import cProfile
from io import StringIO
# 3rd party
import io
import re

import contextlib2 as contextlib

from django.test import TestCase
# silk

from silk.utils.profile_parser import parse_profile


class ProfileParserTestCase(TestCase):

def test_profile_parser(self):
"""
Verify that the function parse_profile produces the expected output.
"""
with contextlib.closing(StringIO()) as stream:
with contextlib.closing(io.StringIO()) as stream:
with contextlib.redirect_stdout(stream):
cProfile.run('print()')
stream.seek(0)
actual = list(parse_profile(stream))
expected = [
['ncalls', 'tottime', 'percall', 'cumtime', 'percall', 'filename:lineno(function)'],
['1', '0.000', '0.000', '0.000', '0.000', '<string>:1(<module>)'],
['1', '0.000', '0.000', '0.000', '0.000', '{built-in method builtins.exec}'],
['1', '0.000', '0.000', '0.000', '0.000', '{built-in method builtins.print}'],
['1', '0.000', '0.000', '0.000', '0.000', "{method 'disable' of '_lsprof.Profiler' objects}"]
]
self.assertListEqual(actual, expected)

# Expected format for the profiling output on cPython implementations (PyPy differs)
# actual = [
# ["ncalls", "tottime", "percall", "cumtime", "percall", "filename:lineno(function)"],
# ["1", "0.000", "0.000", "0.000", "0.000", "<string>:1(<module>)"],
# ["1", "0.000", "0.000", "0.000", "0.000", "{built-in method builtins.exec}"],
# ["1", "0.000", "0.000", "0.000", "0.000", "{built-in method builtins.print}"],
# ["1", "0.000", "0.000", "0.000", "0.000", "{method 'disable' of '_lsprof.Profiler' objects}"],
# ]

exc_header = ["ncalls", "tottime", "percall", "cumtime", "percall", "filename:lineno(function)"]
self.assertEqual(actual[0], exc_header)

exc_number = re.compile(r"\d(.\d+)?")
exc_module = re.compile(r"({method.*})|({built-in.*})|(<.+>:\d+\(<.+>\))")

exc_row = [exc_number, exc_number, exc_number, exc_number, exc_number, exc_module]

for row in actual[1:]:
for text, expected_regex in zip(row, exc_row):
self.assertRegex(
text, expected_regex,
msg="Expected something like {} but found {}"
)
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
addopts = --cov silk --cov-config .coveragerc --cov-append --cov-report term
python_files = test.py tests.py test_*.py tests_*.py *_tests.py *_test.py
DJANGO_SETTINGS_MODULE = project.settings
13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.

11 changes: 4 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# -*- coding: utf-8 -*-
"""Define the Django Silk setup."""
import os
from setuptools import setup

# allow setup.py to be run from any path
os.chdir(os.path.normpath(os.path.join(os.path.abspath(__file__), os.pardir)))

README = open('README.md', 'rb').read().decode("UTF-8")

setup(
name='django-silk',
version='4.0.0',
use_scm_version=True,
packages=['silk'],
include_package_data=True,
license='MIT License',
description='Silky smooth profiling for the Django Framework',
long_description=README,
long_description=open('README.md').read(),
long_description_content_type='text/markdown',
url='https://github.com/jazzband/django-silk',
author='Michael Ford',
Expand Down Expand Up @@ -47,5 +43,6 @@
'pytz',
'gprof2dot>=2017.09.19',
],
python_requires='>=3.5'
python_requires='>=3.5',
setup_requires=['setuptools_scm'],
)
Loading

0 comments on commit 3d28203

Please sign in to comment.