indygreg/PyOxidizer

pyoxidizer path_hook errors when loading filesystem paths

bloodearnest opened this issue · 1 comments

tldr

OxidizedFinder.path_hook errors when being called on a Windows filesystem path directly. This use case works for regular python sys.path_hooks.

more info

I have a pyoxidizer generated windows executable that is running a django application. Because django is as django does, it relies on being on the filesystem. So I have configured pyoxidizer like so:

policy.resources_location = "filesystem-relative:lib"

This works, and django starts up without issue, and everything can be imported, __file__/__path__ work as advertised.

However, when it then serves a request, it lazily loads django's templating engine, which includes scanning for template tags amongst installed packages, via pkgutils.walk_packages, which ends up iterating through sys.path_hooks (which only contains the pyoxidizer hook), and calls the oxidizer path hook with the file path like so:

oxidized_importer.OxidizedFinder.path_hook('C:\\Users\\ME\\pyox-project\\build\\x86_64-pc-windows-msvc\\release\\install\\pyox-project\\lib\\$PACKAGE\\templatetags'])

i.e. on the filesystem-relative path.

It returns an error: *** ImportError: error running OxidizedFinder.path_hook

This means django doesn't load the templatetags things generally go down hill.

With normal system python and its sys.path_hooks, this exact same path imports just fine. Running import $PACKAGE works fine too, so I don't think its fundamentally an issue with the specific module files on disk, but maybe something do with pyoxidizer's sys.path_hooks setup when using filesystem-relative resource location?

Ok, I realised this case is probably what python_config.filesystem_importer = True is for, enabling that and stuff loads. Sorry for the noise!