-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Automatic import plugin #1099
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
Automatic import plugin #1099
Conversation
It might be worth looking at pyodide.loadPackagesFromImports - they've got a fair bit of infrastructure built up around similar functionality, including mapping known packages whose import name is different from their package name.. It only works with packages in the Pyodide distribution, not PyPi, but still might be interesting. |
Awesome thank you for the reference! I was thinking to do something like an index of packages+imports seems like that's what pyodide is using in a way 😄 This will definitely help! |
I was playing around with this, had a few problems I ran into, just thought I'd point it out:
|
// named group called "dependency". The rule will match any text | ||
// that contains 'import' or 'from' at the beginning of the line | ||
// or '\nimport', '\nfrom' which is the case when we invoke _trimWhiteSpace | ||
const importRegexRule = /^(?:\\n)?(?:import|from)\s+(?<dependency>[a-zA-Z0-9_]+)?/gm; |
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.
Can't you add \s*
to the beginning of the regex and remove trimWhiteSpace
?
const importRegexRule = /^(?:\\n)?(?:import|from)\s+(?<dependency>[a-zA-Z0-9_]+)?/gm; | |
const importRegexRule = /^(?:\\n)?\s*(?:import|from)\s+(?<dependency>[a-zA-Z0-9_]+)?/gm; |
Closing this PR since this was a POC for pyscript fun meeting |
I'm opening this PR as a draft to show the code of the automatic imports that I presented yesterday.
I think there's a lot of room for improvement so feel free to add any comments 😄
Here's a few things I would like to do: