Ticket #7076 (closed: fixed)
mtd.importAll does not work in the main script window
Reported by: | Martyn Gigg | Owned by: | Martyn Gigg |
---|---|---|---|
Priority: | major | Milestone: | Release 3.0 |
Component: | Python | Keywords: | |
Cc: | Blocked By: | ||
Blocking: | Tester: | Jay Rainey |
Description (last modified by Martyn Gigg) (diff)
Executing mtd.importAll from the main script window gives an error:
IndexError: string index out of range at line 1 in '' caused by line 53 in '/home/dmn58364/Builds/mantid/checker/bin/mantid/api/_adsimports.py' caused by line 1054 in '/usr/lib/python2.7/inspect.py' caused by line 1032 in '/usr/lib/python2.7/inspect.py' caused by line 1007 in '/usr/lib/python2.7/inspect.py' caused by line 528 in '/usr/lib/python2.7/inspect.py'
It works as expected from the command interpreter though.
Change History
comment:4 Changed 7 years ago by Martyn Gigg
- Description modified (diff)
- Milestone changed from Backlog to Release 3.0
comment:5 Changed 7 years ago by Martyn Gigg
- Status changed from new to inprogress
Fix mtd.importAll within Python Script Window
The inspect.stack() call was failing with a fresh tab because the executing code didn't have a valid identifier. For a loaded file it worked because the identifier was automatically set to the filename.
A blank identifier is now not allowed and it uses a default if an empty string is passed in. This also fixes a bug with the file attribute not being updated on save.
Refs #7076
Changeset: 1acd09dcacaf5b9f645587a65e8bdc20c9ab4a69
comment:6 Changed 7 years ago by Martyn Gigg
- Status changed from inprogress to verify
- Resolution set to fixed
Branch: bugfix/7076_importAll_fails_script_window
Tester: The main thing to test here is that mtd.importAll() now works from within the ScriptWindow and still works from within the ScriptInterpreter.
- Start MantidPlot
- Open the Script Window
- Load a workspace and take note of the name you give it
- When it is loaded go to the Script Window (make sure it says "New Script" in the tab title) and type mtd.importAll() and execute the script.
- After finishing execution you should be able to start typing the name of the workspace you just loaded and the autocomplete should appear telling you that the variable has been imported into the current scope.
A by-product of this fix is that the python __file__ is now correctly set/updated when a file is saved. Continuing from above:
- Clear everything typed in the window and type "print file"
- Executing this should produce an error saying that no file attribute exists
- Save the file
- Rerun the script and it should now print the full path to where the file was saved
- Now save the file under another name and run the script again after it has saved. It should print the new path
comment:7 Changed 7 years ago by Jay Rainey
- Status changed from verify to verifying
- Tester set to Jay Rainey
comment:8 Changed 7 years ago by Jay Rainey
- Status changed from verifying to closed
Testing
- Tested both in the ScriptWindow and the ScriptInterpreter. No errors are thrown when executing mtd.importAll() in either. In both cases, auto-completion works as expected.
- __file__ functionality is working correctly.
Code review
- Well commented and tidy code.
comment:9 Changed 7 years ago by Jay Rainey
Merge remote-tracking branch 'origin/bugfix/7076_importAll_fails_script_window'
comment:11 Changed 5 years ago by Stuart Campbell
This ticket has been transferred to github issue 7922
Batch move to 2.7