Skip to content
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

PythonPlugin: replace deprecated/removed Eval with Exec #1349

Merged
merged 1 commit into from
Nov 7, 2024

Conversation

andresailer
Copy link
Member

It doesn't matter because we don't care about the result

BEGINRELEASENOTES

  • PythonPlugin: replace deprecated Eval with Exec (root 6.36 need)

ENDRELEASENOTES

It doesn't matter because we don't care about the result
Copy link
Contributor

@MarkusFrankATcernch MarkusFrankATcernch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Andre, conditional compilation is probably better:

#include <RVersion.h>
....
#if ROOT_VERSION_CODE < ROOT_VERSION(6,35,1)
          TPython::Eval(c.second.c_str());
#else
          TPython::Exec(c.second.c_str());
#endif

@andresailer
Copy link
Member Author

The Exec exists and we use it in the different case, so this will always compile.

@MarkusFrankATcernch
Copy link
Contributor

I was doing the same changes yesterday.
Normally there is a subtle difference between Eval and Exec:

  • Eval is in the same variable space (locals, globals)
  • Exec normally is in a fresh variable space and only the global variables are presented.
    Though, at least for me yesterday all tests worked, but I wonder whether on the ROOT side
    this was ever though of....

@andresailer
Copy link
Member Author

Admittedly I just took the advice in the ROOT doc at face value to just use Exec instead of eval. But since we didn't look at the returned value before, it all boils down to

https://github.com/root-project/root/blob/v6-34-00-patches/bindings/tpython/src/TPython.cxx#L465

  PyObject *pyObjectResult =
      PyRun_String(const_cast<char *>(command.str().c_str()), Py_file_input, gMainDict, gMainDict);

and

PyObject *result = PyRun_String(const_cast<char *>(expr), Py_eval_input, gMainDict, gMainDict);

Which is equivalent. The rest of the functions are just treating the output, are they not?

And if we don't compile conditionally we make this change dependent on the DD4hep version, and not the ROOT version behind it. Which is maybe better to spot errors if things turn out to be different in the end?

@MarkusFrankATcernch
Copy link
Contributor

I think it is OK. There is anyhow no other choice.

Copy link

github-actions bot commented Nov 7, 2024

Test Results

   14 files     14 suites   6h 35m 33s ⏱️
  368 tests   368 ✅ 0 💤 0 ❌
2 531 runs  2 531 ✅ 0 💤 0 ❌

Results for commit 31d4a30.

@andresailer
Copy link
Member Author

andresailer commented Nov 7, 2024

Hi @smuzaffar,

Any preference?

@smuzaffar
Copy link

I have no preference. If TPython::Exec works for root 6.30 and above then I am fine with TPython::Exec

@andresailer andresailer merged commit 6c04cd7 into AIDASoft:master Nov 7, 2024
15 checks passed
@andresailer andresailer deleted the dropEval branch November 7, 2024 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants