|
| 1 | +# Using DShell with PyCharm |
| 2 | + |
| 3 | +This document will outline how Dshell decoders and the framework itself can be setup to allow development and |
| 4 | +debugging within the Python IDE, PyCharm. If preferred, the concepts can likely be translated to other IDE’s and debugging environments. |
| 5 | + |
| 6 | +After first installing all prerequistes mentioned in the [README](../README.md) and then opening the source repository |
| 7 | +in Pycharm, the following needs to be done in order for PyCharm to correctly recognize the Dshell source code and executables. |
| 8 | + |
| 9 | + |
| 10 | +## Settings |
| 11 | + |
| 12 | +### Project Structure |
| 13 | +In order to properly use PyCharm with Dshell, we need to tell it where to find the relevant Python files. |
| 14 | +Under `File -> Settings -> Project: DShell -> Project Structure` set the folders `bin`, `decoders`, `lib`, and `lib/output` |
| 15 | +as sources. Then click OK. After a few seconds, you should now see all the red underlines on imports disappear. |
| 16 | + |
| 17 | + |
| 18 | + |
| 19 | +### Project Interpreter |
| 20 | +We also need to tell the Python interpreter where to find the relevant files. This is useful if you want to import |
| 21 | +Dshell modules within the interpreter. Under `File -> Settings -> Project: DShell -> Project Interpreter` click the |
| 22 | +gear icon next to the dropdown with the project interpreter you are going to use, and then select `More…` |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +Then with your current Python interpreter highlighted, click the small folder tree icon (below the filter icon) to see a |
| 27 | +window of `Interpreter Paths`. In this window click the `+` icon to the right and add the four folders added earlier |
| 28 | +(`bin`, `decoders`, `lib`, and `lib/output`). |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +You should now be able to import decoders and other Dshell modules using the built in Python interpreter. |
| 33 | + |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | +## Run Configurations |
| 38 | +Run configurations in PyCharm allow a user to specify how to run tasks and programs. In the context of Dshell, a |
| 39 | +configuration can be setup to specify which decoder to run, how to setup the environment variables needed by Dshell, and what working directory to use. |
| 40 | + |
| 41 | +### Opening Configurations |
| 42 | +The first step within PyCharm is to open up the interface to edit configurations. This can be done through the toolbar as |
| 43 | +shown below or by using the menu to navigate to `Run -> Edit Configurations…` |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +### Adding a New Python Configuration for Dshell |
| 48 | +Once the configurations interface is open, the next step is to add a new configuration. Since Dshell utilizes Python, a |
| 49 | +Python configuration needs to be created. Select the `+` symbol near the top left and select `Python` in the drop down menu. |
| 50 | + |
| 51 | + |
| 52 | + |
| 53 | +### Specifying the Configuration Details |
| 54 | +Now that the configuration window is open, the following fields need to be populated: |
| 55 | + |
| 56 | +- Script: The full path to the `decode.py` script in Dshell. |
| 57 | +- Script parameters: The parameters that would be passed in when running the decode command. |
| 58 | +- Environment variables: The environment variables found in the `.dshellrc` file in Dshell’s root directory. This is detailed more below. |
| 59 | +- Working directory: If all the settings use absolute paths, the working directory can be set to anything. Setting the working directory to a location where output files should be placed is a reasonable option. |
| 60 | + |
| 61 | + |
| 62 | + |
| 63 | +### Specifying the Environment Variables |
| 64 | +The environment variables in the configuration are important to mirror the Dshell shell. |
| 65 | + |
| 66 | +When first running Dshell, some of the first steps are to build the project using make and to run the "dshell" script. |
| 67 | +The build step is relevant here because it produces the `.dshellrc` file that the "dshell" script depends on to configure the shell’s environment. |
| 68 | + |
| 69 | +For the PyCharm configuration, open up the `.dshellrc` file in Dshell’s directory and take a look at the environment |
| 70 | +variables. Use these values to set the `Environment variables` field in the configuration. |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +### Save the Configuration |
| 75 | +Now that the configuration has been setup, just give it a name and hit OK. |
| 76 | + |
| 77 | + |
| 78 | +## Debugging |
| 79 | + |
| 80 | +### Select Your Configuration |
| 81 | +Before debugging, make sure the configuration you want is selected. |
| 82 | + |
| 83 | + |
| 84 | + |
| 85 | +### Start Debugging |
| 86 | +Once the configuration is set, make sure to set any breakpoints. Then, start up the debugger. Further details on how to use the debugger can be found online. |
| 87 | + |
| 88 | + |
0 commit comments