charmlibs-pathops 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,54 @@
1
+ # Copyright 2025 Canonical Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ r""":mod:`pathlib`-like interface for local and :class:`ops.Container` filesystem paths.
16
+
17
+ The ``pathops`` charm library provides:
18
+
19
+ - :class:`PathProtocol`: defines the interface of methods common to both local and container paths.
20
+ Use this to type annotate code designed to work on both Kubernetes and machine charms.
21
+ - :class:`ContainerPath`: the concrete implementation of the interface for remote paths in the
22
+ workload container of Kubernetes charms. Operations are implemented using the Pebble file API.
23
+ - :class:`LocalPath`: the concrete implementation of the interface for local paths, which includes
24
+ both machine charms and the charm container of Kubernetes charms.
25
+ - Top-level helper functions such as :func:`ensure_contents`, which operate on both container
26
+ and local paths.
27
+
28
+ :class:`ContainerPath` methods that interact with the remote filesystem will raise a
29
+ :class:`PebbleConnectionError` if the workload container isn't reachable.
30
+ Methods designed to work with both local and container paths may handle this error internally,
31
+ or they may leave handling connection errors to the caller, documenting this if so.
32
+ """
33
+
34
+ from __future__ import annotations
35
+
36
+ from pathlib import Path as _Path # for __version__
37
+
38
+ from ops.pebble import ConnectionError as PebbleConnectionError
39
+
40
+ from ._container_path import ContainerPath, RelativePathError
41
+ from ._functions import ensure_contents
42
+ from ._local_path import LocalPath
43
+ from ._types import PathProtocol
44
+
45
+ __all__ = (
46
+ 'ContainerPath',
47
+ 'LocalPath',
48
+ 'PathProtocol',
49
+ 'PebbleConnectionError',
50
+ 'RelativePathError',
51
+ 'ensure_contents',
52
+ )
53
+
54
+ __version__ = (_Path(__file__).parent / '_version.txt').read_text().strip()
@@ -0,0 +1,31 @@
1
+ # Copyright 2025 Canonical Ltd.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """Magic numbers."""
16
+
17
+ import stat
18
+
19
+ DEFAULT_MKDIR_MODE = stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
20
+ """Pebble's default of 0o755 (493) 'drwxr-xr-x'.
21
+
22
+ Pathlib's default value is 0o777 (511) 'drwxrwxrwx'.
23
+ """
24
+ assert DEFAULT_MKDIR_MODE == 0o755
25
+
26
+ DEFAULT_WRITE_MODE = stat.S_IRUSR | stat.S_IWUSR | stat.S_IRGRP | stat.S_IROTH
27
+ """Pebble's default of 0o644 (420) '-rw-r--r--'.
28
+
29
+ Pathlib's default value is 0o666 (438) '-rw-rw-rw-'.
30
+ """
31
+ assert DEFAULT_WRITE_MODE == 0o644