IDE PyCharm

By pjain      Published Dec. 9, 2019, 6:15 a.m. in blog Programming   

Python IDEs Overview

IDE with Eclipse

  • PyDev in Eclipse bit more complex and slower and quite hard and problematic to a junior dev.

r PyCharm 101

PyCharm BPR CodeStyle

PyCharm 2016.3 Help :: Configuring Code Style

PyCharm, NGx, JS debugging

PyCharm 2016.3 Help :: Using AngularJS

PyCharm

Overview

  • PyCharm simplicity and straightforwardness in working with Django based projects. Especially with those project's virtual environments. You can set up a virtual environment and connect PyCharm afterwards to a ready made project. http://garmoncheg.blogspot.com/2012/01/establishing-dev-environment-with.html

  • PyCharm has a project run and run config/edit management buttons.

PyCharm, at least, DOES have an interactive console However, the suggestions above are better programming practices.

The interactive console is clunky, often fails to appear, and crashes all the time (I've tried several different versions and OSs).

PyDev and PyCharm, and quite a few others, have decent debugging features, but I don't think it has good integration with scientific tools. That means, if you plot, you lose access to your prompt. Not good.

  • Code Reformat - bulk tab Spaces - PEP8 better with spaces not mixed tabs/spaces
  • Settings > Code Style Python > uncheck [ ] Use tab character
  • Then select a project directory .. Code | Reformat .. this will convert all tabs properly

This only converts the tabs without changing anything else: Edit -> Convert Indents -> To Spaces

  • Where py3 is installed /usr/local/Cellar/python3/3.6.0/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /usr/local/bin/python3.6

PyCharm 2017.1 Help :: Quick Start Guide

Key Mappings

The default keymapping (on Mac) is option-shift-E. Then your variables are loaded in memory.

IDE Debug using PyCharm

Debugging is a part of the python process, that is run by your IDE. So debugger connects to it and interrupts execution of your code where you tell him to. - http://garmoncheg.blogspot.com/2013/06/django-how-to-debug-django.html

PyCharm Unit Tests

Creating and running a Python unit test - PyCharm - Confluence unit testing - Pycharm won't allow to run a file. Shows run unittest option only. - Stack Overflow

PyCharm REST

PyCharm 2017.1 Help :: REST Client Tool Window PyCharm 2017.1 Help :: Using AngularJS

2 ~m/Python/RestDjango/tastypieex/djangoapi/ - whatever API for JSON - polls app https://www.jetbrains.com/help/pycharm/2017.1/creating-and-running-your-first-django-project.html

DJ Pycharm

  • TUTE: https://www.jetbrains.com/help/pycharm/2017.1/creating-and-running-your-first-django-project.html

Settings Dedicated project type for Django

  • Settings > Django > [x] Enable Django Support

Create project, app via GUI Dialogs

  • File > New > Project

    • name, location, type: Django
    • select Py sdk or vEnv
    • initial first app (not same as Django project name)
  • Configure which manage.py script is main one

    • in Settings > Languages/frameworks > Django
    • Select desired Django project
    • Then select which manage.py script is main one using .. to browse path
    • In the Environment variables field, specify the environment variables to be passed to the script.
      • By default, this field is empty.
      • ... pops up existing environmental variables .. select those you want passed on.
  • RUN the tasks of the manage.py utility.

    Tools > Run manage.py task Enter manage.py task name: startapp select name of app

  • In the bottom panes .. manage.py console - shows the history of commands

  • You can simply type a taskname - and do completion
  • F1 for help

Debug setup and running

  • Setup debug in general

    • Run | Edit configurations
    • select desired one, or create a new one - https://www.jetbrains.com/help/pycharm/2017.1/creating-and-editing-run-debug-configurations.html
  • ^D to start debugging or bug button on main toolbar .

    • It will break at chosen breakpoints and you can .. Examine the rendering contexts in the Variables pane. Step through the breakpoints defined within the Django template. Use the debugging console.
  • Trace back exceptions that are raised in course of template debugging,

    • open Breakpoints dialog,
    • in the Django Exception Breakpoints tab, select the check box Suspend.
  • CONSOLE log Error window during running

Views, Templates Authoring

  • Ability to create templates from context/completion, usage

    • if you are hover over missing myindex.html below, just select A-enter to select from intention actions - create template return render_to_response('myindex.html', {...})
    • Just select from a template location - eg directories in settings.py TEMPLATE_DIRS, TEMPLATE_LOADERS
    • or you can specify your own location
  • In a template directory C-N and select HTML/XHTML file ..and create away!

  • Ability to debug Django templates

    • Debugging Jinja and Mako templates is not supported, settings>Python Template Languges > v is selected
    • Placing breakpoints to the lines of Django template files, at the lines with Django tags or expressions.
  • Navigation between views and templates.

    • in views.py while on a line with a template dir name, there will be a gutter icon .. click on that, goes to template
    • in a template file, click on gutter icon, goes to referring views.py
  • Templates Extends navigation

    • There will be a gutter icon eg if cursor is in a {% block content %}
    • this will take you to base template or vice-versa - for any extending implementing block window

Live templates (snippets) for the quick development of Django templates. Django templates support (syntax and error highlighting, code completion, navigation, completion for block names, resolve and

  • Completion for custom tags and filters, and quick documentation for tags and filters).

  • Multiple templates types supported: https://www.jetbrains.com/help/pycharm/2017.1/python-template-languages.html

Static files referring

  • settings.py should have 'django.contrib.staticfiles' added to INSTALLED_APPS
  • PRJDIR/static/ exists - or change settings.py STATICFILES_DIRS variable appropriately.

  • While editing eg <img src='' do ^-space and choice will b given to select resource images/xyz.png etc <img src='{{ STATIC_URL ^popup-here }}'

Code completion and resolve in

Code insight support for Django ORM.
views.py and urls.py files
Models, meta
Class-based views. PyCharm provides Intention action to convert Django function-based generic views to class-based views.

Generating model dependency diagrams for Django models.

Model dependency diagram enables you to get an overview of the models within your Django application, and analyze their relationships.

To open the Model Dependency diagram of a project

On the main menu, choose View | Show Model Dependency Diagram. On the context menu of the Project tool window, or the editor, point to Diagrams, and choose Show Diagram or Show Diagram Pop-up. Press ⌥⇧⌘U, or ⌥⌘U. Select the type of diagram from the pop-up window: Django models Google App Engine models SQLAlchemy

In the Model Dependency diagram, you can perform the following operations see: https://www.jetbrains.com/help/pycharm/2017.1/viewing-model-dependency-diagram.html Select elements. Add notes, delete elements. Change diagram layout. Change diagram scale. Navigate to source code. Navigate through the models using the Structure view (⌘F12). Find usages of the selected node element. Invoke refactoring commands.

Remote intepreters for production, Debugging, Buildout

Run/debug configuration for Django server.

Buildout see: https://www.jetbrains.com/help/pycharm/2017.1/buildout.html

DJ Globalization

  • SEE: https://www.jetbrains.com/help/pycharm/2017.1/internationalization-and-localization-support.html

0 comments

There are no comments yet

Add new comment

Similar posts

IDE Python other

Collaboration, Sync Processing =========

Simulation

PIMy Project Managment Review