moderngl / moderngl-window

A cross platform utility library for ModernGL making window creation and resource loading simple
MIT License
244 stars 57 forks source link

Pathlib issue with python 3.6 #31

Closed francoisruty closed 5 years ago

francoisruty commented 5 years ago

model = WindowConfig.load_scene("/input/uv.obj") Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.6/dist-packages/moderngl_window/context/base/window.py", line 673, in load_scene **kwargs, File "/usr/local/lib/python3.6/dist-packages/moderngl_window/resources/scenes.py", line 18, in load return super().load(meta) File "/usr/local/lib/python3.6/dist-packages/moderngl_window/resources/base.py", line 46, in load self.resolve_loader(meta) File "/usr/local/lib/python3.6/dist-packages/moderngl_window/resources/base.py", line 97, in resolve_loader if loader_cls.supports_file(meta): File "/usr/local/lib/python3.6/dist-packages/moderngl_window/loaders/base.py", line 34, in supports_file path = Path(meta.path) File "/usr/lib/python3.6/pathlib.py", line 1001, in new self = cls._from_parts(args, init=False) File "/usr/lib/python3.6/pathlib.py", line 656, in _from_parts drv, root, parts = self._parse_args(args) File "/usr/lib/python3.6/pathlib.py", line 640, in _parse_args a = os.fspath(a) TypeError: expected str, bytes or os.PathLike object, not type

einarf commented 5 years ago

Think that is fixed in master already, but I'll take a look just in case.

francoisruty commented 5 years ago

cool, many thanks! Do you know when will the next release come out?

einarf commented 5 years ago

Hopefully today. Worst case tomorow. I'll close this issue when the release is out

einarf commented 5 years ago

This looks suspicious. That method is not a static or classmethod. I'm guessing /input/uv.obj will be interpreted as the self argument while the path argument is not properly set.

model = WindowConfig.load_scene("/input/uv.obj")

If you don't use a WindowConfig instance you need to go thought the resources module. I'm still working on docs for that.

from moderngl_window import resources
from moderngl_window.meta import SceneDescription

scene = resources.scenes.load(SceneDescription(path='scenes/crate.obj'))

The load_scene implementation in WindowConfig is probably also a good reference.

If you created your own window and context, also make sure you register it.

moderngl_window.activate_context(ctx=my_moderngl_contect)

And of course also register a search path for your resources

from moderngl_window import resources
resources.register_dir('this/is/where/my/data/is')
resources.register_dir('another/location')

.. because all paths sent to the resource system are relative to one or multiple search paths.

francoisruty commented 5 years ago

Thanks, so here is what happened.

I was trying to get the example in https://github.com/moderngl/moderngl/blob/master/examples/loading_obj_files.py working. I'm working on a test script so I didn't want the multiple imbricated classes, that's why I didn't have the self argument.

The problem was indeed that:

Many thanks for your help!

einarf commented 5 years ago

Awsome. Will be more docs very soon. That is pretty much pri 1 at the moment 😄

einarf commented 5 years ago

Finally added a section about it here : https://moderngl-window.readthedocs.io/en/latest/guide/custom_usage.html

Be free to yell if you see improvements.