This guide explains how to use PyCharm to debug HubCommander.
This guide assumes that you:
- Have read the contributing document, configured Slack, and have a working Python 3 development environment.
- Have installed HubCommander
Once you complete those two steps, download and install PyCharm.
Follow the instructions below to get PyCharm configured and working properly:
-
Open PyCharm. At the title screen click
Open
-
Navigate to the directory that contains the HubCommander code. Which, if following the contributing and installation instructions, will be located in a directory named
python-rtmbot-0.4.0
. You want to open the encompassing directory. It should look like: -
You will then be presented with a new PyCharm project. On the left-side of the screen, there is the Project Viewer. It should look similar to this:
-
Right-click on the
hubcommander
directory in the project viewer >Mark Directory as
>Sources Root
-
On macOS, type
⌘,
-- on Linux and Windows, go to File > Settings. Next, typeProject Interpreter
in the search box. Verify that it is set to the virtual environment that was created by the installation script. If not, then click the gears icon >Add Local
, and then navigate to thevenv/bin/python
that was created by the script. ClickOK
to save and close the window.
We will now make sure that py.test can run properly.
If you did not already, follow the instructions in the Install the unit test requirements
section of the contributing guide
to set up all the required testing dependencies.
Next, to configure PyCharm for tests, open the PyCharm preferences, and type default test runner
in the search box. In
the drop-down for Default test runner
, select py.test
, then click OK.
Then, to test that it is working, expand hubcommander
in the project explorer. Right-click on tests
, and click
Debug py.test in tests
. It should hopefully report that a number > 19 tests pass.
If you want to debug a feature, you can place breakpoints and then step through them. This can be immensely helpful at debugging what's happening under the hood.
To get HubCommander runnable, you will need to make a debug configuration in PyCharm. This is somewhat identical to the unit test section above, but will require you to define environment variables with the secrets in them.
🚨
Follow the these steps:
-
To configure the debug configuration, go to
Run
>Edit Configurations
, and a new Python configuration: -
Under
Script
, you want to navigate to yourvenv/bin/rtmbot
. -
Under
Environment
>Environment Variables
, you want to click the three dots (...), and click the green+
to add in, at a minimum, the following:PYTHONIOENCODING
:"UTF-8"
SLACK_TOKEN
:YOUR-SLACK-TOKEN-HERE
- ... and any other tokens and secrets that need to be present for you to debug
-
Set the
Working Directory
to thepython-rtmbot-0.4.0
directory. -
Lastly... Set a name for the configuration to
Debug HubCommander
. Your configuration window should look something along the lines of this:
Once this is all complete, you are ready to debug! Place breakpoints where you want them, fire up Slack, and start debugging away.