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

refactor for toml no null #108

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

Sairam90
Copy link
Contributor

@Sairam90 Sairam90 commented Sep 3, 2024

As we cannot assign None to an attribute in a toml file we must ignore the attribute 'icon' or set it to empty string to account for this
toml-lang/toml#975

Added a fix related to this - check if attr 'icon' is present in page object and if attribution 'icon' is not empty - add it to page title else ignore

@blackary - Could you please have a look - I tried using st-pages==1.0.1 and faced the above issue ; built the lib and used it locally and it works as expected

Copy link
Owner

@blackary blackary left a comment

Choose a reason for hiding this comment

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

Can you please put back all the deleted methods?

pages.append(Section(page["name"], page["icon"])) # type: ignore
pages.append(
Section(page["name"], page["icon"] if hasattr(page, "icon") else None)
) # type: ignore
else:
pages.append(Page(**page)) # type: ignore
Copy link
Owner

Choose a reason for hiding this comment

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

What do you think about handling "icon" here the same way you've handled it in the "if section" block above? That seems like it would nicely handle a lot of the other checks, and could simply default to null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sure, I will work on it tom and get back !

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have made the changes to set icon to None when initializing here but I think the string null check has to be done separately when setting the page title and section names.

Let me know if that looks good!

Natarajan Sairam and others added 2 commits September 4, 2024 07:22
@blackary
Copy link
Owner

blackary commented Sep 4, 2024

I'm taking a look more at your solution, but I'm also struggling to understand exactly what the issues is -- if you simply leave the icon missing, it works fine as-is -- you can see the example with the example_three.py page here https://github.com/blackary/st_pages/blob/main/example_app/.streamlit/pages.toml#L17

You can see the result at https://st-pages.streamlit.app/
image

Is there some different behavior you're trying to support?

@Sairam90
Copy link
Contributor Author

Sairam90 commented Sep 4, 2024

I think the example app uses pages_sections

When I use the current lib with the icon attr removed from the toml,it errors on line 202 as page[“icon”] is not found

@blackary
Copy link
Owner

blackary commented Sep 4, 2024

@Sairam90 it uses both, depending on whether the toggle for "Sections" it checked, but both of them have no icon for "example three"

Ah, so the actual problem is if you have a Section with no icon. Yeah, that makes sense -- I didn't realize that was the problem. In that case, can you limit your changes to just support Sections with no icon? That would be great. Everything else should work fine as-is.

@@ -199,7 +201,9 @@ def _get_pages_from_config(path: str = ".streamlit/pages.toml") -> list[Page] |
for page in raw_pages:
if page.get("is_section"):
page["path"] = ""
pages.append(Section(page["name"], page["icon"])) # type: ignore
pages.append(
Section(page["name"], page["icon"] if hasattr(page, "icon") else None)
Copy link
Owner

Choose a reason for hiding this comment

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

I think this should be the only required change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah..got it..cool..I will make the changes in some time!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done now ..thanks for the help!

Copy link
Contributor Author

@Sairam90 Sairam90 Sep 5, 2024

Choose a reason for hiding this comment

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

I think there are two fixes left:

  1. here - It needs to be if page.icon: instead as icon defaults to '' (empty string) here

  2. here
    - It needs to be page.get("icon") - so that the section icons get rendered

Let me know your thoughts - I can make the changes later today

Copy link
Owner

Choose a reason for hiding this comment

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

  1. The icon should not default to '', but to None -- are you sure it's defaulting to ''?

  2. Yeah, page.get("icon") should work well there

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, cause I see the leading space issue in the section name alone in this case,though am not sure why it defaults to ‘’ instead of None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants