-
Notifications
You must be signed in to change notification settings - Fork 116
Allow ? in keys and address versions in listings, files and copies #1055
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
460c4cb
Allow "?" in keys and address versions in listings, files and copies
laughingman7743 43ab8f9
Fix regressions found in the review of version paths and "?" keys
laughingman7743 a16f063
Do not look up a missing version as a key prefix in info()
laughingman7743 b3b7d2f
Raise failed lookups of version paths, and leave destination sequence…
laughingman7743 491e567
Require fsspec>=2026.9.0 and move the version check to S3Path
laughingman7743 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ | |
|
|
||
| from __future__ import annotations | ||
|
|
||
| import os | ||
| import re | ||
| from dataclasses import dataclass, replace | ||
| from re import Pattern | ||
|
|
@@ -24,8 +25,9 @@ class S3Path: | |
| Paths are parsed from strings such as ``s3://bucket/key``, | ||
| ``s3a://bucket/key`` or ``bucket/key``, optionally followed by a version | ||
| ID query (``?versionId=``, ``?versionID=``, ``?versionid=`` or | ||
| ``?version_id=``). The root path, which names no bucket, is not an | ||
| ``S3Path``. | ||
| ``?version_id=``). Only a query at the end of the path is a version ID; | ||
| any other ``?`` is part of the key. The root path, which names no bucket, | ||
| is not an ``S3Path``. | ||
|
|
||
| Attributes: | ||
| bucket: The name of the bucket. | ||
|
|
@@ -46,9 +48,16 @@ class S3Path: | |
| 's3://bucket/dir/key?versionId=v1' | ||
| """ | ||
|
|
||
| # Version IDs do not contain "?", so only the last query can be one. | ||
| VERSION_QUERY: ClassVar[Pattern[str]] = re.compile( | ||
| r"\?version(Id|ID|id|_id)=(?P<version_id>[^?]+)\Z" | ||
| ) | ||
| # Keys may contain any character, including newlines. A bare "/" is tried | ||
| # before a key so that "bucket/?versionId=..." names the bucket. | ||
| PATTERN: ClassVar[Pattern[str]] = re.compile( | ||
| r"(^s3://|^s3a://|^)(?P<bucket>[a-zA-Z0-9.\-_]+)(/(?P<key>[^?]+)|/)?" | ||
| r"($|\?version(Id|ID|id|_id)=(?P<version_id>.+)$)" | ||
| r"(^s3://|^s3a://|^)(?P<bucket>[a-zA-Z0-9.\-_]+)(/|/(?P<key>.+?))?" | ||
| rf"(\Z|{VERSION_QUERY.pattern})", | ||
| re.DOTALL, | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Independent review (relayed), findings 2 and 3 (P2): confirmed and repaired.
Both are covered by new |
||
| ) | ||
|
|
||
| bucket: str | ||
|
|
@@ -74,6 +83,41 @@ def parse(cls, path: str) -> S3Path: | |
| raise ValueError(f"Invalid S3 path format {path}.") | ||
| return cls(match.group("bucket"), match.group("key"), match.group("version_id")) | ||
|
|
||
| @classmethod | ||
| def split_version_id(cls, path: str) -> tuple[str, str | None]: | ||
| """Split the version ID query from the end of a path string. | ||
|
|
||
| Unlike :meth:`parse`, any string is accepted, such as the names that | ||
| fsspec builds. | ||
|
|
||
| Args: | ||
| path: The path string. | ||
|
|
||
| Returns: | ||
| Tuple of the string without the version ID query and the version | ||
| ID, or of the string itself and None if it ends with no version | ||
| ID query. | ||
| """ | ||
| match = cls.VERSION_QUERY.search(path) | ||
| if not match: | ||
| return path, None | ||
| return path[: match.start()], match.group("version_id") | ||
|
|
||
| @classmethod | ||
| def has_version_id(cls, path: str | os.PathLike[str]) -> bool: | ||
| """Return whether a path string ends with a version ID query. | ||
|
|
||
| Unlike :meth:`parse`, any string is accepted, as with | ||
| :meth:`split_version_id`. | ||
|
|
||
| Args: | ||
| path: The path. | ||
|
|
||
| Returns: | ||
| Whether the path ends with a version ID query. | ||
| """ | ||
| return cls.split_version_id(os.fspath(path))[1] is not None | ||
|
|
||
| @property | ||
| def is_bucket(self) -> bool: | ||
| """Whether the path names the bucket: it has no key, or a key of only slashes.""" | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Independent review (relayed), finding 6 (P2): confirmed and repaired. Delegating aio
_expand_path()to the syncexpand_path()lost fsspec's async globprefix=(the stem before the first wildcard), sobucket/reports/2026-*.csvlistedreports/instead ofreports/2026-.The aio override now splits off the version paths with the shared
_split_version_paths()and passes the others to fsspec's async_expand_path().test_expand_path_glob_lists_stem_prefixassertsprefix="2026-".