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

extension implementation load path problems in apps #5315

Closed
bryevdv opened this issue Oct 5, 2016 · 3 comments · Fixed by #5425
Closed

extension implementation load path problems in apps #5315

bryevdv opened this issue Oct 5, 2016 · 3 comments · Fixed by #5425

Comments

@bryevdv
Copy link
Member

bryevdv commented Oct 5, 2016

see ref: #5304

@bryevdv
Copy link
Member Author

bryevdv commented Oct 24, 2016

@mattpap I believe the root cause of this has to do with the cwd is set when the app is run. It works for "directory style" apps, but I am fairly certain it does not work well with single file apps.

@mattpap
Copy link
Contributor

mattpap commented Oct 24, 2016

@bryevdv, it's "directory style" apps that don't work in particular and the problem is in cwd (and some other factors, including Python's simplicty).

In CodeRunner.run() we have the following code:

os.chdir(dirname(self._path))
sys.path.insert(0, '')

This makes manual setting of __imlementation__ work, but not logic in custom module compiler. The reason is the custom models are resolved at later time, when those two lines aren't in effect anymore, and because Python graciously resolves module paths as relative if a module is run from the current directory and it's path is on sys.path (both conditions are met here) and as absolute otherwise. Don't know why anyone would invent such a thing, besides making things aesthetically pleasing, but this was fixed in 3.4. The only non-obtrusive solution I found, is to replace those two lines with:

sys.path.insert(0, os.path.dirname(self._path))

where self._path is already absolute. This makes both:

__implementation__ = open(join(dirname(__file__), "surface3d.coffee")).read()

and

__implementation__ = "surface3d.coffee"

work at the same time. Obviously current directory is now set to wherever bin/bokeh was run from. I didn't yet fully analyzed this, but this may not have any negative effect, because we uniformly used __file__ to derive location of auxiliary files.

@bryevdv
Copy link
Member Author

bryevdv commented Dec 7, 2016

Migration note: we will no longer os.chdir into app directories, but __file__ will have correct path that can be used with open, etc. (which we already demonstrate, but let's underscore this more)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment