Skip to content

Andrew/372 check paths #382

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Andrew/372 check paths #382

wants to merge 8 commits into from

Conversation

ayjayt
Copy link
Collaborator

@ayjayt ayjayt commented Aug 12, 2025

solves #372

@emilykl emilykl self-requested a review August 12, 2025 18:18
@gvwilson gvwilson added community community contribution fix fixes something broken P1 needs immediate attention labels Aug 13, 2025
@ayjayt
Copy link
Collaborator Author

ayjayt commented Aug 13, 2025

#372

@@ -10,6 +13,14 @@
KJS_PATH = Path(__file__).resolve().parent / "vendor" / "kaleido_scopes.js"


def _ensure_path(path: Path | str):
_logger.debug(f"Ensuring path {path!s}")
if not urlparse(str(path)).scheme.startswith("file"): # is url
Copy link
Collaborator

@emilykl emilykl Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, this logic as written doesn't actually resolve the issue in #372. AFAIK the plotly argument isn't required to start with "file://", so it can just be a "bare" path starting with e.g. "/Users/..." (on Mac). In that case, this if resolves to True and the function returns without error, even when the file doesn't actually exist.

This suggestion fixes that problem (assuming it's an OK assumption that the only things we consider URLs are paths which start with http or https).

Suggested change
if not urlparse(str(path)).scheme.startswith("file"): # is url
if urlparse(str(path)).scheme.startswith("http"): # is url

if not urlparse(str(path)).scheme.startswith("file"): # is url
return
if not Path(path).exists():
raise ValueError(f"{path!s} does not seem to be a valid path.")
Copy link
Collaborator

@emilykl emilykl Aug 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

more assertive wording

and more specific exception type

Suggested change
raise ValueError(f"{path!s} does not seem to be a valid path.")
raise FileNotFoundError(f"{path!s} does not exist.")

force_cdn: (default False) Don't use plotly import, use CDN
plotly: The url to the plotly.js to use. Defaults to plotly.js
present in plotly.py, if installed. Otherwise fallback to
global constant.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you edit this docstring to describe where to find these global constants? to help someone who might be trying to debug

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(not highest priority just trying to think about how to make these docstrings slightly less opaque)

Copy link
Collaborator

@emilykl emilykl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments otherwise looks good

@@ -10,6 +13,14 @@
KJS_PATH = Path(__file__).resolve().parent / "vendor" / "kaleido_scopes.js"


def _ensure_path(path: Path | str):
_logger.debug(f"Ensuring path {path!s}")
if not urlparse(str(path)).scheme.startswith("file"): # is url
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or perhaps this?

Suggested change
if not urlparse(str(path)).scheme.startswith("file"): # is url
path_scheme = urlparse(str(path)).scheme
if path_scheme not in {"", "file"}: # is url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community community contribution fix fixes something broken P1 needs immediate attention
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Kaleido does not raise exception when plotlyjs path argument is a nonexistent file
3 participants