-
Notifications
You must be signed in to change notification settings - Fork 6
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
Fix detection of dependencies where key and name differ #36
Merged
Merged
Changes from 9 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
6b4a5a5
Fix logic
wch 13b6a16
Fix detection of packages where key and name differ
wch 44eb0c9
Be case insensitive for package names
wch 4021e47
Update changelog
wch 3d93bbb
Fix escaping
wch 13f2e32
Allow - and _ in requirements.txt
wch 93df443
Don't error if package not found in pyodide_lock
wch d2f5c0a
Bump version to 0.5.0.9000
wch ee8a46e
Add tests for dependency detection
wch 41aac9e
Skip some tests in CI
wch 3cbde49
Use 'is None' instead of '== None'
wch 6d20125
Clearer comment block
wch 7c034fd
Fix typo
wch c370507
Add more tests
wch File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# The version of this Python package. | ||
SHINYLIVE_PACKAGE_VERSION = "0.5.0" | ||
SHINYLIVE_PACKAGE_VERSION = "0.5.0.9000" | ||
|
||
# This is the version of the Shinylive assets to use. | ||
SHINYLIVE_ASSETS_VERSION = "0.5.0" |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""Tests for Shinlyive assets.""" | ||
"""Tests for Shinylive assets.""" | ||
|
||
import os | ||
|
||
|
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
"""Tests for Shinylive dependency detection.""" | ||
|
||
|
||
def test_requirements_txt(): | ||
from shinylive._deps import _find_packages_in_requirements | ||
|
||
requirements_txt = """ | ||
typing_extensions | ||
jsonschema-specifications (<1.0) | ||
# comment | ||
""" | ||
|
||
# This should convert '_' to '-', and remove the version constraints. | ||
assert _find_packages_in_requirements(requirements_txt) == [ | ||
"typing-extensions", | ||
"jsonschema-specifications", | ||
] | ||
|
||
# Should preserve case here (in other steps it will be lowercased). | ||
assert _find_packages_in_requirements("Jinja2") == ["Jinja2"] | ||
assert _find_packages_in_requirements("jinja2") == ["jinja2"] | ||
|
||
|
||
def test_module_to_package_key(): | ||
from shinylive._deps import module_to_package_key | ||
|
||
assert module_to_package_key("cv2") == "opencv-python" | ||
assert module_to_package_key("black") == "black" | ||
assert module_to_package_key("foobar") == None | ||
|
||
|
||
def test_dep_name_to_dep_key(): | ||
from shinylive._deps import dep_name_to_dep_key | ||
|
||
assert dep_name_to_dep_key("black") == "black" | ||
assert dep_name_to_dep_key("typing-extensions") == "typing-extensions" | ||
assert ( | ||
dep_name_to_dep_key("jsonschema_specifications-tests") | ||
== "jsonschema-specifications-tests" | ||
) | ||
|
||
# Should not convert `_` to `-` | ||
assert dep_name_to_dep_key("typing_extensions") == None | ||
|
||
# Should be case insensitive to input. | ||
assert dep_name_to_dep_key("Jinja2") == "jinja2" | ||
assert dep_name_to_dep_key("JiNJa2") == "jinja2" | ||
|
||
assert dep_name_to_dep_key("cv2") == None | ||
|
||
|
||
def test_find_recursive_deps(): | ||
from shinylive._deps import _find_recursive_deps | ||
|
||
# It is possible that these dependencies will change in future versions of Pyodide, | ||
# but the reason we're testing jsonschema specifically is because it includes | ||
# jsonschema_specifications, which is the package name (and not the key). | ||
assert sorted(_find_recursive_deps(["jsonschema"])) == [ | ||
"attrs", | ||
"jsonschema", | ||
"jsonschema_specifications", | ||
"pyrsistent", | ||
"referencing", | ||
"rpds-py", | ||
"six", | ||
] | ||
|
||
assert sorted(_find_recursive_deps(["opencv-python"])) == [ | ||
"numpy", | ||
"opencv-python", | ||
] |
Oops, something went wrong.
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.
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.
Should this maybe throw a warning?
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.
Oh nvm, now I see the warning above
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 will be fairly common to not have a package in the pyodide_lock.json file. In that case, micropip will go out and try to install it from PyPI.