Skip to content

Commit

Permalink
examples/snippets: fix error in case .pyc files of snippets are prese…
Browse files Browse the repository at this point in the history
…nt. Fixes #35

The code assumed that module.__file__ points to the source, but it
points to the .pyc file in case it exists. Use inspect.getsource()
instead.
  • Loading branch information
lazka committed May 4, 2017
1 parent 7f052bd commit 4ddad64
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions examples/cairo_snippets/snippets/__init__.py
@@ -1,4 +1,5 @@
import os
import inspect
import importlib


Expand Down Expand Up @@ -30,7 +31,9 @@ def get_snippets():
s.name = name
mod = importlib.import_module("." + name, __package__)
s.draw_func = getattr(mod, "draw")
with open(mod.__file__, "rb") as h:
s.code = h.read().decode("utf-8")
code = inspect.getsource(mod)
if isinstance(code, bytes):
code = code.decode("utf-8")
s.code = code
snippets[s.name] = s
return snippets

0 comments on commit 4ddad64

Please sign in to comment.