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

Normalize path while requesting list of assets from the server #1454

Merged
merged 4 commits into from
Jun 14, 2024

Conversation

yarikoptic
Copy link
Member

@yarikoptic yarikoptic commented Jun 14, 2024

Closes #1452

See individual commits for more description/rationale.

Related:

Duplication leads to bugs and also makes it harder to read the test
since requires mental "filtering" to disregard unnecessary duplicated
code while ensuring that not missing some critical difference.

E.g. I did miss that some have sorted() and some not.  Now it is more obvious
IMHO.

Ideally other tests with similar pattern should be redone as well.
Ideally there might be a way to use parametric testing with a common
fixture (did not check how/if possible yet)
What we call "path" is really just a prefix for dandi-archive.  To ensure more
consistent operation for a user, let's normalize those paths, even though normalization would seemingly allow for obnoxious cases like "nonexistent/../realfolder/".

According to #1452 it is likely that
we had operation more robust at server-side before and were accepting "./"
whenever now it just returns an empty list.  Not sure if worth seeking change
at dandi-archive level ATM.
@yarikoptic yarikoptic added patch Increment the patch version when merged release Create a release when this pr is merged labels Jun 14, 2024
@yarikoptic yarikoptic requested a review from jwodder June 14, 2024 13:05
yarikoptic added a commit to yarikoptic/openscope_databook that referenced this pull request Jun 14, 2024
If worked before, it stopped working at some point.
We are likely to make it more robust on dandi-cli side:
- dandi/dandi-cli#1454

but I think it would be better to just not specify such
way in the example. You might want to elaborate that example
with actually pointing to a specific folder instead
Copy link

codecov bot commented Jun 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 88.58%. Comparing base (59f5da0) to head (0aabf16).
Report is 49 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1454      +/-   ##
==========================================
+ Coverage   88.47%   88.58%   +0.10%     
==========================================
  Files          77       77              
  Lines       10518    10535      +17     
==========================================
+ Hits         9306     9332      +26     
+ Misses       1212     1203       -9     
Flag Coverage Δ
unittests 88.58% <100.00%> (+0.10%) ⬆️

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.

@@ -1154,6 +1177,8 @@ def get_assets_with_path_prefix(
Returns an iterator of all assets in this version of the Dandiset whose
`~RemoteAsset.path` attributes start with ``path``

``path`` is normalized first to possibly remove leading `./` or relative
paths (e.g., `../`) within it.
Copy link
Member

Choose a reason for hiding this comment

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

Add a blank line after this line to force a paragraph break.

Also, this paragraph should probably also be added to the docs for get_asset_by_path() and download_directory(), since those pass their path arguments to this method.

Copy link
Member Author

Choose a reason for hiding this comment

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

ok, will add use to get_asset_by_path as well

Comment on lines 1180 to 1181
``path`` is normalized first to possibly remove leading `./` or relative
paths (e.g., `../`) within it.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
``path`` is normalized first to possibly remove leading `./` or relative
paths (e.g., `../`) within it.
``path`` is normalized first to possibly remove leading ``./`` or relative
paths (e.g., ``../``) within it.

Helper to normalize path before passing it to the server.

We and API call it "path" but it is really a "prefix" with inherent
semantics of containing directory divider '/' and emphasizing with
Copy link
Member

Choose a reason for hiding this comment

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

I don't think "emphasizing" is the word you want here. Maybe "and referring to a directory when terminated with '/'."

# possibly specifying ./ or some other relative paths etc, let's normalize
# the path.
# Ref: https://github.com/dandi/dandi-cli/issues/1452
path_normed = os.path.normpath(path)
Copy link
Member

Choose a reason for hiding this comment

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

Use posixpath instead of os.path here so that forward slashes will remain forward slashes when running on Windows.

@yarikoptic
Copy link
Member Author

ha -- I have missed that my change to test_upload (to actually use ./ in download_directory) which I accidentally committed to test locally broke tests! and rightfully so since normalizing the path lead to side effect in that function... not happy about my solution now but let's proceed by fixing up download_directory for now.

@yarikoptic
Copy link
Member Author

windows -- flaky

________________________ test_IteratorWithAggregation _________________________
dandi\support\tests\test_iterators.py:72: in test_IteratorWithAggregation
    assert got in ([], [0])
E   assert [0, 1] in ([], [0])

---------- coverage: platform win32, python 3.10.11-final-0 ----------
Coverage XML written to file coverage.xml

@yarikoptic yarikoptic merged commit da90c49 into master Jun 14, 2024
27 of 28 checks passed
@yarikoptic yarikoptic deleted the bf-download-directory branch June 14, 2024 14:54
Copy link

🚀 PR was released in 0.62.2 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
patch Increment the patch version when merged release Create a release when this pr is merged released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

RemoteDandiset.download_directory doesn't appear to work?
2 participants