Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions dandi/dandiarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,8 @@ class _dandi_url_parser:
dandiset_id_grp = f"(?P<dandiset_id>{DANDISET_ID_REGEX})"
# Should absorb port and "api/":
server_grp = "(?P<server>(?P<protocol>https?)://(?P<hostname>[^/]+)/(api/)?)"
# Build instance name pattern from known instances to avoid matching unknown patterns
instance_name_pattern = "|".join(re.escape(name) for name in known_instances.keys())
known_urls: list[tuple[re.Pattern[str], dict[str, Any], str]] = [
# List of (regex, settings, display string) triples
#
Expand All @@ -589,13 +591,13 @@ class _dandi_url_parser:
# for not only "dandiarchive.org" URLs
(
re.compile(
rf"(?P<instance_name>DANDI):"
rf"(?P<instance_name>{instance_name_pattern}):"
rf"{dandiset_id_grp}"
rf"(/(?P<version>{VERSION_REGEX}))?",
flags=re.I,
),
{},
"DANDI:<dandiset id>[/<version>]",
"<INSTANCE>:<dandiset id>[/<version>]",
),
(
re.compile(r"https?://gui\.dandiarchive\.org/.*"),
Expand Down
49 changes: 49 additions & 0 deletions dandi/tests/test_dandiarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,55 @@
version_id="0.210831.2033",
),
),
# Test other instances with short format
(
"DANDI-SANDBOX:000029",
DandisetURL(
instance=known_instances["dandi-sandbox"],
dandiset_id="000029",
version_id=None,
),
),
(
"dandi-sandbox:000029/draft",
DandisetURL(
instance=known_instances["dandi-sandbox"],
dandiset_id="000029",
version_id="draft",
),
),
(
"LINC:000029",
DandisetURL(
instance=known_instances["linc"],
dandiset_id="000029",
version_id=None,
),
),
(
"linc:000029/0.210831.2033",
DandisetURL(
instance=known_instances["linc"],
dandiset_id="000029",
version_id="0.210831.2033",
),
),
(
"EMBER:000029",
DandisetURL(
instance=known_instances["ember"],
dandiset_id="000029",
version_id=None,
),
),
(
"ember-sandbox:000029/draft",
DandisetURL(
instance=known_instances["ember-sandbox"],
dandiset_id="000029",
version_id="draft",
),
),
(
"http://localhost:8000/api/dandisets/000002/",
DandisetURL(
Expand Down
6 changes: 4 additions & 2 deletions docs/source/ref/urls.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ has one, and its draft version will be used otherwise.
(case insensitive; ``version`` cannot be "draft") when it redirects
to one of the other URL formats

- :samp:`DANDI:{dandiset-id}[/{version}]` (case insensitive)
— Refers to a Dandiset on the main DANDI Archive instance named "dandi".
- :samp:`{instance-name}:{dandiset-id}[/{version}]` (case insensitive,
where ``instance-name`` is a known DANDI instance such as ``DANDI``,
``DANDI-SANDBOX``, ``LINC``, ``EMBER``, etc.)
— Refers to a Dandiset on the specified DANDI Archive instance.
`parse_dandi_url()` converts this format to a `DandisetURL`.

- Any ``https://gui.dandiarchive.org/`` or
Expand Down