Skip to content
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

clarify resource identifier docs #1437

Merged
merged 5 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
27 changes: 26 additions & 1 deletion dandi/cli/cmd_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,41 @@
from ..download import DownloadExisting, DownloadFormat, PathType
from ..utils import get_instance, joinurl

_examples = """
EXAMPLES: \n
# Download only the dandiset.yaml \n
dandi download --download dandiset.yaml DANDI:000027 \n

# Download only dandiset.yaml if there is a newer version \n
dandi download https://identifiers.org/DANDI:000027 --existing refresh

# Download only the assets \n
dandi download --download assets DANDI:000027

# Download all from a specific version \n
dandi download DANDI:000027/0.210831.2033

# Download a specific file or directory \n
dandi download dandi://DANDI/[email protected]/sub-RAT123/sub-RAT123.nwb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • what could trailing empty spaces would do besides in rare cases possibly negatively effecting wrapping?

  • also why bother with extra new line?

  • best to provide specific example for a directory since needs to end with / IIRC (please check that works)

Suggested change
EXAMPLES: \n
# Download only the dandiset.yaml \n
dandi download --download dandiset.yaml DANDI:000027 \n
# Download only dandiset.yaml if there is a newer version \n
dandi download https://identifiers.org/DANDI:000027 --existing refresh
# Download only the assets \n
dandi download --download assets DANDI:000027
# Download all from a specific version \n
dandi download DANDI:000027/0.210831.2033
# Download a specific file or directory \n
dandi download dandi://DANDI/000027@0.210831.2033/sub-RAT123/sub-RAT123.nwb
EXAMPLES:\n
# Download only the dandiset.yaml
dandi download --download dandiset.yaml DANDI:000027
# Download only dandiset.yaml if there is a newer version
dandi download https://identifiers.org/DANDI:000027 --existing refresh
# Download only the assets
dandi download --download assets DANDI:000027
# Download everything for a specific version of a dandiset
dandi download DANDI:000027/0.210831.2033
# Download a specific directory
dandi download dandi://DANDI/000027@0.210831.2033/sub-RAT123/
# Download a file
dandi download dandi://DANDI/000027@0.210831.2033/sub-RAT123/sub-RAT123.nwb

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what could trailing empty spaces would do besides in rare cases possibly negatively effecting wrapping?

I just used them to separate the \n for human reading, but I dont feel strongly. Removed in latest commit.

also why bother with extra new line?

I'm not sure why, but a single newline is skipped, maybe something to do with the fstring?

# The use of f-strings apparently makes this not a proper docstring, and so
# click doesn't use it unless we explicitly assign it to `help`:

Your suggestion renders like this:

  EXAMPLES:

  # Download only the dandiset.yaml dandi download --download dandiset.yaml
  DANDI:000027 # Download only dandiset.yaml if there is a newer version dandi
  download https://identifiers.org/DANDI:000027 --existing refresh # Download
  only the assets dandi download --download assets DANDI:000027 # Download
  everything for a specific version of a dandiset dandi download
  DANDI:000027/0.210831.2033 # Download a specific directory dandi download
  dandi://DANDI/[email protected]/sub-RAT123/ # Download a file dandi
  download dandi://DANDI/[email protected]/sub-RAT123/sub-RAT123.nwb

"""


# The use of f-strings apparently makes this not a proper docstring, and so
# click doesn't use it unless we explicitly assign it to `help`:
@click.command(
help=f"""\
Download files or entire folders from DANDI.

\b
{_dandi_url_parser.resource_identifier_primer}

\b
{_dandi_url_parser.known_patterns}
asmacdo marked this conversation as resolved.
Show resolved Hide resolved
"""

\b
{_examples}

"""
)
@click.option(
"-o",
Expand Down
2 changes: 2 additions & 0 deletions dandi/cli/cmd_ls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
The arguments may be either resource identifiers or paths to local
files/directories.

\b
{_dandi_url_parser.resource_identifier_primer}
\b
{_dandi_url_parser.known_patterns}
"""
Expand Down
10 changes: 10 additions & 0 deletions dandi/dandiarchive.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,16 @@ class _dandi_url_parser:
"https://<server>/...",
),
]
resource_identifier_primer = """RESOURCE ID/URLS:\n
dandi commands accept URLs and URL-like identifiers called <resource
ids> in the following formats for identifying Dandisets, assets, and
asset collections.

Text in [brackets] is optional. A server field is a base API or GUI URL
for a DANDI Archive instance. If an optional ``version`` field is
omitted from a URL, the given Dandiset's most recent published version
will be used if it has one, and its draft version will be used otherwise.
"""
known_patterns = "Accepted resource identifier patterns:" + "\n - ".join(
[""] + [display for _, _, display in known_urls]
)
Expand Down
Loading