When testing with PyOxidizer, which doesnt set __file__, as it is not sensible in that context and also it is not a mandatory module property, ruamel.yaml fails many of its tests (104) because main.py attempts to load official modules using __file__.
The easy fix is to make it optional, and dont allow plugins (i.e. the jinja2 plugin), in that context.
The better fix is to find the list of ruamel.yaml.* packages using other mechanisms that are now part of Python, especially importlib.metadata and importlib.resources, both of which have backports.
In order to avoid backports, perhaps mix strategies by using __file__ if present, or fallback to using importlib.
(originally posted on 2019-11-04 at 04:40:03 by John Vandenberg <John Vandenberg@bitbucket>)
None
(originally posted on 2019-11-04 at 04:43:26 by John Vandenberg <John Vandenberg@bitbucket>)
Hello, I am seeing this same issue with PyOxidizer with my command-line application
jc: https://github.com/kellyjonbrazil/jcA user reported that the YAML parser (using ruamel.yaml) is not working with the PyOxidizer binary:
For this test
I get this error
The pypi install is fine which is why I think it's a packaging bug - not a bug in jc as such.
But I'm happy to open an issue on the jc project if you prefer.
I'm not sure how you would fix it since ruamel.yaml does this
Last edit: Kelly Brazil 2021-02-19
Hi there,
I just wanted to bump this issue since it is user impacting and if it happens to be an easy fix I'd like to re-package my application so it will have full functionality.
Thanks in advance,
Kelly
It is an easy fix if the packaging doesn't need the plug-ins. In that case it is a question of catching the NameError and returning the empty list. It is scheduled for 0.17.0.
Until then you can of course do something like:
before instantiating
YAML()Last edit: Anthon van der Neut 2021-03-05
Hi Anthon,
Thanks for the workaround - I'll try that out!
Hi Anthon - looks like that worked. Thanks for your help!
If you ever need to include one of the plug-ins, e.g.
jinja2then you can do:assuming that you package the plug-in as well.
Diff:
This is solved in 0.17 by catching the
NameErrorthat accessing__file__throws.This works out of the box if no plug-ins are necessary. If plugins are bundled in the oxidized executable, than
YAML.official_plug_insmust be monkey patched with a lambda that gives the correct list for the bundled plugins sub-paths.