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

bokeh plot library doesn't work on positron in windows #4397

Closed
jonvanausdeln opened this issue Aug 19, 2024 · 4 comments
Closed

bokeh plot library doesn't work on positron in windows #4397

jonvanausdeln opened this issue Aug 19, 2024 · 4 comments
Assignees
Labels
area: plots Issues related to Plots category. bug Something isn't working lang: python theme: app builder

Comments

@jonvanausdeln
Copy link
Contributor

System details:

Positron and OS details:

Latest daily 2024.08.0-31
Windows 11

Interpreter details:

Python 3.12.2

Describe the issue:

bokeh library works in a python shell outside of Positron, but does not work inside positron using either a file or directly in the console. Looks to be missed in #4118

Steps to reproduce the issue:

Execute sample:

from bokeh.plotting import figure, show
p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2)
show(p)

Results in error output (this one is from a notebook)

{
	"name": "PermissionError",
	"message": "[Errno 13] Permission denied: 'c:\\\\Program Files\\\\Positron\\\\resources\\\\app\\\\extensions\\\\positron-python\\\\python_files\\\\positron\\\\positron_language_server.html'",
	"stack": "---------------------------------------------------------------------------
PermissionError                           Traceback (most recent call last)
Cell In[1], line 4
      2 p = figure(title=\"Simple line example\", x_axis_label='x', y_axis_label='y')
      3 p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label=\"Temp.\", line_width=2)
----> 4 show(p)

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\showing.py:147, in show(obj, browser, new, notebook_handle, notebook_url, **kwargs)
    144 state = curstate()
    146 if isinstance(obj, UIElement):
--> 147     return _show_with_state(obj, state, browser, new, notebook_handle=notebook_handle)
    149 def is_application(obj: Any) -> TypeGuard[Application]:
    150     return getattr(obj, '_is_a_bokeh_application_class', False)

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\showing.py:198, in _show_with_state(obj, state, browser, new, notebook_handle)
    195     shown = True
    197 if state.file or not shown:
--> 198     _show_file_with_state(obj, state, new, controller)
    200 return comms_handle

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\showing.py:179, in _show_file_with_state(obj, state, new, controller)
    175 def _show_file_with_state(obj: UIElement, state: State, new: BrowserTarget, controller: BrowserLike) -> None:
    176     '''
    177 
    178     '''
--> 179     filename = save(obj, state=state)
    180     controller.open(\"file://\" + filename, new=NEW_PARAM[new])

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\saving.py:98, in save(obj, filename, resources, title, template, state)
     95 theme = state.document.theme
     97 filename, resources, title = _get_save_args(state, filename, resources, title)
---> 98 _save_helper(obj, filename, resources, title, template, theme)
     99 return abspath(expanduser(filename))

File ~\\.pyenv\\pyenv-win\\versions\\3.12.2\\Lib\\site-packages\\bokeh\\io\\saving.py:166, in _save_helper(obj, filename, resources, title, template, theme)
    163 from ..embed import file_html
    164 html = file_html(obj, resources=resources, title=title, template=template or FILE, theme=theme)
--> 166 with open(filename, mode=\"w\", encoding=\"utf-8\") as f:
    167     f.write(html)

PermissionError: [Errno 13] Permission denied: 'c:\\\\Program Files\\\\Positron\\\\resources\\\\app\\\\extensions\\\\positron-python\\\\python_files\\\\positron\\\\positron_language_server.html'"
}

Expected or desired behavior:

Plot to show

Were there any error messages in the UI, Output panel, or Developer Tools console?

@jonvanausdeln jonvanausdeln added area: plots Issues related to Plots category. lang: python labels Aug 19, 2024
@juliasilge juliasilge added the bug Something isn't working label Aug 19, 2024
@juliasilge juliasilge added this to the 2024.09.0 Pre-Release milestone Aug 19, 2024
@isabelizimm isabelizimm self-assigned this Aug 26, 2024
isabelizimm added a commit that referenced this issue Aug 28, 2024
<!-- Thank you for submitting a pull request.
If this is your first pull request you can find information about
contributing here:
  * https://github.com/posit-dev/positron/blob/main/CONTRIBUTING.md

We recommend synchronizing your branch with the latest changes in the
main branch by either pulling or rebasing.
-->

<!--
  Describe briefly what problem this pull request resolves, or what
  new feature it introduces. Include screenshots of any new or altered
  UI. Link to any GitHub issues but avoid "magic" keywords that will 
  automatically close the issue. If there are any details about your 
approach that are unintuitive or you want to draw attention to, please
  describe them here.
-->

addresses #4397 

osx wants the url for this file to be in `file://....` format where
windows just wants `c://...`, so making a small check to account for
that!

### QA Notes

<!--
  Add additional information for QA on how to validate the change,
  paying special attention to the level of risk, adjacent areas that
  could be affected by the change, and any important contextual
  information not present in the linked issues.
-->

```python
from bokeh.plotting import figure, show
p = figure(title="Simple line example", x_axis_label='x', y_axis_label='y')
p.line([1, 2, 3, 4, 5], [6, 7, 2, 4, 5], legend_label="Temp.", line_width=2)
show(p)
```

should run without error
@jonvanausdeln
Copy link
Contributor Author

I just checked in 2024.08.0-83 and it's still failing.

image

Note, it works on a dev build (hence why I approved the PR), but not this release build. It still has issues writing to that file location.

@petetronic
Copy link
Collaborator

petetronic commented Aug 29, 2024

@isabelizimm I think we need to consider that this logic is returning False on Windows (perhaps under certain circumstances), leading bokeh to not use a temp file and falling back to the default location of the parent directory of the python process, which is not actually writable to Positron's ipykernel process: https://github.com/bokeh/bokeh/blob/branch-3.6/src/bokeh/io/util.py#L123

@isabelizimm
Copy link
Contributor

isabelizimm commented Aug 29, 2024

Ah, that is probably the root of the problem; bokeh is using os.access(), which is not perfect ⏬

Note: I/O operations may fail even when access() indicates that they would succeed, particularly for operations on network filesystems which may have permissions semantics beyond the usual POSIX permission-bit model. from Python docs

So that always returns True (you can see the file in the positron-python extension after running bokeh examples). We can try/except and handle the exception, or maybe always move that file to the user's current directory and then open it, since that is where it would be generated if you ran from the terminal? (or put it in a tempdir and show it)

isabelizimm added a commit that referenced this issue Sep 5, 2024
re: #4397

patches bokeh to not allow writing files to positron extension

A few other stragglers-- the [Python nightly tests are failing for bokeh
stuff](https://github.com/posit-dev/positron/actions/workflows/positron-python-nightly.yml),
likely due to the fact `bokeh` is not being installed. AND I am turning
the Windows tests back on, they seem to be running on my machine but if
there is other context I'm missing happy to rework tests in a different
way!
@jonvanausdeln
Copy link
Contributor Author

Verified Fixed

Positron Version(s) : 2024.09.0-8
OS Version(s) : Windows 11

Test scenario(s)

bokeh plots now work as expected

Link(s) to TestRail test cases run or created:

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 20, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: plots Issues related to Plots category. bug Something isn't working lang: python theme: app builder
Projects
None yet
Development

No branches or pull requests

5 participants