-
Notifications
You must be signed in to change notification settings - Fork 4k
Move check_* utils to own file #8764
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
Conversation
lukasmasuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like that the methods are not yet removed from utils.py or am I missing something. Also, it seems to not yet cover all relevant elements (e.g data editor is missing?)
lib/streamlit/elements/policies.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit annoyed by all the import cycle warnings. I believe this import might be the issue. Can we move this import down into the function from where it is used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah the circular imports at some places in the code base are pretty annoying. I have spent some time today looking into refactoring it and refactoring everything including the delta generator are on top of my list 😄 moving the imports down - if it works at all as it opened a rabbit hole earlier - just hides the original problem that the code is not pretty well abstracted. I guess eventually we have to start cleaning it up top down.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving the imports down - if it works at all as it opened a rabbit hole earlier - just hides the original problem that the code is not pretty well abstracted
Yeah, I think the better solution would be to have some internal import for exception and warning, but I'm not sure if that is viable without bigger refactoring. But just having a blank streamlit import here on top doesn't feel super good. Overall, it's better to move this import down and all the other check_ imports to the top level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since its a delta generator function, the best way would likely be to have to pass the deltagenerator to the function instead of importing a global object. But this surfaces other import issues at other places; so I think the first step has to be abstracting the delta generator and probably move out the main_dg and other *_dg variables and dg_stack out and work with a singleton factory or so. But that requires a little bit more time
73b59b9 to
b5aad90
Compare
94e6571 to
12ec5c3
Compare
|
@lukasmasuch could you please have another look? The CodeScan things look like a lot, but I have moved the imports within the |
lukasmasuch
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 I think it would be good to move policies and/or utils into the element/lib folder. These are the only two non-element modules within this folders, and it feels like element/lib would be a better place.
12ec5c3 to
18888e0
Compare
Great point, I have moved both utils files |
| f'The widget with key "{key}" was created with a default value but' | ||
| " also had its value set via the Session State API." | ||
| ) | ||
| _shown_default_value_warning = True |
Check notice
Code scanning / CodeQL
Unused global variable
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from streamlit import config, runtime | ||
| from streamlit.elements.form import is_in_form |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
| from streamlit.elements.lib.policies import ( | ||
| check_cache_replay_rules, | ||
| check_callback_rules, | ||
| check_session_state_rules, | ||
| ) |
Check notice
Code scanning / CodeQL
Cyclic import
## Describe your changes In https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/elements/utils.py we have some check_* functions that are used to enforce certain rules. This PR moves them to their own policies.py file for cleaner abstraction. Also, tests for check_cache_replay_rules were missing that are added now. This is in preparation of adding a new check_* policy function in this PR: https://github.com/streamlit/streamlit/pull/8756/files ## GitHub Issue Link (if applicable) ## Testing Plan - Unit Tests (JS and/or Python) - moved unittests and added new ones --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
## Describe your changes In https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/elements/utils.py we have some check_* functions that are used to enforce certain rules. This PR moves them to their own policies.py file for cleaner abstraction. Also, tests for check_cache_replay_rules were missing that are added now. This is in preparation of adding a new check_* policy function in this PR: https://github.com/streamlit/streamlit/pull/8756/files ## GitHub Issue Link (if applicable) ## Testing Plan - Unit Tests (JS and/or Python) - moved unittests and added new ones --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
## Describe your changes In https://github.com/streamlit/streamlit/blob/develop/lib/streamlit/elements/utils.py we have some check_* functions that are used to enforce certain rules. This PR moves them to their own policies.py file for cleaner abstraction. Also, tests for check_cache_replay_rules were missing that are added now. This is in preparation of adding a new check_* policy function in this PR: https://github.com/streamlit/streamlit/pull/8756/files ## GitHub Issue Link (if applicable) ## Testing Plan - Unit Tests (JS and/or Python) - moved unittests and added new ones --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.
Replace the TTLCache in ResourceCache with a TTLCleanupCache. Add on_release to the st.cache_resource API, and plumb it through to the TTLCleanupCache. Update st.cache_resource.clear_all to clear the cache directly instead of just GCing it to ensure release functions are called. Implements feature request in #8764 .
## Describe your changes Replace the TTLCache in ResourceCache with a TTLCleanupCache. Add on_release to the st.cache_resource API, and plumb it through to the TTLCleanupCache. Update st.cache_resource.clear_all to clear the cache directly instead of just GCing it to ensure release functions are called. Implements feature request in #8764 . ## GitHub Issue Link (if applicable) - Closes #8674 ## Testing Plan - Unit Tests (JS and/or Python) Implemented. --- **Contribution License Agreement** By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license. --------- Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
Describe your changes
In streamlit/elements/utils.py we have some
check_*functions that are used to enforce certain rules. This PR moves them to their ownpolicies.pyfile for cleaner abstraction.Also, tests for
check_cache_replay_ruleswere missing that are added now.This is in preparation of adding a new
check_*policy function in this PR: https://github.com/streamlit/streamlit/pull/8756/filesGitHub Issue Link (if applicable)
Testing Plan
Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.