Strange import behaviour: from vapory import * doesn't work
JohnCC330 opened this issue · 4 comments
I first installed vapory through pip, then downloaded the git zip and installed by hand. Same experience. The code below works, but if I replace the import with import *
, not even the set_trace()
gets called (first line in main()
).
A quick look at the vapory code didn't reveal anything obvious. Am I missing something?
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# vapory_demo.py
from vapory import Camera, LightSource, Sphere, Scene, Texture, Pigment
import pdb
def main(args):
pdb.set_trace()
camera = Camera( 'location', [0,2,-3], 'look_at', [0,1,2] )
light = LightSource( [2,4,-3], 'color', [1,1,1] )
sphere = Sphere( [0,1,2], 2, Texture( Pigment( 'color', [1,0,1] )))
scene = Scene( camera, objects= [light, sphere])
scene.render("purple_sphere.png", width=400, height=300)
print("rendered")
return 0
if __name__ == '__main__':
import sys
sys.exit(main(sys.argv))
Update: I traced the behaviour to the if __name__ == '__main__':
statement. If I remove the if
(and un-indent the following 2 lines, all is well. Like this:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from vapory import *
def main(args):
camera = Camera( 'location', [0,2,-3], 'look_at', [0,1,2] )
light = LightSource( [2,4,-3], 'color', [1,1,1] )
sphere = Sphere( [0,1,2], 2, Texture( Pigment( 'color', [1,0,1] )))
scene = Scene( camera, objects= [light, sphere])
scene.render("purple_sphere.png", width = 800, height = 600)
import sys
sys.exit(main(sys.argv))
It seems __name__
has been changed to vapory
in the module!
This is because vapory/__init__.py defines all, and it includes all the dunder names. It should exclude those lines. Change the definition to this:
__all__ = [k for k in locals().keys() if k not in
['webbrowser',
'deepcopy',
'wikiref',
'vectorize',
'format_if_necessary']
and not k.startswith("_")]
Oops, except __all__ is already gone in GitHub. Need a new release.
Thanks, nedbat!
Removing the entire __all__
statement from __init__.py
solved the issue