pythonqt icon indicating copy to clipboard operation
pythonqt copied to clipboard

Handling with pyc files ignores standard python flags

Open kreuzberger opened this issue 4 years ago • 1 comments

Hi! During development we added the -B (DontWriteByteCode) and the environment variables for that to our execution. PythonQt seems to ignore those flags in PythonQtImporter and writes/loads the pyc files directly.

I think the writing of pyc files NOT in pycache has historical py2 reasons, but could the flag be evaluated in PythonQtImporter? There is a function to load with standard python loader in PythonQt.h, but i seems too different to the "reqular" parseFile Method and is not referenced by the interface to evaluate it.

Could handling of this flag be integrated? Or a PythonQt specific Flag would be also ok? Second would be better to have "normal" python behaviour of writing cache files only for imported files/modules and not during call of evalFile

kreuzberger avatar Mar 12 '21 06:03 kreuzberger

Yes, feel free to provide a merge request for this.

In our own projects, we stopped using the PythonQtImporter mechanism, because the Python 3 importers have changed so much and we did not want to reimplement all features of the default python importer again and again. We originally did the custom importer to support crypted Python files.

So I would actually recommend switching to parseFileWithPythonLoaders

and to not enable the custom PythonQtImporter anymore. This will give you default Python 3 imports with all flags and caching.

We could also introduce a PythonQt init flag to enable usage of parseFileWithPythonLoaders instead wherever files are loaded (or introduce a flag in those methods, whatever is easier).

I will not have time for this in the near future, so a merge request for this would also be welcome!

On Fri 12. Mar 2021 at 07:04, Jörg Kreuzberger @.***> wrote:

Hi! During development we added the -B (DontWriteByteCode) and the environment variables for that to our execution. PythonQt seems to ignore those flags in den PythonQtImporter and writes/loads the pyc files directly.

I think the writing of pyc files NOT in pycache has historical reasons, but could the flag be evaluated in PythonQtImporter? There is a function to load with standard python loader in PythonQt.h, but i seems too different to the "reqular" parseFile Method and is not referenced by the interface to evaluate it.

Could handling of this flag be integrated?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/MeVisLab/pythonqt/issues/41, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKHPHGGUWT6AZGBO5NFN6DTDGVGVANCNFSM4ZBUV5UA .

florianlink avatar Mar 12 '21 08:03 florianlink