Skip to content

Error Checking Troubleshooting

John Holt edited this page Feb 12, 2020 · 16 revisions

Scripts are now “linted” on load, which means they are checked for validity against a variety of conditions. This means that more mistakes in the code can be caught before the script is run. The script is linted on load and if there are issues the output from g.load_script will look something like:

W:  2: Found indentation with tabs instead of spaces (mixed-indentation)
E:  4: Unable to import 'my_file_in_inst' (import-error)

Where the initial W: indicates a warning or E: indicates an error and the number is the line number in the script.

If loading a script produces warnings only, it will still be loaded successfully and can be used thereafter, whereas any errors will prevent a script from being loaded altogether.

We do provide the option to disable linting by setting the check_script argument to false, i.e.:

g.load_script(“some_script.py”, check_script=False)

However, doing this is at your own discretion and with the understanding that you are exposing yourself to issues, either immediately or further down the line. We recommend fixing issues in scripts before running it.

We have found that there are some common warnings and errors which we have listed below with suggestions of what might be wrong. If you find something that is not included let us know and we can add it to this page to help others.

Errors

Unable to import 'file_in_inst' (import-error)

This happens when the script contains something like

from file_in_inst import my_function

where file_in_inst is a file in your NDX/Python/inst directory, such as inst_routines This may work at the command line but does not work with the checker/linter. A better way of writing this is

from inst.file_in_inst import my_function

The checker does not know of this special case of allowing inst modules on the command line unprefixed.

Warnings

Found indentation with tabs instead of spaces (mixed-indentation)

Here the script file you are loading contains both spaces and tabs. This can upset the python interpreter although this is usually caught on import; we recommend using spaces for indent.

If you are using Notepad++ as your editor it can be made to use spaces instead of tabs when you press tab. This is done by

  1. Select from the menu bar Settings -> Preferences.
  2. Select Language in the left-hand box
  3. In "Tab Settings" box select "python"
  4. Untick "Use default value" and tick "Replace by space".

** Unused import XXXX from wildcard import (unused-wildcard-import)**

Although wildcard imports are not recommended because of the possibility of name collisions if you want to use it the linter will give you lots of warning about anything you didn't use from the package. To disable these warnings place the following comment on the import line which will suppress these warnings:

from XXXX import *  # pylint: disable=unused-wildcard-import

You will still get a warning about wildcards which is good but not the warning about unused methods.

Clone this wiki locally