-
Notifications
You must be signed in to change notification settings - Fork 33
Reimplement dandi.utils.is_url
#1767
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## remove-hardcode #1767 +/- ##
===================================================
+ Coverage 75.04% 75.07% +0.02%
===================================================
Files 84 84
Lines 11887 11905 +18
===================================================
+ Hits 8921 8938 +17
- Misses 2966 2967 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
What prompted this? |
9764a26 to
492e74e
Compare
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.
Pull request overview
This PR reimplements the is_url helper function to provide more precise URL validation for HTTP, HTTPS, FTP, and DANDI URLs, with support for different DANDI archive instances. The previous implementation used simple string prefix matching, while the new version uses pydantic's URL validators and DANDI's URL parser.
Key changes:
- Replaced string prefix checking with pydantic
TypeAdapterfor standard URL validation - Integrated DANDI URL validation through
parse_dandi_urlfor custom DANDI URL formats - Added comprehensive test coverage with 41 test cases covering valid and invalid URLs
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| dandi/utils.py | Reimplements is_url() function using pydantic validators and parse_dandi_url() for more precise URL detection; adds module-level _url_adapter for performance |
| dandi/tests/test_utils.py | Adds comprehensive test suite with TestIsUrl class covering HTTP/HTTPS/FTP URLs, DANDI identifiers, and invalid URL formats |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
So that it can determine whether a given string is a standard HTTP, HTTPS, FTP URL, or DANDI URL more precisely. Additionally, this solution supports DANDI URL of different DANDI archive instances.
492e74e to
b8d1379
Compare
|
@yarikoptic This one is ready for review. I don't know what label is appropriate since it is to be merged to #1760. |
* test: update `test_update_dandiset_from_doi` So that the checks of `id` and `identifier` in metadata allow different instance names * test: update `test_download_dandiset_yaml` So that the check of `id` in metadata allows different instance names * feat: remove block that fetch dandiset identifier that is irrelevant See #1760 (comment) for details * doc: replace hardcoded "DANDI:" comment To reflect that instance names are no longer restricted to "DANDI" * fix: strip instance name prefix from dandiset ID in `update_dandiset_from_doi` This is only a replacement for the code that strips the "DANDI:" prefix. The replacement works for dandisets of different DANDI instances. However, `update_dandiset_from_doi` is far from robust. This replacement doesn't fix underlying weakness stems from assumptions. Further improvements of `update_dandiset_from_doi` are needed. * Reimplement `dandi.utils.is_url` (#1767) * feat: reimplement `dandi.utils.is_url` So that it can determine whether a given string is a standard HTTP, HTTPS, FTP URL, or DANDI URL more precisely. Additionally, this solution supports DANDI URL of different DANDI archive instances. * test: Add tests for `dandi.utils.is_url` * ci: test against vendored dandiapi other than default (#1771) Configuer CI to test against a vendor specific DANDI API other than the default instance of DANDI API
This PR reimplement the helper function
dandi.utils.is_urlso that it can determine whether a given string is a standard HTTP, HTTPS, FTP URL, or DANDI URL more precisely. Additionally, this solution supports DANDI URLs of different DANDI archive instances.Remaining TODOs: