Jump to content
  • How to use an external editor to edit IronPython scripts - with autocomplete and syntax checking


    This page describes how to set up editors so that they support autocomplete for the Spotfire API, hence making script development a much simpler proposition.

    Introduction

    The editor that Spotfire provides for IronPython scripts has limited capabilities - it's fine when writing short scripts, but things become tricky when writing anything substantial. In a perfect world, the Spotfire editor would provide full IDE features such as debugging, linting, autocomplete etc. In the absence of such capabilities, it is possible to use an external editor when working on scripts and then copy/paste the script between the editor and Spotfire. This page describes how to set up editors so that they support autocomplete for the Spotfire API, hence making script development a much simpler proposition.

    converted-file.gif.a5a1449cd2558f71e4f8565670aefa8a.gif

    Setting up Atom

    Atom is a popular open source editor/IDE, with a wealth of 'Packages' available that extend its capabilities - including Python autocomplete, linting etc. These instructions are for a specific set of packages, but be aware that others are available and you should be able to configure them in similar ways:

    • Download and install Python (see note on versions) from https://www.python.org/downloads/ - Python is used to support the autocomplete and linting features in the editor. You need regular Python rather than IronPython because the tools rely on Python - don't worry, Python syntax is compatible with IronPython used by Spotfire.
    • Download and install Atom from https://atom.io/
    • Download the correct set of stubs from this page. Unzip them to a folder on your machine (in the example I've unzipped to c:spotfire-stubs).
    • Run Atom.
    • Within Atom, install the 'autocomplete-python' package - this package will use our 'stubs' to support autocomplete.
    • Within Atom, install the 'linter-pylint' package - this will support 'linting' to highlight potential errors in the code. 
    • Configure the autocomplete-python package with both the path to the Python executable (unless you've added it to the PATH) and the location of your stubs (in the 'Extra Paths For Packages' setting).
    • Create a new file with the '.py' extension.
    • Autocomplete should now work - if there are problems, first make sure that autocomplete is working for regular Python syntax (failure likely indicates that the path is missing in the settings), then make sure that the stubs are configured correctly in the Extra Paths setting.

    converted-file.png.54d3fff8433f6ea79059d17fab79e1fa.png

    Setting up Visual Studio Code

    Visual Studio Code is Microsoft's free lightweight IDE with a wealth of 'Packages' available that extend its capabilities - including Python autocomplete, linting etc. These instructions are for a specific set of packages, but be aware that others are available and you should be able to configure them in similar ways:

    • Download and install Python (see note on versions) from https://www.python.org/downloads/ - Python is used to support the autocomplete and linting features in the editor. You need regular Python rather than IronPython because the tools rely on Python - don't worry, Python syntax is compatible with IronPython used by Spotfire.
    • Download and install Visual Studio Code from https://code.visualstudio.com/
    • Download the correct set of stubs from this page. Unzip them to a folder on your machine (in the example I've unzipped to c:spotfire-stubs).
    • Run Visual Studio Code.
    • Within Code, install language support for Python.
    • Edit your user settings to configure the path to the Python executable (unless you've added it to the PATH) and the location of your stubs. You can do this by adding user settings similar to those below (note that the settings are stored in a JavaScript file, hence '' needs to be escaped as ''
    • Create a new file with the '.py' extension.
    • Autocomplete should now work - if there are problems, first make sure that autocomplete is working for regular Python syntax (failure likely indicates that the path is missing in the settings), then make sure that the stubs are configured correctly in the extraPaths setting.
    {
        "python.pythonPath": "C:Python27python",
        "python.autoComplete.extraPaths": ["C:spotfire-stubs"]
    }
     

    A note on Python versions

    You should download and install a version of Python that is compatible with the version of IronPython you're using within Spotfire. Spotfire has historically used IronPython version 2.0.2. Spotfire 7.11 added support for 2.7.7. The most recent versions of Spotfire support IronPython 3.4. In theory, Python 2 syntax is compatible with all minor versions so you should be able to use Python version 2.7 for all your editing. But I'm no expert, so you may want to use 2.0 to be on the safe side when working with older versions of Spotfire.

    Stubs - what are they? How do I get them?

    "Stubs" are Python files that mimic the Spotfire libraries in order to support autocomplete. Python loads these stubs, sees classes, methods, properties, etc. that match those within the Spotfire libraries, allowing the editor to support Spotfire syntax. You can download various stubs from this page - use the version that matches your version of Spotfire. Stubs are generated using a tool that runs within IronPython - see https://github.com/pete-thompson/spotfire-python-stubs for more information or to create your own stubs.

    Caveat

    The stubs are generated by reverse engineering all the publicly visible classes within a Spotfire distribution - which means there are classes, methods, etc. included that are not part of the supported Spotfire API. Always ensure that you use supported API calls, or you run the risk of the code not working with future Spotfire releases.
     

    spotfire-stubs_-_7.10.zip


    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...