relative#
Relative Path implementation.
- class s3pathlib.core.relative.RelativePathAPIMixin[source]#
A mixin class that implements the relative path concept.
- classmethod make_relpath(*parts: str) S3Path [source]#
A construct method that create a relative S3 Path.
Definition of relative path:
no bucket (self.bucket is None)
- has some parts or no part. when no part, it is a special relative path.
Any path add this relative path resulting to itself. We call this special relative path Void relative path. A Void relative path is logically equivalent to Void s3 path.
- relative path can be a file (object) or a directory. The
Void relative path is neither a file or a directory.
- Parameters:
parts –
New in version 1.0.1.
中文文档
相对路径的概念是 p1 + p2 = p3, 其中 p1 和 p3 都是实际存在的路径, 而 p2 则是 相对路径.
相对路径的功能是如果 p3 - p1 = p2, 那么 p1 + p2 必须还能等于 p3. 有一个特殊情况是 如果 p1 - p1 = p0, 两个相同的绝对路径之间的相对路径是 p0, 我们还是需要满足 p1 + p0 = p1 以保证逻辑上的一致.
- relative_to(other: S3Path) S3Path [source]#
Return the relative path to another path. If the operation is not possible (because this is not a sub path of the other path), raise
ValueError
.-
is a syntax sugar forrelative_to
. See more information at__sub__()
.The relative path usually works with
joinpath()
to form a new path. Or you can use the/
syntax sugar as well.Examples:
>>> S3Path("bucket", "a/b/c").relative_to(S3Path("bucket", "a")).parts ['b', 'c'] >>> S3Path("bucket", "a").relative_to(S3Path("bucket", "a")).parts [] >>> S3Path("bucket", "a").relative_to(S3Path("bucket", "a/b/c")).parts ValueError ... >>> S3Path("bucket") / S3Path("new_bucket/file.txt").relative_to(S3Path("new_bucket")) S3Path('s3://bucket/file.txt')
- Parameters:
other – other
S3Path
instance.- Returns:
a relative path object, which is a special version of S3Path
New in version 1.0.1.
- is_relpath() bool [source]#
Relative path is a special path supposed to join with other concrete path.
Definition
A long full path relating to its parent directory is a relative path. A
void
path also a special relative path.New in version 1.0.1.