Feature Spotlight: Behavior-Driven Development in PyCharm

Happy Friday!

Today I’d like to shed some light on another brand-new functionality upcoming for PyCharm 4 – Behavior-Driven Development (BDD) Support. You can already check it out in the PyCharm 4 Public Preview builds available on the EAP page.

Note: The BDD support is available only in the PyCharm Professional Edition, not in the Community Edition.

BDD is a very popular and really effective software development approach nowadays. I’m not going to cover the ideas and principles behind it in this blog post, however I would like to encourage everyone to try it, since it really drives your development in more stable and accountable way. Sure, BDD works mostly for companies that require some collaboration between non-programmers management and development teams. However the same approach can be used in smaller teams that want to benefit from the advanced test-driven development concept.

In the Python world there are two most popular tools for behavior-driven development – Behave and Lettuce. PyCharm 4 supports both of them, recognizing feature files and providing syntax highlighting, auto-completion, as well as navigation from specific feature statements to their definitions. On-the-fly error highlighting, automatic quick fixes and other helpful PyCharm features are also available and can be used in a unified fashion.

Let me show you how it works in 10 simple steps:

1. To start with BDD development and in order to get the full support from PyCharm, you first need to define a preferred tool for BDD (Behave or Lettuce) in your project settings:

settings

2. You can create your own feature files within your project – just press Alt+Insert while in the project view window or in the editor and select “Gherkin feature file”. It will create a feature file where you can define your own features, scenarios, etc. PyCharm recognizes feature files format and provides syntax highlighting accordingly:

feature_file

3. Since there is no step definitions at the moment, PyCharm highlights these steps in a feature file accordingly. Press Alt+Enter to get a quick fix on a step:

new_step

4. Follow the dialog and create your step definitions:

step_definition

5. You can install behave or lettuce right from the editor. Just press Alt+Enter on unresolved reference to get the quick-fix suggestion to install the BDD tool:

install

6. Look how intelligently PyCharm keeps your code in a consistent state when working on step definitions. Use Alt+Enter to get a quick-fix action:

intelligence

7. In feature files, with Ctrl+Click you can navigate from a Scenario description to the actual step definition:

navigate

Note: Step definitions may contain wildcards as shown in the step #6 – matched steps are highlighted with blue in feature files.

8. PyCharm also gives you a handy assistance on automatic run configurations for BDD projects. In the feature file, right-click and choose the “create” option, to create an automatic run configuration for behave/lettuce projects:

run_configurations

9. In the run configurations you can specify the scenarios to run, parameters to pass and many other options:

run_configurations2

10. Now you’re all set to run your project with a newly created run configuration. Press Shift+F10 and inspect the results:

tests

That was simple, wasn’t it?
Hope you’ll enjoy the BDD support in PyCharm and give this approach a try in your projects!

See you next week!
-Dmitry

Posted in Cool Feature | Leave a comment

First PyCharm 4 Preview Build Now Available

It’s an exciting day for us at JetBrains PyCharm, as the first PyCharm 4 public
preview build 138.2401 is finally available for download! Head on over to the PyCharm Early Access Preview (EAP) page and have a look at the download section where you can get it for your platform right now.

As usual the PyCharm 4 preview build is available in two editions – free/open source PyCharm Community Edition and full-fledged PyCharm Professional Edition. While both of them are available for download and use at no charge, PyCharm Professional Edition has a 30-day evaluation period, which means PyCharm 3.4 Professional Edition EAP build 138.2401 comes with a 30-day time-limited license as well.

Note: The PyCharm 4 EAP build is not in the final product release stage and might contain severe bugs, so it’s supposed to be installed along with your current PyCharm installation for evaluation and checking out new features. No patch update for this EAP build will be available from within the IDE.

The PyCharm 4 preview build introduces a lot of new features, bug fixes and improvements, including a number of recently added PyCharm’s unique features as well as some features and improvements from Web and IntelliJ platform sides.

The most notable PyCharm’s unique features in this preview build are:

Behaviour-driven development (BDD) assistance

Behaviour-driven development has never been so easy and natural. With PyCharm 4 EAP we introduce the special BDD assistance giving you the full control of your textual requirements, graphical representation of the test results, and extensive and intelligent assistance on each step of the overall BDD process:

BDD1

PyCharm 4 EAP now fully supports the two most popular Python tools for BDD: behave and lettuce.
PyCharm recognizes feature files, provides syntax highlighting, auto-completion, as well as navigation from specific feature statements to their definitions and back – all in a unified fashion.
Thanks to its high intelligence, PyCharm has a deep understanding of the definition steps: it shows errors and suggests automatic quick fixes, saving your time and increasing overall performance:

BDD2

PyCharm and PyDev debuggers are merged

As you probably know, previously PyCharm has been using special fork of the PyDev debugger with some PyCharm specific changes and our own unique features like GEvent debugging and breakpoints at Django templates. We’re very proud that the PyCharm team is an active member of the Python community, with many team members deeply involved in different open-source projects development. So recently we decided to make one more contribution to open-sourced software and merged our debugger code with that from the original PyDev repository. Now the work on the debugger continues from both sides (PyCharm and PyDev) in a single place. The merged source code now lives here: https://github.com/fabioz/PyDev.Debugger Pull requests are greatly appreciated!

Referring objects view in PyCharm debugger

When debugging your project you can open the referring objects view for a desired object during runtime. To do so, in the debug mode right-click the object in the “Variables” window then click “Show Referring Objects”:

referringobj

Jinja2 templates debugging

Now the PyCharm debugger works with Jinja2 templates. You can set breakpoints right in the editor, stop on them and perform other debugging actions the same way as in the already supported Django templates debugging mode:

jinja2

To learn more about the new BDD or debugger functionality, stay tuned for further blog posts, announcements, and tutorials.

Improved Python/Django console tool window

PyCharm automatically detects which type of the console should be run depending on your project type and context. The console can be launched via the tools window menu as shown on the picture below or using the “Ctrl+ E” shortcut:

python_console

Still, there is one more cool Python console feature that was included in this build:

showconsoleNow you can leave the console opened after a project run or a debug session, saving its context. In order to enable this functionality, you just need to mark the “Show command line afterwards” option in the project run/debug configurations:

pythonconsole

Method Call hierarchy

Thanks to the PyCharm’s fantastic static code analysis capabilities, PyCharm intelligently analyses the code and builds a call hierarchy trees for method calls in different scopes:

callhierarchy

New project creation wizard

The project creation wizard has changed a bit and now it has 2 steps:
On the first step you have to choose the project type. On the second step PyCharm shows you only relevant settings for the selected project type:

2stepcreation

Unittest sub-tests support

Python 3.4 support is even more polished with the PyCharm`s test runner now recognizing the subTest() context manager for unittest.

As usual, PyCharm 4 will have all features of the upcoming WebStorm 9 release. WebStorm 9 preview builds are already available (read more in WebStorm blog), so here is just a short summary of what’s new available in the PyCharm 4 preview build 138.2401 from the Web side:

- Updated Live Edit feature that can now automatically update your Node.js app on any changes
- Spy-js for Node.js applications
- PhoneGap/Cordova integration
- Postfix templates for JavaScript
- Improved Editorconfig plugin
- Gulp integration
- Improved Polymer support
- Support for the latest Sass 3.4

These new features are available for installation from JetBrains plugin repository.

Apart from additional features and improvements from the Web side, PyCharm 4 gets a lot of improvements from the underlying IntelliJ Platform. The most noteworthy changes are:

  • Redesigned Settings(Preferences in OS X) dialog: settings dialog gets a cleaner interface, a more straightforward layout and a rearranged settings tree (some of the settings have been merged, and others reordered based on their frequency of use):

settings2

  • The Open action from the Welcome screen now opens single files. That means you can now edit files regardless of the projects and their configurations.

Other improvements from the IntelliJ Platform include:
- Backspace smart indent makes the Backspace key aware of your code formatting settings, so it doesn’t break your code when removing indents before caret.
- The new Code cleanup action (available via Analyze → Code Cleanup or as an option in the VCS commit dialog) applies quick-fixes in batch mode to selected files.
- The improved Find in path action
- Copy/paste selected code as HTML/RTF is now available without additional plugins.
- Better IDE startup time.
- Mercurial support improvements
- Reset Current Branch to Here action now available from the Git Log

Download PyCharm 4 preview build 138.2401 for your platform right from the project EAP page and please report any bugs and feature request to our Issue Tracker.

Develop with pleasure!
-PyCharm team

Posted in Cool Feature, Early Access Preview | 22 Comments

Feature Spotlight: Deployment with PyCharm

Happy Friday, everyone!

I’d like to highlight a very handy feature of PyCharm called Deployment support in our spotlight this week:

deployment

When developing some Python or Web applications, chances are at one point we will be deploying them. During development we may want to deploy our application to a testing/staging server, to a VM or a Vagrant box. And once release day is there we want to make sure our carefully crafted code makes it to production.

PyCharm shines here again, as it supports code deployment to remote hosts. Read the Deployment in PyCharm tutorial to learn how to easily set up mappings, browse files on a remote machine, upload and synchronize your code, compare local and remote versions of your files and configure automatic synchronization.

See you next week!
-Dmitry

Posted in Cool Feature | 2 Comments

Feature Spotlight: Multiple Selections in PyCharm

Today I’d like to highlight one of the most top voted features that appeared in PyCharm 3.4 some time ago – Multiple Selections. Since then a lot of people have been using it and enjoying the increased productivity while editing.

With this feature you can:

  • Set multiple cursors in the editor area: Alt + Mouse Click (Option + Mouse Click for Mac OS X). Note that on some systems you also have to use Shift with the shortcuts mentioned.
  • Select/unselect the next occurrence: Alt + J / Shift + Alt + J (Ctrl + G / Shift + Ctrl +G for Mac OS X)
  • Select all occurrences: Shift + Ctrl + Alt + J (Ctrl + Cmd + G for Mac OS X)
  • Clone caret above/below (the shortcuts are not mapped yet)
  • Remove all selections: Esc

You can redefine these shortcuts in Settings -> Keymap -> Editor Actions if necessary.

Multiple selections work nicely together with other PyCharm features like Code completion, Select word at caret, Join lines, Copy/paste, and the others. This feature also works with all languages supported by PyCharm such as Python, HTML, JavaScript, CSS and more.

Here’s a short demo on how Multiple Cursors work in PyCharm:

Hope you’ll enjoy this handy feature!

-Dmitry

Posted in Cool Feature | 6 Comments

Meet the PyCharm Team in Berlin, Germany at EuroPython 2014

europythonJuly 21 – 27, the JetBrains PyCharm Team will be in Berlin, Germany for EuroPython 2014. The conference will be held in the Berlin Congress Center which is found in the immediate vicinity of the Fernsehturm at Alexanderplatz, right in the centre of Berlin.

The EuroPython conference is the second largest global conference for the popular programming language Python, after the PyCon US conference in North America. It is aimed at everyone in the Python community, of all skill levels, both professional programmers and those who just started learning this fantastic language. There will be more than 120 talks in five different tracks, including one by JetBrains:

Python Debugger Uncovered – Thursday, July 24 at 11:45
by Dmitry Trofimov

This talk will explain how to implement a debugger for Python. We’ll start with setting a simple trace function, then look how it is implemented in modern IDEs like PyCharm and Pydev. Then we go further in the details and uncover the tricks used to implement some cool features like exception handling and multiprocess debugging.

The show represents a great opportunity to meet three members of the PyCharm Team, learn about the latest release, our current developments or just say hi. We invite you to stop by with your questions and chat about your experiences with PyCharm and other JetBrains products. We will be raffling some PyCharm licenses so be sure to register and grab some of our cool giveaways.

PyCharm_team

We look forward to meeting you there! For more information on the EuroPython 2014 conference, please visit the official website.

Develop with pleasure!
PyCharm team

Posted in Conferences & Events | Leave a comment

Write Clean, Professional, Maintainable, Quality Code in Python

Bad code can work. But if it’s buggy, messy and difficult to maintain, it can eventually break a project, a development team or even an entire company. The necessity to write clean, professional and maintainable code is obvious and is getting more important nowadays as projects grow, more people become involved in development, and more projects go open source.

In today’s world projects are huge, with dozens and hundreds of people working on the same code base. Early detection of possible problems in code plays a huge role in helping developers write clean, professional, high-quality code that will be understood by others. Luckily, there are a number of tools that allow Python developers to analyse their code against errors and possible perils. These include pyflakes, pylint, pep8, and others. The problem, however, is that many developers use them after the code is already written, just to check what can be improved. A much more sound approach is, as with Continuous Integration, to find problems early and write clean code from the very beginning. This is where IDEs come in with their code intelligence.

What distinguishes a good IDE from good text editors? By definition, an IDE tightly integrates a range of development tools tuned to work with each other seamlessly. Unlike text editors, even superior ones like Vim or Sublime Text, a good IDE intimately understands your code and its flows. While some IDE functionality can be enjoyed in a text editor by installing third-party plugins, these plugins are not guaranteed to work smoothly as they don’t interact with each other. They do their highly-tailored job, but without communicating with other subsystems. An IDE with its core collects data from different subsystems, effectively transfers this data to other subsystems and reuses it whenever is possible. Consequently, it provides code intelligence with refactoring abilities, code navigation, automatic code fixes, testing assistance, smart code autocompletion and ultimately suggestions to keep your code maintainable and of a good quality.

PyCharm is one of the most intelligent Python development products on the market today. It has a lot of specially selected tools, tuned and tested to work with each other: an advanced editor derived from IntelliJ Platform, a debugger with the ability to collect runtime type statistics, many unique code inspections which work on the fly, and lots more. Any PyCharm user can benefit from using it for their development.

The ultimate goal of any development tool is not only to speed up your development, but more importantly, to keep your code under control, in a consistent state. This is applicable to any project, but is most valuable when you have a team or simply some large project that must stay maintainable. Or when you have coding standards to adhere to. Or when you just want to get unified and standardized code as output that you want to share with others.

A key benefit you get from PyCharm is being able to write clean, professional and maintainable code from the early development stages. It proactively monitors your code state as you type, checking it against numerous inspections for code style violations rules and sophisticated traps that are not obvious but potentially can break your application. As a result, you can prevent possible problems, rather than having to troubleshoot them later. You start to form a development practice where you get instant feedback right as you’re coding. This saves time on bug-fixing and, in the end, allows your team to develop cohesive software more rapidly.

dangerous

Let me highlight some of the features in PyCharm that can help you consistently hold your code to a high quality standard.

Code Style violations

The very first feature I need to describe is basic code style checking. Python is very sensitive to code formatting by its nature. The very basic requirement to keep your code in a consistent state is to preserve the same formatting style across all over your project. PyCharm has a special subsystem that controls code style and inspects different code style violations. It watches for code formatting rules like tabs and indents, spaces, wrapping and braces, blank lines etc. If there are any code style violations, PyCharm will highlight them in the code:

codestylehighlight

PyCharm has special automatic quick-fixes for errors that it finds, so in this case you can quickly apply the “Reformat file” fix and PyCharm will make the file conforming to project code style settings:

reformatfile

These code style settings are highly customizable, and you can set your own code style scheme for each desired language, per project:

codestylesetings

You can also save your settings and apply them to other projects or share with your peers.

Simple formatting is not enough! Here come customizable inspections

PyCharm has a huge number of code inspections for various projects, languages and frameworks. Those inspections checks your code against different errors. PyCharm finds different types of errors such as unresolved references, unused variables and imports, deprecated functions, classes and modules, PEP8, package requirements, and many many others. You can review the list of available inspections in Settings | Inspections. The checklist is comparable to pylint functionality, and you’ll notice it’s very comprehensive. Pylint is still the definitive tool for Python code analysis, but PyCharm’s advantage is that it checks your code on the fly. PyCharm has many settings to control those inspections: enable and disable, set the severity of inspections, edit the behavior of alerts, etc.:

inspections

You can also create and share customized inspections profiles. That is very helpful when you want to apply the same set of checks against different projects, or if you want your entire team to develop in the same style.

Manageable code inspections scopes

PyCharm provides flexibility for managing code quality with inspections scopes. Inspection scopes settings let you set and manage different rules for individual project parts:

scopes

Code analysis reports

With PyCharm, you can check your code against different inspection profiles, both standard and customized, and get a detailed report for further investigations. Lots of actions can be performed with code analysis reports as well:

inspections_reports

You can export the results to HTML or XML for further investigation. In that way PyCharm works similar to pylint.

PEP 8 integration

Among a number of different inspections, PyCharm supports the PEP 8 standard by integration of the official pep8.py tool. This tool is being run in the background and you get an instant results with the highlights of PEP 8 violations in the code editor. Like with other inspections, you can change the severity of PEP 8, edit highlighting and other settings.

pep8

Python code compatibility checks

Living in a world with two contending versions of Python 2 and 3, it’s very important to check your code for compatibility against different versions of Python. PyCharm has a special inspection that helps you do that:

compatibility

Quick-fixes

OK, so PyCharm finds errors and warnings. What else? PyCharm doesn’t just alert you to potential problems, but helps you with suggestions to fix them in-place. When a problem is found at the line your caret is on, you’ll notice a red or yellow bulb next to it. Choose from the list of ways to fix the problem and apply the suggested fix in one click / keypress.

quickfixes

As you can see, PyCharm has a powerful and highly customizable toolset for code quality assurance. It checks your code on the fly and helps you eliminate problems early.

This article only scratched the surface of what PyCharm can really do. There are a lot more features in PyCharm that assist you with code quality for your projects. For more details on features mentioned in this article and to learn additional handy features like code auto-generation, type hinting and more, please consult the tutorial Code Quality Assistance Tips and Tricks, or How to make your code look pretty? available in our tutorial space among other useful tutorials about PyCharm.

All the described functionality is available in PyCharm Community Edition, which is free and open source! Feel free to use it to improve your code quality and speed up the development process for your professionally developed projects!

Develop with Pleasure!

Posted in Cool Feature, Tutorial | 23 Comments

Announcing PyCharm 3.4.1

We’re eager to announce that we’ve just made available a fresh PyCharm 3.4.1 update for both the free Community Edition and the full-blown Professional Edition!

Thanks everyone for giving us a lot of helpful feedback and reporting problems to our public tracker. So as a recap, some notable highlights of this release include: a fix for unexpected hangs and freezes of the IDE, a Python debugger console fix, a fix for running a Django server on a remote host and fixes for Django and Jinja template tags.

For further details on the bug fixes and changes, please consult the Release Notes.

PyCharm 3.4.1 installation sources can be found on PyCharm Download page. You can also use the patch-based upgrade to upgrade from previous PyCharm versions without a full reinstallation.

As always, please report any problem you found in the issue tracker.

If you would like to discuss your experiences with PyCharm, we look forward to your feedback on our public PyCharm forum and twitter.

Develop with Pleasure!
-PyCharm team

Posted in Release Announcements | 13 Comments

The PyCharm 3.4.1 Release Candidate is now available

PyCharm 3.4 – the brand-new major release of our intelligent Python IDE – has been released just a bit more than a week ago and now we’re almost ready to release the minor 3.4.1 bug-fix update. Today we’ve published the PyCharm 3.4.1 RC build 135.1049, which is already available for download and evaluation from the EAP page.

The full list of fixes and improvements for this build can be found in the release notes. The most notable among them are: a fix for unexpected hangs and freezes of the IDE, a Python debugger console fix, a fix for running a Django server on a remote host and fixes for Django and Jinja template tags.

The build is available for download, and you can also use the patch-based upgrade to upgrade from within the IDE (from PyCharm 3.4 only) without a full reinstallation.

If no problems will occur with this build in the coming days, we’ll release PyCharm 3.4.1 on this week. Anyway, if you encounter problems, please file them to our public tracker.

Develop with Pleasure!
-PyCharm team

Posted in Early Access Preview | Leave a comment

Announcing The PyCharm 3.4 Release

We’re happy to announce the immediate availability of PyCharm 3.4, the new major release of our intelligent IDE for Python and Web development. As before, PyCharm 3.4 is available as a full-fledged Professional Edition for Python and Web development or the free and open-source Community Edition for pure Python development and education.

Download PyCharm 3.4 for your platform today!

Despite the minor version number, PyCharm 3.4 is a true major release. We’re staying up to speed with the cutting-edge technologies from the Python world, in particular the latest versions of Python 3.4, Django 1.7 and others, which you’ve come to expect.

With v3.4 we introduce improved functionality, better performance, and many handy new must-have features that we hope will make you even more productive!

Here are the most notable highlights of the release:

- New Python interpreters management with a new UI
- New refined support for remote interpreters
- Django 1.7 support
- New live templates for Python
- Multiple carets and selections
- Vagrant support improvements
- New automatic quick-fixes
- Full debug support in the interactive Python console
- Debugging for Stackless Python
- Advanced built-in AngularJS support
- IdeaVim plugin updated with new enhancements
- New ‘Github’ color scheme for the PyCharm editor
- And many other valuable improvements across the IDE

Please see what’s new in PyCharm 3.4 for more details, and download the IDE for your platform.

PyCharm 3.4 Professional Edition is a free update for everyone who purchased their license after May 29, 2013. As usual, a 30-day trial is available if you want to try PyCharm as your new Python/Django IDE.

Develop with pleasure!
JetBrains PyCharm Team

Posted in Release Announcements | 29 Comments

The Second Release Candidate for PyCharm 3.4 is now available

We are now approaching the final steps towards the PyCharm 3.4 release which is planned to be released in short. So today we’re happy to announce the availability of the second release candidate for PyCharm 3.4.

Generally speaking, feedback on the previous PyCharm 3.4 RC has been positive and we believe this second release candidate will be even better. That’s why we invite you all to try it out. Please take it for a spin and give us feedback. The PyCharm 3.4 RC2 build 135.973  is available for download from the Early Access Preview page.

The last few days since the announcement of PyCharm 3.4 RC, we’ve been only fixing bugs. So no any new functionality in this build. The complete list of bug fixes can be found in the Release Notes.

We hope that there will be no major bugs, but anyway, should you encounter any problems, please report them to our public tracker.

A patch update from the previous RC and EAP builds should be available soon.

Stay tuned, follow us on twitter and develop with pleasure!

-PyCharm team

Posted in Early Access Preview | 3 Comments