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

Conversation

asmacdo
Copy link
Contributor

@asmacdo asmacdo commented Apr 26, 2024

I pulled the "primer" from https://dandi.readthedocs.io/en/latest/ref/urls.html#resource-ids

Do you think that helps enough?
(I also added to dandi_ls since it reused the same resource id doc)

$ dandi download --help

Usage: dandi download [OPTIONS] [URL]...

  Download files or entire folders from DANDI.

  dandi commands and 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.

  Accepted resource identifier patterns:
   - DANDI:<dandiset id>[/<version>]
   - https://gui.dandiarchive.org/...
   - https://identifiers.org/DANDI:<dandiset id>[/<version id>] (<version id> cannot be 'draft')
   - https://<server>[/api]/[#/]dandiset/<dandiset id>[/<version>][/files[?location=<path>]]
   - https://*dandiarchive-org.netflify.app/...
   - https://<server>[/api]/dandisets/<dandiset id>[/versions[/<version>]]
   - https://<server>[/api]/assets/<asset id>[/download]
   - https://<server>[/api]/dandisets/<dandiset id>/versions/<version>/assets/<asset id>[/download]
   - https://<server>[/api]/dandisets/<dandiset id>/versions/<version>/assets/?path=<path>
   - https://<server>[/api]/dandisets/<dandiset id>/versions/<version>/assets/?glob=<glob>
   - dandi://<instance name>/<dandiset id>[@<version>][/<path>]
   - https://<server>/...
      

Options:
  -o, --output-dir DIRECTORY      Directory where to download to (directory
                                  must exist). Files will be downloaded with
                                  paths relative to that directory.
  -e, --existing [error|skip|overwrite|overwrite-different|refresh]
                                  What to do if a file found existing locally.
                                  'refresh': verify that according to the size
                                  and mtime, it is the same file, if not -
                                  download and overwrite.  [default: error]
  -f, --format [pyout|debug]      Choose the format/frontend for output. TODO:
                                  support all of the ls
  --path-type [exact|glob]        Whether to interpret asset paths in URLs as
                                  exact matches or glob patterns  [default:
                                  exact]
  -J, --jobs N[:M]                Number of parallel download jobs and,
                                  optionally number of subjobs per Zarr asset
                                  [default: 6]
  --download [dandiset.yaml,assets,all]
                                  Comma-separated list of elements to download
                                  [default: all]
  --sync                          Delete local assets that do not exist on the
                                  server
  -i, --dandi-instance TEXT       DANDI Archive instance to download from. If
                                  any URLs are provided, they must point to
                                  the given instance. If no URL is provided,
                                  and there is a local dandiset.yaml file, the
                                  Dandiset with the identifier given in the
                                  file will be downloaded from the given
                                  instance.  [env var: DANDI_INSTANCE]
  --help                          Show this message and exit.

Copy link

codecov bot commented Apr 26, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.59%. Comparing base (15196a9) to head (d3d4ec3).

❗ Current head d3d4ec3 differs from pull request most recent head 58c7c4c. Consider uploading reports for the commit 58c7c4c to get more accurate results

Additional details and impacted files
@@             Coverage Diff             @@
##           master    #1437       +/-   ##
===========================================
- Coverage   88.54%   62.59%   -25.95%     
===========================================
  Files          77       77               
  Lines       10561    10563        +2     
===========================================
- Hits         9351     6612     -2739     
- Misses       1210     3951     +2741     
Flag Coverage Δ
unittests 62.59% <100.00%> (-25.95%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@asmacdo
Copy link
Contributor Author

asmacdo commented Apr 26, 2024

IMO with the explanation we could now trim that list way back to the common cases and include a linking to https://dandi.readthedocs.io/en/latest/ref/urls.html#resource-ids

dandi/dandiarchive.py Outdated Show resolved Hide resolved
@asmacdo
Copy link
Contributor Author

asmacdo commented Apr 27, 2024

Added examples and cleaned it up a bit.

Usage: dandi download [OPTIONS] [URL]...

  Download files or entire folders from DANDI.

  RESOURCE ID/URLS:

      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.

  Accepted resource identifier patterns:
   - DANDI:<dandiset id>[/<version>]
   - https://gui.dandiarchive.org/...
   - https://identifiers.org/DANDI:<dandiset id>[/<version id>] (<version id> cannot be 'draft')
   - https://<server>[/api]/[#/]dandiset/<dandiset id>[/<version>][/files[?location=<path>]]
   - https://*dandiarchive-org.netflify.app/...
   - https://<server>[/api]/dandisets/<dandiset id>[/versions[/<version>]]
   - https://<server>[/api]/assets/<asset id>[/download]
   - https://<server>[/api]/dandisets/<dandiset id>/versions/<version>/assets/<asset id>[/download]
   - https://<server>[/api]/dandisets/<dandiset id>/versions/<version>/assets/?path=<path>
   - https://<server>[/api]/dandisets/<dandiset id>/versions/<version>/assets/?glob=<glob>
   - dandi://<instance name>/<dandiset id>[@<version>][/<path>]
   - https://<server>/...



  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 all from a specific version

  dandi download DANDI:000027/0.210831.2033

Options:
  -o, --output-dir DIRECTORY      Directory where to download to (directory
                                  must exist). Files will be downloaded with
                                  paths relative to that directory.
  -e, --existing [error|skip|overwrite|overwrite-different|refresh]
                                  What to do if a file found existing locally.
                                  'refresh': verify that according to the size
                                  and mtime, it is the same file, if not -
                                  download and overwrite.  [default: error]
  -f, --format [pyout|debug]      Choose the format/frontend for output. TODO:
                                  support all of the ls
  --path-type [exact|glob]        Whether to interpret asset paths in URLs as
                                  exact matches or glob patterns  [default:
                                  exact]
  -J, --jobs N[:M]                Number of parallel download jobs and,
                                  optionally number of subjobs per Zarr asset
                                  [default: 6]
  --download [dandiset.yaml,assets,all]
                                  Comma-separated list of elements to download
                                  [default: all]
  --sync                          Delete local assets that do not exist on the
                                  server
  -i, --dandi-instance TEXT       DANDI Archive instance to download from. If
                                  any URLs are provided, they must point to
                                  the given instance. If no URL is provided,
                                  and there is a local dandiset.yaml file, the
                                  Dandiset with the identifier given in the
                                  file will be downloaded from the given
                                  instance.  [env var: DANDI_INSTANCE]
  --help                          Show this message and exit.

Co-authored-by: Yaroslav Halchenko <debian@onerussian.com>
Comment on lines 15 to 29
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
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
Contributor 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/000027@0.210831.2033/sub-RAT123/ # Download a file dandi
  download dandi://DANDI/000027@0.210831.2033/sub-RAT123/sub-RAT123.nwb

Co-authored-by: Yaroslav Halchenko <debian@onerussian.com>
@yarikoptic
Copy link
Member

Coolio, thank you!

@yarikoptic yarikoptic merged commit e5ecb8c into dandi:master May 1, 2024
16 of 24 checks passed
Copy link

github-actions bot commented May 3, 2024

🚀 PR was released in 0.62.0 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants