Hello, I am Stéphane Python Freelancer Open Source = My Passion/Job PythonFOSDEM CPython contributor #fellow member of Python Software Foundation Community Service Award EuroPython organizer former core dev of Odoo (Open Source ERP) blah blah Python blah 2 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) 6 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite 7 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) 8 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... 9 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... duplicated/dead code 10 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... duplicated/dead code no async for jobs 11 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... duplicated/dead code no async for jobs no Continuous Integration / Continuous Delivery 12 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... duplicated/dead code no async for jobs no Continuous Integration / Continuous Delivery no API for external tools need to export data (mobile app, ticket search app, etc...) 13 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... duplicated/dead code no async for jobs no Continuous Integration / Continuous Delivery no API for external tools need to export data (mobile app, ticket search app, etc...) no syslog, just send error with exception to the mailing list. 14 / 69
Unconfessed project Python 2.7 (support 2020) Django 1.8 (support april 2018) few dependencies are deprecated or no maintainers (incompatible with django 1.11) SQLite no tests (+- 30k lines of code) no documentation, some comments are in Italian, French, ... duplicated/dead code no async for jobs no Continuous Integration / Continuous Delivery no API for external tools need to export data (mobile app, ticket search app, etc...) no syslog, just send error with exception to the mailing list. settings were hardcoded, no environment variables 15 / 69
Continuous Integration Travis (https://www.travis.org) language: python python: - "2.7" install: - pip install -r requirements-dev.txt script: "python manage.py compilemessages && python manage.py test" Gitlab CI is also open source and you can use. Your laptop can become a slave for your CI 29 / 69
Tests Behave (https://github.com/behave/behave) (BDD) Feature: This feature is useless Scenario: Create a screenshot Given Go on PyCon Ireland Website And Click on "Full Schedule" Then Take a screenshot 35 / 69
Tests Behave (https://github.com/behave/behave) (BDD) Feature: This feature is useless Scenario: Create a screenshot Given Go on PyCon Ireland Website And Click on "Full Schedule" Then Take a screenshot @given("Go on PyCon Ireland Website") def step(context): driver.get('https://pyconie17.python.ie') @given('Click on "{link_text}"') def step(context, link_text): driver.find_element_by_link_text(link_text).click() @then('Take a screenshot') def step(context): driver.save_screenshot() 36 / 69
Tests Django + Behave = behave_django You can use behave with Django, in fact, a scenario will be executed in a transaction and you can interact with your database. @when(u'I visit "{url}"') def visit(context, url): context.browser.visit(context.base_url + url) 37 / 69
Tests Django + Behave = behave_django You can use behave with Django, in fact, a scenario will be executed in a transaction and you can interact with your database. @when(u'I visit "{url}"') def visit(context, url): context.browser.visit(context.base_url + url) @given(u'user "{username}" exists') def create_user(context, username): # This won't be here for the next scenario User.objects.create_user(username=username, password='SeCr4T') 38 / 69
Tests behave + Django + Selenium + Sphinx = Updated screenshots for your documentation pip install sphinx-selenium-screenshots Change the configuration of your sphinx project screenshots_server_path = 'http://localhost:8080' ..screenshot:: schedule.png :server_path: /schedule Your developers and users will be happy with an updated documentation, you can provide a PDF or a real book with a print provider 41 / 69
Write Code/Refactoring These tools will help your code With the tests, you can start to rewrite the bad code django-extensions pip install django-extensions Show the urls Generate a graph of your models Integration of a web interface for the debugger more features... 45 / 69
Write Code/Refactoring These tools will help your code With the tests, you can start to rewrite the bad code pyflake8, pylint radon (Cyclomatic Complexity, Maintainability Index) vulture (Find deadcode) 46 / 69
Write Code/Refactoring These tools will help your code With the tests, you can start to rewrite the bad code mypy with mypy-django gnrbag.py:84: error: Incompatible types in assignment (expression has type "classmethod", va gnrbag.py:317: error: Name 'json' already defined gnrbag.py:2874: error: Need type annotation for variable gnrbag.py:3083: error: Dict entry 3 has incompatible type "int": "str" ` 47 / 69
Write Code/Refactoring These tools will help your code With the tests, you can start to rewrite the bad code autoflake --remove-all-unused-imports isort 48 / 69
Pro ling django-devserver + line_profiler Only for Python 2 [11/Jul/2017 12:26:50] "GET /favicon.ico HTTP/1.1" 302 0 [11/Jul/2017 12:26:50] "GET /en/favicon.ico HTTP/1.1" 301 0 [sql] (3ms) 1 queries with 0 duplicates [profile] Total time to render was 0.03s [profile] Timer unit: 1e-06 s Total time: 0.009523 s File: $VIRTUALENV/XXX/lib/python2.7/site-packages/cms/views.py Function: details at line 23 Line # Hits Time Per Hit % Time Line Contents ============================================================== 23 def details(request, slug): 24 """ 25 The main view of the Django-C 26 page. 27 """ 50 / 69
Pro ling pytest-profiling with --profile-svg --durations=2 $ pytest --durations=2 --profile-svg ======================== slowest 2 test durations ========================================== 0.47s setup tests/test_reset_password.py::ResetPasswordTestCase::test_reset_password 0.36s call tests/test_stripe.py::StripeViewTestCase::test_add_stripe_on_order_test if you are a purist, maybe you will prefer cProfile 51 / 69
Pro ling cprofilev is a web interface for the cProfile output pip install cprofilev cprofilev -f prof/test_reset_password.prof [cProfileV]: cProfile output available at http://127.0.0.1:4000 53 / 69
Debugging django-pdb and --ipdb pdbpp (pdb++) (for pytest) python -m pdb manage.py test #or python manage.py test --pdb Support for pytest-ipdb has been stopped & replaced by pdbpp https://asciinema.org/a/143426 54 / 69
Deployment We already use: Docker docker-compose But for the Continuous Delivery we need Kubernetes / Docker Swarm For example, Gitlab 10 provides the support of the Continuous Delivery with Kubernetes 58 / 69
Integrated Development Environment You can use your favourite editor Emacs | Vim Atom Visual Code Sublime Text ed but maybe you could give a try to PyCharm (Community or Pro) Auto-Completion Code Coverage (Remote) Debugging Profiling Virtual env Integration with the documentation Integration with Type Hinting Integration with Docker ... they offer pro licenses if you work on a open source project or discount 68 / 69