Closed chnpenny closed 11 months ago
@liormizr this PR is ready. Can we get a review please?
@chnpenny how do you want to continue? I'm waiting for this PR for a big version Do you want to continue or do you want me to take when you did as an example and write my own version of this feature?
@chnpenny how do you want to continue? I'm waiting for this PR for a big version Do you want to continue or do you want me to take when you did as an example and write my own version of this feature?
@liormizr apologies. we have been quite busy until now. We will work on this now.
@liormizr thanks for the review. i implemented your suggestions and this is ready for another round of review.
Thanks for the comment about relative paths @liormizr. This is again ready for review.
thanks @chnpenny & @nlangellier I think that we are almost done Two notes
thanks @chnpenny & @nlangellier I think that we are almost done Two notes
- after adding PureVersionedS3Path and VersionedS3Path can we update the doc's accordingly? I mean in the docs/interface.rst file
- In PureVersionedS3Path why didn't we in the end go with changing the _from_parts method?
Thank you @liormizr
Regarding the first question: Yes forgot to update that. Will do that today.
Regarding the second point: We felt it was unnecessary to do so, but perhaps we missed an important detail as to why you suggested to override the _from_parts
method? One of our goals in this PR was to avoid code duplication when possible. _VersionedS3Accessor
required a fair bit of code duplication, which is OK. But as another example, you had originally suggested to define PureVersionedS3Path.from_uri
as:
def from_uri(cls, uri: str, *, version_id: str) -> PureVersionedS3Path:
if not uri.startswith('s3://'):
raise ValueError('Provided uri seems to be no S3 URI!')
return cls(uri[4:], version_id=version_id)
but we made the decision to recycle the code from PureS3Path.from_uri
by implementing PureVersionedS3Path.from_uri
as:
def from_uri(cls, uri: str, *, version_id: str) -> PureVersionedS3Path:
self = PureS3Path.from_uri(uri)
return cls(self, version_id=version_id)
The idea there was that if a future change is made to PureS3Path.from_uri
, the same change will very likely be needed in PureVersionedS3Path.from_uri
as well and thus the change will only need to be made in one place. In a similar manner of thinking we implemented PureVersionedS3Path.__rtruediv__
by trying to minimize code duplication and recycle code where possible. By defining it as
def __rtruediv__(self, key):
if not isinstance(key, (PureS3Path, str)):
return NotImplemented
new_path = super().__rtruediv__(key)
new_path.version_id = self.version_id
return new_path
then we let pathlib.PurePath.__rtruediv__
"do the heavy lifting" so to speak and we only add the additional functionality needed on top of that. If you don't like this approach or there is some subtle bug we are not thinking of, please let us know and we'll be happy to implement your idea of additionally overriding _from_parts
.
For the first version we can go with your approach Lets see maybe it's just my preference
Well done and thank you for the hard work
@liormizr we hadn't finished updating the documentation yet. We'll open a separate PR for that later today
This PR addresses issue #126 by
VersionedS3Path
class to the public APIst_version_id
property toStatResult
tests/test_path_operations.py
README.rst
anddocs/interface.rst
Additional notes
VersionedS3Path
inherits fromS3Path
but adds aversion_id
parameter to the various constructor methods. In order to follow the Liskov substitution principle, this parameter is made optional with a default value ofNone
. We thought that if a user does not supply a value for this parameter, then the returned instance should be of typeS3Path
instead ofVersionedS3Path
. Hence the necessity for overriding the__new__
constructor.S3Path
objects, they do not make sense forVersionedS3Path
objects as relative and bucket-only S3 paths have no concept of a version ID. Thus aValueError
is raised if a used attempts to instantiate such an object.__repr__
method as the default__repr__
provided bypathlib
would omit the value of theversion_id
argument, leading to a misrepresentation of the construction of the object.st_version_id
parameter ofStatResult
has a default value ofNone
and thus is fully backwards compatible with previous versions ofs3path
. In fact, we were careful to make all changes in this PR backwards compatible.README.rst
, we added the line\*New in S3Path version 0.5.0
. Please feel free to ask us to remove this line or to change it to whatever version this will be added to.