SasView / sasview

Code for the SasView application.
BSD 3-Clause "New" or "Revised" License
48 stars 41 forks source link

Get rid of exec calls in UI (Trac #371) #506

Open mdoucet opened 5 years ago

mdoucet commented 5 years ago

I noticed that there are a lot of 'exec' calls peppered in the UI code. We should go through and get rid of them.

Migrated from http://trac.sasview.org/ticket/371

{
    "status": "new",
    "changetime": "2015-06-11T01:44:50",
    "_ts": "2015-06-11 01:44:50.039604+00:00",
    "description": "I noticed that there are a lot of 'exec' calls peppered in the UI code.\nWe should go through and get rid of them.",
    "reporter": "mathieu",
    "cc": "",
    "resolution": "",
    "workpackage": "SasView QA and testing",
    "time": "2015-03-05T15:07:43",
    "component": "SasView",
    "summary": "Get rid of exec calls in UI",
    "priority": "major",
    "keywords": "",
    "milestone": "SasView Next Release +1",
    "owner": "",
    "type": "defect"
}
pkienzle commented 5 years ago

Trac update at 2015/06/11 01:44:50: pkienzle changed workpackage from "SasView Bug Fixing" to "SasView QA and testing"

lucas-wilkins commented 1 year ago

Pretty sure they're all gone now, will double check

pkienzle commented 1 year ago

There are some eval() calls that don't need to be:

$ grep "\We\(xec\|val\) *(" sasview/src/**/*.py 
sasview/src/sas/qtgui/Calculators/DataOperationUtilityPanel.py:            output = eval("data1 %s data2" % operator)
sasview/src/sas/qtgui/Perspectives/Fitting/ComplexConstraint.py:            eval(expression_to_evaluate)
sasview/src/sas/qtgui/Perspectives/Fitting/FittingOptions.py:            widget_to_activate = eval(widget_name)
sasview/src/sas/qtgui/Perspectives/Fitting/FittingOptions.py:                line_edit = eval(widget_name)
sasview/src/sas/qtgui/Perspectives/Fitting/FittingOptions.py:        return eval('self.' + option)
sasview/src/sas/qtgui/Perspectives/Fitting/FittingOptions.py:                control = eval(widget_name)
sasview/src/sas/qtgui/Perspectives/Fitting/FittingOptions.py:                eval(widget_name).setText(str(options[option]))
sasview/src/sas/qtgui/Perspectives/Fitting/MultiConstraint.py:            eval(expression_to_evaluate)
sasview/src/sas/qtgui/Utilities/TabbedModelEditor.py:        return msg_box.exec()
sasview/src/sas/qtgui/sasview/sasview.py:        exec(sys.argv[2])
sasview/src/sas/sascalc/fit/AbstractFitEngine.py:    def eval(self, x):
sasview/src/sas/sascalc/fit/AbstractFitEngine.py:        return self.eval(x)
sasview/src/sas/sascalc/fit/BumpsFitting.py:                            pvec.append(eval(err_exp).n)
sasview/src/sas/sascalc/fit/BumpsFitting.py:                            stderr.append(eval(err_exp).s)
sasview/src/sas/sascalc/fit/expression.py:    #exec(functiondef, global_context, local_context)
sasview/src/sas/sascalc/fit/expression.py:    eval(compile(source, location, 'exec'), global_context, local_context)

DataOperationUtilityPanel could use operator.add, etc.

FittingOptions could be using self.get(attribute_name) instead of eval("self."+attribute_name) for attribute lookup.

This still leaves eval for constraint expressions.

lucas-wilkins commented 1 year ago

Yuck.

For DataOperationUtilityPanel, other possibilities are: 1) Write classes representing basic algebraic operations. This is pretty simple and I've done similar things in a lot of contexts. Parsing strings representing them is a bit annoying, but not too hard as long as one sticks to basic operations, +-*/^ and (). 2) Use sympy. It's heavy duty, but it's an option for this kind of thing.

Constraint expressions need a better data structure anyway as I'm told there are issues with multiple constraints.