Use Python script as external tool in IntelliJ IDEA

1.6k Views Asked by At

I'm using IntelliJ IDEA 14 Ultimate and I'd like to run a Python script (in a Tomcat server) from within the IDE.

I did it on Windows but it's not cross platform and I think it's a trick...

This is what I did:

  • I defined C:\Python27\python.exe as Program
  • I added my script as a parameter : initDB.py

Screenshot: New external tools

It works well on Windows but I have to redefine this path on my other computers and my collaborators must do it too.

So my question is: can I use a Python script as an external tool without specifying my script as a parameter?

Thanks for the help.

1

There are 1 best solutions below

2
On BEST ANSWER

There are a few things you can do to improve the situation a bit.

As described in Single script to run in both Windows batch and Linux Bash?, it is possible to create a single script that you can run as a Windows batch file and as a Linux bash file. You could for example create a file /Freek/Scripts/initDB.cmd with the following contents:

:; /usr/bin/python initDB.py; exit $?
C:\Programs\Python27\python.exe initDB.py

The definition of you external tool is stored in a well readable xml file. For example, on my Windows laptop it is in the file C:\Users\Freek\.IdeaIC15\config\tools\External Tools.xml, which contains:

<toolSet name="External Tools">
  <tool name="Test (Python)" description="Simple Python script" showInMainMenu="true"
        showInEditor="true" showInProject="true" showInSearchPopup="true" disabled="false"
        useConsole="true" showConsoleOnStdOut="false" showConsoleOnStdErr="false"
        synchronizeAfterRun="true">
    <exec>
      <option name="COMMAND" value="/Freek/Scripts/initDB.cmd" />
      <option name="PARAMETERS" />
      <option name="WORKING_DIRECTORY" value="/Freek/Scripts" />
    </exec>
  </tool>
</toolSet>

This file could be (partially) copied from one machine to another and does not contain any platform dependencies if you can decide on a common directory/link for all operating systems (like /Freek/Scripts, which also works on Windows).