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

VFS can't find files without packages #267

Closed
spaceman-codes opened this issue May 9, 2019 · 9 comments · Fixed by #270 or #446
Closed

VFS can't find files without packages #267

spaceman-codes opened this issue May 9, 2019 · 9 comments · Fixed by #270 or #446
Assignees
Labels

Comments

@spaceman-codes
Copy link

spaceman-codes commented May 9, 2019

[Ed.: This issue has had a few incarnations now. But basically VFS can fail to resolve assets at the root of the VFS under some REPLs. This is a bug.]


The following error was obtained when I ran the code in iPython without an image file present.

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-1-eca4d86b41c8> in <module>()
     12
     13
---> 14 ppb.run(setup=setup)

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\__init__.py in run(setup, log_level, starting_scene)
     32
     33     with GameEngine(starting_scene, **kwargs) as eng:
---> 34         eng.run()

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\engine.py in run(self)
     77         else:
     78             self.start()
---> 79             self.main_loop()
     80
     81     def start(self):

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\engine.py in main_loop(self)
     91                     self.signal(event)
     92                     while self.events:
---> 93                         self.publish()
     94             self.manage_scene()
     95

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\engine.py in publish(self)
    113         self.__event__(event, self.signal)
    114         for system in self.systems:
--> 115             system.__event__(event, self.signal)
    116         # Required for if we publish with no current scene.
    117         # Should only happen when the last scene stops via event.

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\events.py in __event__(self, bag, fire_event)
     74             try:
     75                 elog.debug(f"Calling handler {meth} for {name}")
---> 76                 meth(bag, fire_event)
     77             except TypeError as ex:
     78                 from inspect import signature

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\systems\__init__.py in on_render(self, render_event, signal)
     61
     62         for game_object in render_event.scene:
---> 63             resource = self.prepare_resource(game_object)
     64             if resource is None:
     65                 continue

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\systems\__init__.py in prepare_resource(self, game_object)
     76             return None
     77         if image_name not in self.resources:
---> 78             self.register_renderable(game_object)
     79
     80         source_image = self.resources[game_object.image]

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\systems\__init__.py in register_renderable(self, renderable)
    105     def register_renderable(self, renderable):
    106         image_name = renderable.__image__()
--> 107         source_path = renderable.__resource_path__()
    108         self.register(source_path / image_name, image_name)
    109

~\AppData\Local\Continuum\anaconda3\lib\site-packages\ppb\sprites.py in __resource_path__(self)
    237     def __resource_path__(self):
    238         if self.resource_path is None:
--> 239             self.resource_path = Path(realpath(getfile(type(self)))).absolute().parent
    240         return self.resource_path

~\AppData\Local\Continuum\anaconda3\lib\inspect.py in getfile(object)
    651             if getattr(object, '__file__', None):
    652                 return object.__file__
--> 653         raise TypeError('{!r} is a built-in class'.format(object))
    654     if ismethod(object):
    655         object = object.__func__

TypeError: <module '__main__'> is a built-in class

@AstraLuma
Copy link
Member

Can you also post some code that'll reproduce the issue? I'm not sure how type(self) can produce the module __main__.

@pathunstrom
Copy link
Collaborator

He copied the code into iPython and hit enter. This is what was spit out. It's a weird context, but probably a good one to consider going forward.

@AstraLuma
Copy link
Member

What code?

@pathunstrom
Copy link
Collaborator

Oh, right, the 15 line demo in the readme.

@AstraLuma
Copy link
Member

Ok, yup, trivial reproduction. Gonna dig in.

@AstraLuma AstraLuma self-assigned this May 14, 2019
@AstraLuma
Copy link
Member

AstraLuma commented May 14, 2019

Ahhhhhhhhhh.

IPython's __main__ does not have a __file__ property, so inspect assumes it's a built-in. This is also true of the built-in REPL.

I think the fix is to add a check in __resource_path__() for __name__ == "__main__".

@pathunstrom
Copy link
Collaborator

My gut instinct was somewhere in the resource path plumbing, glad to know I'm still good at this.

bors bot added a commit that referenced this issue May 16, 2019
270: Fix Resource Paths in REPL r=pathunstrom a=astronouth7303

Fix the crashing bug when running PPB in a REPL by using the CWD when the module is `__main__`.

Closes #267.

Co-authored-by: Jamie Bliss <jamie@ivyleav.es>
Co-authored-by: Piper Thunstrom <pathunstrom@gmail.com>
@bors bors bot closed this as completed in #270 May 16, 2019
@AstraLuma
Copy link
Member

AstraLuma commented Mar 10, 2020

This seems to have come back after the VFS rewrite? I just stumbled into it again.

@AstraLuma AstraLuma reopened this Mar 10, 2020
@pathunstrom
Copy link
Collaborator

We saw this work recently, I think it's been fixed and can be closed?

@AstraLuma AstraLuma changed the title TypeError: <module '__main__'> is a built-in class VFS can't find files without packages Apr 18, 2020
bors bot added a commit that referenced this issue May 9, 2020
446: vfs: Handle if __main__ has no __file__ r=pathunstrom a=astronouth7303

Closes #267
Closes #437

Co-authored-by: Jamie Bliss <jamie@ivyleav.es>
Co-authored-by: Piper Thunstrom <pathunstrom@gmail.com>
@bors bors bot closed this as completed in 63112d0 May 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants