BugFix: Correctly extract top-level imports to prevent installation errors#31
Open
asddass wants to merge 1 commit into
Open
BugFix: Correctly extract top-level imports to prevent installation errors#31asddass wants to merge 1 commit into
asddass wants to merge 1 commit into
Conversation
Refactors the `extract_imports` function to only identify and use base module names. This change improves the stability and reliability of the dependency management.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description:
This pull request updates the
extract_importsfunction instreamlit_desktop_app/build.pyto only extract and utilize base module names during import detection. Previously, the function could return extended module paths (such asrequests.Session) due to its current implementation. This behavior sometimes resulted in installation errors when the package manager incorrectly processed these extended import paths.Problem:
The previous implementation of
extract_importsiterated through the Abstract Syntax Tree (AST) of the Streamlit script and directly added the full import path to the set of dependencies. This resulted in the inclusion of nested module paths (e.g.,requests.Session) as top-level requirements. Consequently, the application might attempt to install non-existent packages or encounter errors during the dependency resolution process. As highlighted in the provided example:Solution:
This pull request modifies the
extract_importsfunction to extract only the top-level module name from bothimportandfrom ... import ...statements. This ensures that only core packages are identified as dependencies.The provided example demonstrates the effectiveness of this fix. The new implementation correctly extracts the top-level imports:
# new_output: ['cul_cffi', 'dotenv', 'os', 'requests', 'streamlit']Impact:
I believe this enhancement will contribute to a more stable and user-friendly experience with
streamlit-desktop-appby preventing installation issues related to incorrect module path usage with accurate dependency detection and streamlined dependency management.