<h3><ahref="../index.html">Table of Contents</a></h3>
<ul>
<li><aclass="reference internal"href="#">Setting up PyCharm with Evennia</a><ul>
<li><aclass="reference internal"href="#setting-up-the-project-interpreter">Setting up the project interpreter</a></li>
<li><aclass="reference internal"href="#attaching-pycharm-debugger-to-evennia">Attaching PyCharm debugger to Evennia</a></li>
<li><aclass="reference internal"href="#setting-up-an-evennia-run-configuration">Setting up an Evennia run configuration</a></li>
<li><aclass="reference internal"href="#alternative-run-configuration-utilizing-logfiles-as-source-of-data">Alternative run configuration - utilizing logfiles as source of data</a></li>
<h1>Setting up PyCharm with Evennia<aclass="headerlink"href="#setting-up-pycharm-with-evennia"title="Permalink to this headline">¶</a></h1>
<p><aclass="reference external"href="https://www.jetbrains.com/pycharm/">PyCharm</a> is a Python developer’s IDE from Jetbrains available
for Windows, Mac and Linux. It is a commercial product but offer free trials, a scaled-down
community edition and also generous licenses for OSS projects like Evennia.</p>
<blockquote>
<div><p>This page was originally tested on Windows (so use Windows-style path examples), but should work
the same for all platforms.</p>
</div></blockquote>
<p>First, install Evennia on your local machine with [[Getting Started]]. If you’re new to PyCharm,
loading your project is as easy as selecting the <codeclass="docutils literal notranslate"><spanclass="pre">Open</span></code> option when PyCharm starts, and browsing to
your game folder (the one created with <codeclass="docutils literal notranslate"><spanclass="pre">evennia</span><spanclass="pre">--init</span></code>). We refer to it as <codeclass="docutils literal notranslate"><spanclass="pre">mygame</span></code> here.</p>
<p>If you want to be able to examine evennia’s core code or the scripts inside your virtualenv, you’ll
need to add them to your project too:</p>
<olclass="simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">File</span><spanclass="pre">></span><spanclass="pre">Open...</span></code></p></li>
<li><p>Select the folder (i.e. the <codeclass="docutils literal notranslate"><spanclass="pre">evennia</span></code> root)</p></li>
<li><p>Select “Open in current window” and “Add to currently opened projects”</p></li>
</ol>
<sectionid="setting-up-the-project-interpreter">
<h2>Setting up the project interpreter<aclass="headerlink"href="#setting-up-the-project-interpreter"title="Permalink to this headline">¶</a></h2>
<p>It’s a good idea to do this before attempting anything further. The rest of this page assumes your
project is already configured in PyCharm.</p>
<olclass="simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">File</span><spanclass="pre">></span><spanclass="pre">Settings...</span><spanclass="pre">></span><spanclass="pre">Project:</span><spanclass="pre">\<mygame\></span><spanclass="pre">></span><spanclass="pre">Project</span><spanclass="pre">Interpreter</span></code></p></li>
<li><p>Click the Gear symbol <codeclass="docutils literal notranslate"><spanclass="pre">></span><spanclass="pre">Add</span><spanclass="pre">local</span></code></p></li>
<li><p>Navigate to your <codeclass="docutils literal notranslate"><spanclass="pre">evenv/scripts</span><spanclass="pre">directory</span></code>, and select Python.exe</p></li>
</ol>
<p>Enjoy seeing all your imports checked properly, setting breakpoints, and live variable watching!</p>
<h2>Attaching PyCharm debugger to Evennia<aclass="headerlink"href="#attaching-pycharm-debugger-to-evennia"title="Permalink to this headline">¶</a></h2>
<olclass="simple">
<li><p>Launch Evennia in your preferred way (usually from a console/terminal)</p></li>
<li><p>Open your project in PyCharm</p></li>
<li><p>In the PyCharm menu, select <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Attach</span><spanclass="pre">to</span><spanclass="pre">Local</span><spanclass="pre">Process...</span></code></p></li>
<li><p>From the list, pick the <codeclass="docutils literal notranslate"><spanclass="pre">twistd</span></code> process with the <codeclass="docutils literal notranslate"><spanclass="pre">server.py</span></code> parameter (Example: <codeclass="docutils literal notranslate"><spanclass="pre">twistd.exe</span><spanclass="pre">--nodaemon</span><spanclass="pre">--logfile=\<mygame\>\server\logs\server.log</span><spanclass="pre">--python=\<evennia</span><spanclass="pre">repo\>\evennia\server\server.py</span></code>)</p></li>
</ol>
<p>Of course you can attach to the <codeclass="docutils literal notranslate"><spanclass="pre">portal</span></code> process as well. If you want to debug the Evennia launcher
or runner for some reason (or just learn how they work!), see Run Configuration below.</p>
<blockquote>
<div><p>NOTE: Whenever you reload Evennia, the old Server process will die and a new one start. So when
you restart you have to detach from the old and then reattach to the new process that was created.</p>
</div></blockquote>
<blockquote>
<div><p>To make the process less tedious you can apply a filter in settings to show only the <aclass="reference external"href="http://server.py">server.py</a>
process in the list. To do that navigate to: <codeclass="docutils literal notranslate"><spanclass="pre">Settings/Preferences</span><spanclass="pre">|</span><spanclass="pre">Build,</span><spanclass="pre">Execution,</span><spanclass="pre">Deployment</span><spanclass="pre">|</span><spanclass="pre">Python</span><spanclass="pre">Debugger</span></code> and then in <codeclass="docutils literal notranslate"><spanclass="pre">Attach</span><spanclass="pre">to</span><spanclass="pre">process</span></code> field put in: <codeclass="docutils literal notranslate"><spanclass="pre">twistd.exe"</span><spanclass="pre">--nodaemon</span></code>. This is an
example for windows, I don’t have a working mac/linux box.
<imgalt="Example process filter configuration"src="https://i.imgur.com/vkSheR8.png"/></p>
<h2>Setting up an Evennia run configuration<aclass="headerlink"href="#setting-up-an-evennia-run-configuration"title="Permalink to this headline">¶</a></h2>
<p>This configuration allows you to launch Evennia from inside PyCharm. Besides convenience, it also
allows suspending and debugging the evennia_launcher or evennia_runner at points earlier than you
could by running them externally and attaching. In fact by the time the server and/or portal are
running the launcher will have exited already.</p>
<olclass="simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code></p></li>
<li><p>Click the plus-symbol to add a new configuration and choose Python</p></li>
<li><p>Add the script: <codeclass="docutils literal notranslate"><spanclass="pre">\<yourrepo\>\evenv\Scripts\evennia_launcher.py</span></code> (substitute your virtualenv if
it’s not named <codeclass="docutils literal notranslate"><spanclass="pre">evenv</span></code>)</p></li>
<li><p>Ensure the chosen interpreter is from your virtualenv</p></li>
<li><p>Set Working directory to your <codeclass="docutils literal notranslate"><spanclass="pre">mygame</span></code> folder (not evenv nor evennia)</p></li>
<li><p>You can refer to the PyCharm documentation for general info, but you’ll want to set at least a
config name (like “MyMUD start” or similar).</p></li>
</ol>
<p>Now set up a “stop” configuration by following the same steps as above, but set your Script
parameters to: stop (and name the configuration appropriately).</p>
<p>A dropdown box holding your new configurations should appear next to your PyCharm run button.
Select MyMUD start and press the debug icon to begin debugging. Depending on how far you let the
program run, you may need to run your “MyMUD stop” config to actually stop the server, before you’ll
<h2>Alternative run configuration - utilizing logfiles as source of data<aclass="headerlink"href="#alternative-run-configuration-utilizing-logfiles-as-source-of-data"title="Permalink to this headline">¶</a></h2>
<p>This configuration takes a bit different approach as instead of focusing on getting the data back
through logfiles. Reason for that is this way you can easily separate data streams, for example you
rarely want to follow both server and portal at the same time, and this will allow it. This will
also make sure to stop the evennia before starting it, essentially working as reload command (it
will also include instructions how to disable that part of functionality). We will start by defining
a configuration that will stop evennia. This assumes that <codeclass="docutils literal notranslate"><spanclass="pre">upfire</span></code> is your pycharm project name, and
also the game name, hence the <codeclass="docutils literal notranslate"><spanclass="pre">upfire/upfire</span></code> path.</p>
<olclass="simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code>\</p></li>
<li><p>Click the plus-symbol to add a new configuration and choose the python interpreter to use (should
be project default)</p></li>
<li><p>Name the configuration as “stop evennia” and fill rest of the fields accordingly to the image:
<imgalt="Stop run configuration"src="https://i.imgur.com/gbkXhlG.png"/></p></li>
<p>Now we will define the start/reload command that will make sure that evennia is not running already,
and then start the server in one go.</p>
<olclass="simple">
<li><p>Go to <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">></span><spanclass="pre">Edit</span><spanclass="pre">Configutations...</span></code>\</p></li>
<li><p>Click the plus-symbol to add a new configuration and choose the python interpreter to use (should
be project default)</p></li>
<li><p>Name the configuration as “start evennia” and fill rest of the fields accordingly to the image:
<imgalt="Start run configuration"src="https://i.imgur.com/5YEjeHq.png"/></p></li>
<li><p>Navigate to the <codeclass="docutils literal notranslate"><spanclass="pre">Logs</span></code> tab and add the log files you would like to follow. The picture shows
adding <codeclass="docutils literal notranslate"><spanclass="pre">portal.log</span></code> which will show itself in <codeclass="docutils literal notranslate"><spanclass="pre">portal</span></code> tab when running:
<li><p>Skip the following steps if you don’t want the launcher to stop evennia before starting.</p></li>
<li><p>Head back to <codeclass="docutils literal notranslate"><spanclass="pre">Configuration</span></code> tab and press the <codeclass="docutils literal notranslate"><spanclass="pre">+</span></code> sign at the bottom, under <codeclass="docutils literal notranslate"><spanclass="pre">Before</span><spanclass="pre">launch....</span></code>
and select <codeclass="docutils literal notranslate"><spanclass="pre">Run</span><spanclass="pre">another</span><spanclass="pre">configuration</span></code> from the submenu that will pop up.</p></li>
<li><p>Click <codeclass="docutils literal notranslate"><spanclass="pre">stop</span><spanclass="pre">evennia</span></code> and make sure that it’s added to the list like on the image above.</p></li>
<li><p>Click <codeclass="docutils literal notranslate"><spanclass="pre">Apply</span></code> and close the run configuration window.</p></li>
</ol>
<p>You are now ready to go, and if you will fire up <codeclass="docutils literal notranslate"><spanclass="pre">start</span><spanclass="pre">evennia</span></code> configuration you should see
following in the bottom panel:
<imgalt="Example of running alternative configuration"src="https://i.imgur.com/nTfpC04.png"/>
and you can click through the tabs to check appropriate logs, or even the console output as it is