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

Normalize main script path in st.switch_page and st.page_link #8103

Merged
merged 4 commits into from Feb 8, 2024

Conversation

kajarenc
Copy link
Collaborator

@kajarenc kajarenc commented Feb 7, 2024

Describe your changes

Normalize the main path before using it in st.page_link and st.switch_page.
Close: #8070

GitHub Issue Link (if applicable)

Testing Plan

  • Explanation of why no additional tests are needed
  • Unit Tests (JS and/or Python)
  • E2E Tests
  • Any manual testing needed?

Contribution License Agreement

By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-kjavadyan sfc-gh-kjavadyan marked this pull request as ready for review February 7, 2024 17:09
@sfc-gh-kjavadyan sfc-gh-kjavadyan changed the title normalize main script path before Normalize main script path in st.switch_page and st.page_link Feb 7, 2024
@@ -139,6 +139,7 @@ def switch_page(page: str) -> NoReturn: # type: ignore[misc]
raise NoSessionContext()

main_script_path = os.path.join(os.getcwd(), ctx.main_script_path)
main_script_path = os.path.normpath(main_script_path)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just throwing a couple thoughts to consider before merging.

  1. The problem is the script path is not our desired state, shouldn't we just do os.path.normpath(ctx.main_script_path) instead of normpath the whole thing? I guess it's the same outcome, but perhaps we are specifically identifying the problem.
  2. Should we actually be normalizing this at the very beginning on load, so that we can assume the main script path is set correctly (and avoid this issue again).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I also thinking about this (normalizing main_script_path in context, and not on individual elements level, although here tried to keep changes as small as possible for the fix to not break something else unintentionally).

Absolutely agree it is worth doing!
I am happy to volunteer for that, just want to do it after this merge more carefully to potential side effects.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree. I think I would do (1) narrow this more to the specific issue (the fact that the ctx.main_script_path needs to be normpath).

We can then consider expanding to my question for (2)

Copy link
Collaborator

@LukasMasuch LukasMasuch left a comment

Choose a reason for hiding this comment

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

LGTM 👍 Might be good to check this on a windows computer. I don't have one around right now, but could potentially do it later at home.

@sfc-gh-kjavadyan sfc-gh-kjavadyan merged commit 5c1a8f9 into develop Feb 8, 2024
38 checks passed
@sfc-gh-kjavadyan sfc-gh-kjavadyan deleted the attempt-to-fix-8070 branch February 8, 2024 19:47
zyxue pushed a commit to zyxue/streamlit that referenced this pull request Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants