PyCharm Edu 4 EAP: Integration with Stepik for Educators

PyCharm Educational Edition rolls out an Early Access Program update – download PyCharm Edu 4 EAP2 (build 172.3049).

Integration with Stepik for Educators

In 2016 we partnered with Stepik, a learning management and MOOC platform, to announce the Adaptive Python course. But if you want to create your own Python course with the help of PyCharm Edu, integration with Stepik may help you easily keep up your learning materials and share them with your students.

Let’s take a simple example based on the Creating a Course with Subtasks tutorial and look at the integration features in more detail.

Continue reading

Posted in Early Access Preview | Tagged | 1 Comment

PyCharm 2017.2 EAP 4

The fourth early access program (EAP) version of PyCharm 2017.2 is now available! Go to our website to download it now.

New in this version:

  • Docker Compose support on Windows. If you’re using Docker on Windows, please try it out. To set up a Compose project, go to your project interpreter, Add Remote, choose the ‘Docker Compose’ interpreter type and get started. If you need some help getting started, read our blog post on Docker Compose for Linux and Mac and ignore the warnings about Windows.
  • Support for Azure databases, and Amazon Redshift. To try this out, open the database pane, use the green ‘+’ to add a data source, and choose the one you’re interested in.
  • We’ve also fixed a lot of bugs related to Django support, Jupyter notebooks, and code inspections.
  • And more! See the release notes for details

Please let us know how you like it! Users who actively report about their experiences with the EAP can win prizes in our EAP competition. To participate: just report your findings on YouTrack, and help us improve PyCharm.

To get all EAP builds as soon as we publish them, set your update channel to EAP (go to Help | Check for Updates, click the ‘Updates’ link, and then select ‘Early Access Program’ in the dropdown). If you’d like to keep all your JetBrains tools updates, try JetBrains Toolbox!

-PyCharm Team
The Drive to Develop

Posted in Early Access Preview | Leave a comment

Upgrade Your Testing with Behavior Driven Development

BDD? Why should I care?

Back in the day, I used to write terrible code. I’m probably not the only one who started out writing terrible PHP scripts in high school that just got the job done. For me, the moment that I started to write better code was the moment that I discovered unit testing. Testing forced me to properly organize my code, and keep classes simple enough that testing them in isolation would be possible. Behavior Driven Development (BDD) testing has the potential to do the same at a program level rather than individual classes.

A common problem when making software is that different people have different opinions on what the software should do, and these differences only become apparent when someone is disappointed in the end. This is why in large software projects it’s commonplace to spend quite a bit of effort in getting the requirements right.

If you’re making a small personal project, BDD can help you by forcing you to write down what you want your program to do before you start programming. I speak from experience when I say this helps you to finish your projects. Furthermore, in contrast to regular unit testing you get separation of concerns between your test scenario, and your test code. Which programmer doesn’t become excited about separation of concerns? This one sure does 😀

The real value of BDD arises for those of you who do contract work for small businesses, and even those with small to medium-sized open source projects, wouldn’t it be useful to have a simple way to communicate exactly what the software should do to everyone involved?

Okay, so how do I get better software?

Behavior driven development is just that, development which is driven by the behavior you want from your code. Those of you who do agile probably know the “As a <user>, I want <behavior>, so that <benefit>” template; in BDD a similar template is proposed: “In order to <benefit>, as a <user>, I want <behavior>”. In this template the goal of your feature is emphasized, so let’s do some truth in advertising here:

In order to show off PyCharm’s cool support for BDD

As a Product Marketing Manager at JetBrains

I want to make a reasonably complex example project that shows how BDD works

This is still rather vague, so let’s come up with an actual example project:

Feature: Simulate a basic car

To show off how BDD works, let’s create a sample project which takes the  classic OO car example, and supercharges it. 

The car should take into account: engine power, basic aerodynamics, rolling  resistance, grip, and brake force.

To keep things somewhat simple, the engine will supply constant power (this is not realistic, as it results in infinite Torque at zero RPM)

A key element of BDD is using examples to illustrate the features, so let’s write an example:

 

Scenario: The car should be able to brake

The UK highway code says that worst case scenario we need to stop from 60mph (27 m/s) in 73m

Given that the car is moving at 27 m/s

When I brake at 100% force

And 10 seconds pass

Then I should have traveled less than 73 meters

 

By writing this example, it becomes clear that our code will need to be aware of time passing, keep track of the car’s speed, distance traveled, and the amount of brakes that is applied at a given point in time.

If you have complex examples, or want to check a couple of similar examples, you can use ASCII tables in your feature file to do this. To keep this blog post to a reasonable length I won’t discuss those, but you can check the code on GitHub to see an example, or read more in the behave docs.

Feature files and steps

In BDD, you first write a feature file which describes the feature, with examples that outline how the feature is supposed to behave in certain cases. Using BDD tools, you should then be able to test the scenarios in these feature files automatically.

To make the scenarios testable, they need to be structured in a specific way:

Given a precondition

When an action

Then a postcondition

So let’s take our feature from above, add some scenarios, and create a feature file which we will put in a ‘features’ directory in our project. As always, you can follow along with the code on GitHub.

Most BDD tools also support starting a sentence in the scenario with ‘And’ which will behave the same way as the sentence before it, so ‘Given, And’ will behave just like ‘Given, Given’.

Next you define steps in code, which execute the test. For this, we need a BDD tool. In Python a good choice of tool is behave. An important note here, the newest version of Behave at the time of writing (Behave 1.2.5) is not compatible with Python 3.6, so please use Python 3.5!

If at this point we run behave, it will detect our feature and scenarios, but tell us that all of our steps are still undefined. So let’s have a look at how we can make the scenario testable. Let’s implement the “car should be able to brake” scenario:

This code goes into a file in the /features/steps folder. By writing the test code first you’re forced to think about what you would like your eventual application code to look like. Also note that we’re using PyHamcrest (a library which provides better matchers between expected and actual values) here to define the assertions, as they give us a lot more helpful error messages than regular assertions when they fail.

Running Behave Tests

To run our Behave tests in PyCharm, we need to add a Behave run configuration. To do this, just add a run configuration like any other, but select Behave:

Add behave run configuration

 

You don’t need to configure anything else. If you run behave without specifying anything, Behave will execute all the feature files in your project. So let’s run it:

All tests fail

We can see that our feature is tested, using all of the scenarios that we’ve defined for our feature. As we haven’t written any code yet, all tests fail, and everything is red :( So let’s write some code and see what it looks like after we finish:

All tests pass

Much better, right? Now let’s say we made a mistake, for example, if we forgot the deltaT term when adding the acceleration to the car’s speed, we will see that the acceleration tests fail. Of course PyCharm makes it easy for us to put a breakpoint in the code, and then debug our test:

Debug a test

To Conclude

BDD is a tool which has the potential to make your software better. This blog post was a very short introduction, and I hope it’s been enough to get some of you interested in giving it a shot! Please let me know in the comments if you’d like to read more about BDD in the future.

Posted in Tutorial | Tagged | Leave a comment

Template Debugging

In April we had a webinar about Visual Debugging. I misfired at the end, when showing template debugging in web frameworks, and promised a do-over.

Here’s the do-over…let’s talk about a wonderful and useful feature in PyCharm Professional: breakpoints in templates. PyCharm’s visual debugger is a killer feature, usually the highest-rated feature in our IDE. PyCharm can put breakpoints not just in Python code, but in Django and Jinja2 templates.

Let’s take a look at PyCharm Professional template debugging in Django, Flask, and Pyramid. In this blog post, I’m using the latest stable release, version of 2017.1.3.

Django Template Debugging

Let’s start with a simple sample project using a Django cookiecutter. We’ll start the Django server using the debugger. Note: I’m on macOS so I previously clicked the debugger console link to compile the Cython speedups for this Python version.

Django Startup

With Django now running under the debugger, let’s set a breakpoint in one of our templates, to inspect the value of socialaccount_providers:

Django Set Breakpoint

Reloading the page now pauses execution on that line of the template. We can view all the variables in scope, with all the other debugging features, just like regular debugging:

Django Reload Page

It’s important to make sure PyCharm knows the template language used in the project. If this isn’t set correctly, template debugging won’t work. Let’s confirm that this project uses Django templates:

Django Template Preference

Flask Template Debugging

Flask uses Jinja2 for its template engine, and PyCharm Professional supports debugging Flask templates in Jinja2. We again have a simple Flask todo project which we’ll start under the debugger:

Flask Startup

Setting a template breakpoint is similar to Django:

Flask Set Breakpoint

When we reload our todo list, PyCharm Professional stops execution on that line in the template:

Flask Reload Page

As explained above, we need to ensure this project uses Jinja2 as its Python Template Language:

Flask Template Preference

Pyramid Template Debugging

For completion, PyCharm supports other web frameworks such as Pyramid, and the process is the same. We run the Pyramid server under the debugger:

Pyramid Startup

This is a Jinja2-based Pyramid project which means we can set breakpoints in templates:

Pyramid Set Breakpoint

Again, reloading the page stops the Pyramid request execution at the breakpoint in the template:

Pyramid Reload Page

As a note, Pyramid has first-class add-on support for Jinja2, Chameleon, and Mako, but PyCharm’s template debugging is restricted to Jinja2 (and Django). Also, Jinja2 template debugging isn’t restricted to web frameworks: you should be able to set breakpoints and debug templates in a non-web Python application.

Wrapup

The webinar showed many of the powerful, productive features in “Visual Debugging”: breakpoints, stepping, watches, etc. These features apply as well to template debugging. In this blog post, we showed the first steps needed to apply visual debugging to templates.

If you have any questions, please ask in the comments below. We’d love to hear from you.

Posted in Cool Feature, Video | Leave a comment

PyCharm 2017.1.4 is now available

We’re happy to announce that PyCharm 2017.1.4 is now available for download from our website.

Fixes in this version:

  • Debugger bugs related to IPython and Qt
  • Performance issues when editing Django projects
  • And more, see the release notes for details.

-PyCharm Team
The Drive to Develop

Posted in Release Announcements | Tagged | 2 Comments

PyCharm 2017.2 EAP 3

The third early access program (EAP) version of PyCharm 2017.2 is now available! Go to our website to download it now.

New in this version:

  • Support for typing.NamedTuple
  • The DataFrame viewer automatically resizes columns to ensure you can see the contents. Furthermore, it now supports pandas.Series
  • Now if you write a call to a function with more parameters than the function takes, ‘Change signature’ will be an available quick fix. This quick fix updates the signature of the function to accept the new argument.
  • And more! See the release notes for details

Please let us know how you like it! Users who actively report about their experiences with the EAP can win prizes in our EAP competition. To participate: just report your findings on YouTrack, and help us improve PyCharm.

To get all EAP builds as soon as we publish them, set your update channel to EAP (go to Help | Check for Updates, click the ‘Updates’ link, and then select ‘Early Access Program’ in the dropdown). If you’d like to keep all your JetBrains tools updates, try JetBrains Toolbox!

-PyCharm Team
The Drive to Develop

Posted in Early Access Preview | Tagged | 5 Comments

PyCharm 2017.1.4 RC Available

We’re happy to announce that you can now get the release candidate for PyCharm 2017.1.4 from our Confluence page.  Download PyCharm 2017.1.4 RC now.

Fixes in this RC:

  • Various debugger issues have been resolved, involving the Cython speedups, an issue with adding breakpoints on the fly, and PyQT debugging
  • Test runners with unittest, and nosetests
  • Several inspection problems

If you’re using PyCharm 2017.1, please update to this version and let us know if everything works well for you! To update, either get the installer from Confluence, or update from PyCharm (Help | Check for Updates). Do you use multiple JetBrains IDEs? Then check out JetBrains Toolbox to help you make sure all your IDEs are up to date at all times.

-PyCharm Team
The Drive to Develop

Posted in Early Access Preview | Tagged | 1 Comment

PyCharm Edu 4 Early Access Program is Open

PyCharm Educational Edition follows its professional sibling and also starts the Early Access Program (EAP) for PyCharm Edu 4, available for free download now!

What is EAP and why should you join?

We at JetBrains believe that making tools for developers takes listening carefully to everyone who uses our products, from students to teachers, from beginners to experienced developers. This is why we run our Early Access Programs – so you can evaluate new features, discuss the product and influence development from early stages onwards. Your feedback is more than welcome here in the comments or report issues to our tracker!

Please note that the quality of EAP versions may at times be far below the usual beta standards. You can install PyCharm Edu 4 EAP along with the stable PyCharm Edu 3.5 and get regular updates for both. An easy way to keep your PyCharm Edu installations up to date is to use JetBrains Toolbox.

What’s new in PyCharm Edu 4

In the upcoming release, we’re focusing on better user experience for both students and teachers.

First of all, to make the product start as plain as possible, we’ve changed the welcoming UI. Now you begin by choosing your role, Student or Teacher.

Continue reading

Posted in Early Access Preview | Tagged , | 2 Comments

PyCharm 2017.2 EAP 2 (build 172.2656.2)

On this first summer day of 2017, we bring you the fresh PyCharm 2017.2 EAP build 172.2656. Since the previous EAP build, we’ve introduced a couple of new features as well as a lot of bug fixes:

– A new option for selecting PyQt backend while debugging
– A new string format inspection for new-style format methods
– Fixes for false positive Python inspections
– Fixes for unit testing support
– Jupiter Notebook support fixes
– And much more, see the release notes

>>>
# TODO:
# 1. Get the fresh PyCharm 2017.2 EAP build now from our website!
# 2. Participate in PyCharm 2017.2 EAP contest: File bugs, feature
# requests, participate in active discussions and win! Read more
# in the EAP announcement.

-PyCharm Team
The Drive to Develop

Posted in Contest, Early Access Preview | Tagged | 3 Comments

PyCharm 2017.1.3 Out Now!

We’re happy to announce that PyCharm 2017.1.3 is now available. You can get it now from our website, or using the updater in PyCharm.

Improvements since PyCharm 2017.1.2:

  • Test runner issues: django-nose tests, stdout from tests, and various other fixes
  • Pyramid project creation with Chameleon templates
  • The issue which caused our community edition installer for macOS to be unsigned has been fixed
  • An issue that caused PyCharm to freeze on startup has been resolved
  • Several bugs related to React support have been fixed
  • macOS terminal locale detection
  • As always, you can read the further details in the release notes

We’d like to thank the users who tried the EAP versions of this release for helping us make sure that this version of PyCharm is of the quality you expect from a JetBrains IDE.

If you’d like to see new PyCharm features before we release them, try out the EAP version of our next release.

PyCharm Team
-The Drive to Develop

Posted in Release Announcements | Tagged | 15 Comments