-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Model Editor Bug Fixes #2901
base: release_6.0.1
Are you sure you want to change the base?
Model Editor Bug Fixes #2901
Conversation
…model file before approving it; condense into checkModel method
…o checkModel in previous commit
…with C code. Clear highlights from both python and C windows if checks pass. Ensure that checkModel() is always passed a path argument instead of raw text.
… by removing os.remove(). allow user to load .c models into editor even if .c file fails model checks
…l-editor-bug-fixes
Converting back to draft until 6.0.0 bug fix branch is created |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally, this almost does what it says it does, but I'm not 100% certain this fixes #1633.
If params are in the model text, but not defined in the param table, an error is displayed, but the model file is stil generated. This causes issues when correcting the model if the overwrite option is not selected. I'm not sure if this is the expected behavior or not. @rozyczko, what do you think?
Please note - I am planning to fix the issues I've found here. |
…arams in the model editor window
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally, this almost does what it says it does, but I'm not 100% certain this fixes #1633.
This fixes the issue.
If params are in the model text, but not defined in the param table, an error is displayed, but the model file is stil generated. This causes issues when correcting the model if the overwrite option is not selected. I'm not sure if this is the expected behavior or not.
This is a bigger fix than expected and should not hold up this PR. Many of the underlying checks require the file to exist, so I think this is ready.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks okay. I didn't test functionality.
for line in reversed(all_lines): | ||
if 'File' in line and 'line' in line: | ||
reversed_error_text = list(reversed(all_lines)) | ||
for line in reversed_error_text: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better to use iterator form for line in reversed(all_lines)
rather than turning it into a list that you are just going to throw away.
If you do need to assign an iterator to a variable, wrapping it in a tuple is a good defensive practice. Too often I've tried to reuse a sequence only to find that it empty the second time I traverse it. Tuples are immutable and slightly faster.
if 'File' in line and 'line' in line: | ||
reversed_error_text = list(reversed(all_lines)) | ||
for line in reversed_error_text: | ||
if ('File' in line and 'line' in line): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing compiler error messages feels brittle. Maybe a regexp with r"[Ff]ile.*[Ll]ine ([0-9]+)" will be a little more future proof?
# make sure we have the file handle ready | ||
assert(filename != "") | ||
assert filename != "" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The python "optimizer" suppresses assert statements so technically we shouldn't rely on it for flow control. In practice we never run with the optimizer so not a problem. In this case we would fail on self.writeFile with a missing filename so even less of an issue.
full_path = os.path.join(plugin_location, filename) | ||
if not w.is_python and self.is_python: | ||
pass | ||
elif os.path.splitext(full_path)[1] != ".py": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No idea where filename
is coming from, but if it is model.c
and the code is python would you want this saved as model.c.py
? This will likely cause problems for the loader.
You ought to check that filename without extension is a valid python symbol name [with something like Path(filename).stem.isidentifier()
] and replace the extension with .py
for python models.
Shouldn't this happen before self.writeFile()
?
Also, self.writeFile()
must have similar code for path handling. Can you modify that function to return the full path or set it as an attribute?
Within "create new model" tab add a plugin name. The apply button does not become available until you switch to another field. Okay, a little confusing. Now go back into the plugin name field and change it. Clicking apply it is still using the old name, not the name that is typed into the field. You may want to check whether the name already exists or does not pass the |
I see that the box only accepts alphanumeric (and probably underscore but I didn't try). This still allows a name like 2cows. I can't tell if 2cow is working because this branch is throwing the following error when I try to calculate a model (even a sphere model):
|
Changing |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure that the current value displayed in the text box, not the value before the text box was edited, is the one that is used in the new model file. The remaining suggestions are optional.
Description
Fixes minor bugs in the model editor (
PluginDefinition.py
and its parentTabbedModelEditor.py
) that impede usability or cause undesirable effects.PluginDefinition
orModelEditor
(558c7a1, 54a8aaf, 2b71022)ModelEditor
and only model tests were run when usingPluginDefinition
. The syntax checks were done using theast
library, which only checks for SyntaxErrors. I have kept this check as the first one that runs because it can often catch SyntaxErrors with more precision than usingGuiUtils.checkModel()
. In theory we don't need to run theast
check on models generated with the plugin editor, but it doesn't seem to add significant overhead and could even be useful if future changes break the model template.How Has This Been Tested?
Verified correct behavior in SasView and checked wide variety of possible user inputs to search for additional bugs. Windows installer tested and verified.
Review Checklist:
Documentation (check at least one)
Installers
Licensing (untick if necessary)