Finally, Ren'Py and PyCharm working together...
I love torturing myself. Or at least I think I do. I just don’t know what it is, but I always find it rather fun and exciting to see where Ren'Py can fit in places it shouldn’t.
I love torturing myself. Or at least I think I do. I just don’t know what it is, but I always find it rather fun and exciting to see where Ren'Py can fit in places it shouldn’t. Back in June, I got it to work with Xcode with no big deal, despite missing proper syntax highlighting and what-not. Working on Ren'Py projects inside of Xcode has been a blast, but I’ve since looked elsewhere to see where I can take the idea. Of course, VS Code made a lot of sense and I managed to get it working without a hitch. There’s already a decent plugin for VS Code with Ren'Py and I made use of code snippets and tasks to create a decent workflow. Although not quite well-suited, it did the job just fine.
So, as of the past few days, I began searching in a rather unexpected place: PyCharm. PyCharm is a popular IDE for Python development by JetBrains, the same company that makes the YouTrack issue tracker I use. It’s no surprise that JetBrains can make really great software since developers like me simply drool at what’s made. Having separate IDEs that work really well for a specific language is just simply amazing; they’ve all different kinds for Java, Swift, Python, and even web development (this post was written in WebStorm)! So, of course I had to try getting Ren'Py projects to work with a really popular Python IDE; it couldn’t be that hard, right?
We don’t have any feature requests for it but perhaps someone could take a stab at a plugin
— JetBrains PyCharm (@pycharm) June 4, 2018
Yeah, it turns out that this wasn’t an easy task compared to Xcode, surprisingly. I asked this a year ago when I started looking into using PyCharm for development (and when I got the student subscription to all of JetBrains’s products). Despite the fact that PyCharm works with Python and Python-based projects really well, Ren'Py is/was left out of the mix. Perhaps it’s due to the fact that Ren'Py is Python 2.7-based and not 3.x, or maybe it’s because of some commercial issue. Regardless, it is a bit of an oddity. A few years ago, someone attempted to make a plugin, but the project hasn’t been updated since; the code is still up on GitHub, however.
Somewhat, it’s finally possible
Fast-forward to 2019, when JetBrains released version 2019.2 of their IDE products, PyCharm included. With some of the features this version includes, I figured out some way to get it working (to an extent). Some of these include:
- Syntax highlighting
- File templates
- Build/run configurations
- Linting
Granted, these methods don’t really hook into PyCharm itself and take advantage of all PyCharm has to offer, but it’s at least a step in the right direction.
Proper syntax highlighting with TextMate bundles
Part of the PyCharm 2019.2 release includes the TextMate bundles plugin by default, which provides the syntax highlighting for files that aren’t Pythonic in nature (I guess?). Because of this, I was able to conjure up a way to get Ren'Py syntax highlighting in PyCharm. It wasn’t quite an easy process, however, because there’s no official (or general) TextMate bundle that has Ren'Py language support.
However, the official package on Atom for the Ren'Py language makes the process a little easier; all I would need to do is convert the grammar file to the TextMate language file and create the bundle myself. Luckily, the grammar file it coded very similarly to how a TextMate grammar file would be. All I needed to do was the following:
- Download the grammmar file from the plugin.
- Convert the grammar file (in CSON) to a JSON file.
- Convert the JSON file to a Property List (Plist).
- Rename the Plist file to a TextMate language file.
- Use TextMate to create the bundle.
And that’s what I did. So that no one has to go through that laborious process like how I did again, I published the code that syncs up with the latest version of the Atom package (2.5.0) on GitHub at alicerunsonfedora/renpy-textmate.
From there, adding the syntax file is as easy as following the instructions JetBrains provides in their support document.
For what it is, the syntax highlighting works as you’d pretty much expect if you’re using Atom or VS Code. While it isn’t as intelligent like as if it were Python, it’s at least a decent start.
Creating external tools
PyCharm also makes it easy to work with external tools for linting and running projects. Since there isn’t quite a way to integrate linters directly into PyCharm (at least from what I know), I created some external tools in my preferences to pull it off. Because I’m on macOS Catalina, pointing to the renpy.sh
file doesn’t work like it should due to some integrity checks, but pointing to the renpy
binary in the app file works well enough. Of course, the paths would have to change depending on where Ren'Py is installed, but it’s something nonetheless.
Below are the screenshots for the configurations of the linter, running the project, and building the games:
Granted, there are probably better ways to do this, but it’s at least a start. Once these are added, I can go to Tools > External Tools > Ren'Py and run the desired tool.
Run configurations
However, there’s that nice run button at the top of the window that would be a lot easier to push than having to go to External Tools. Luckily, I figured out a way to get that to work, too, thanks to the Bash Support plugin. All I needed to do was point to the Ren'Py binary again, add the arguments from the external tool, and I was good to go! I even was able to add the linter as a pre-task before so that it acts like how I set it up in Xcode. Nice!
Again, here’s the screenshot for the setup:
So is it worth it?
After playing around with it for a little bit, I’m still discovering ways to get the integration to be a little tighter. It won’t be as perfect as how PyCharm is with pure Python or anything Python-based like Django or Flask, but it’s at least a start. For one thing, the spell check is pretty handy. It’s also a bit nice that I can work with Python and Ren'Py seamlessly.
Ideally, it’d be nice if there’s a way I can figure these out:
- Letting PyCharm interpret
python
blocks as Python code and use all of the advantages of PyCharm like inline method refactoring. - Better build/run configuration support without an external plugin
- A viewer for
layeredimage
or for effects - Better integration with Ren'Py’s lint tool and PyCharm since PyCharm is pretty good when it comes to PEP.
Still, it’s at least a good step forward to making it work. Who knows? Maybe someone will make a decent plugin that makes all of these steps extraneous or JetBrains will attempt adding Ren'Py to PyCharm itself (or maybe make its own IDE?)…
For now, I’m happy with what I have here. Maybe you might, too.