55
55
from ops .jujuversion import JujuVersion
56
56
57
57
if typing .TYPE_CHECKING :
58
+ from pebble import ( # pyright: reportMissingTypeStubs=false
59
+ CheckInfo ,
60
+ CheckLevel ,
61
+ Client ,
62
+ ExecProcess ,
63
+ FileInfo ,
64
+ Plan ,
65
+ ServiceInfo ,
66
+ )
58
67
from typing_extensions import TypedDict
59
68
60
69
_StorageDictType = Dict [str , Optional [List ['Storage' ]]]
@@ -1247,16 +1256,16 @@ class Container:
1247
1256
"""
1248
1257
1249
1258
def __init__ (self , name : str , backend : '_ModelBackend' ,
1250
- pebble_client : Optional ['pebble. Client' ] = None ):
1259
+ pebble_client : Optional ['Client' ] = None ):
1251
1260
self .name = name
1252
1261
1253
1262
if pebble_client is None :
1254
1263
socket_path = '/charm/containers/{}/pebble.socket' .format (name )
1255
1264
pebble_client = backend .get_pebble (socket_path )
1256
- self ._pebble = pebble_client # type: 'pebble. Client'
1265
+ self ._pebble = pebble_client # type: 'Client'
1257
1266
1258
1267
@property
1259
- def pebble (self ) -> 'pebble. Client' :
1268
+ def pebble (self ) -> 'Client' :
1260
1269
"""The low-level :class:`ops.pebble.Client` instance for this container."""
1261
1270
return self ._pebble
1262
1271
@@ -1362,7 +1371,7 @@ def add_layer(self, label: str, layer: '_Layer', *, combine: bool = False):
1362
1371
# fixme: remove ignore once pebble.py is typed
1363
1372
self ._pebble .add_layer (label , layer , combine = combine ) # type: ignore
1364
1373
1365
- def get_plan (self ) -> 'pebble. Plan' :
1374
+ def get_plan (self ) -> 'Plan' :
1366
1375
"""Get the current effective pebble configuration."""
1367
1376
return self ._pebble .get_plan ()
1368
1377
@@ -1377,7 +1386,7 @@ def get_services(self, *service_names: str) -> '_ServiceInfoMapping':
1377
1386
services = self ._pebble .get_services (names ) # type: ignore
1378
1387
return ServiceInfoMapping (services )
1379
1388
1380
- def get_service (self , service_name : str ) -> 'pebble. ServiceInfo' :
1389
+ def get_service (self , service_name : str ) -> 'ServiceInfo' :
1381
1390
"""Get status information for a single named service.
1382
1391
1383
1392
Raises :class:`ModelError` if service_name is not found.
@@ -1392,7 +1401,7 @@ def get_service(self, service_name: str) -> 'pebble.ServiceInfo':
1392
1401
def get_checks (
1393
1402
self ,
1394
1403
* check_names : str ,
1395
- level : Optional ['pebble. CheckLevel' ] = None ) -> 'CheckInfoMapping' :
1404
+ level : Optional ['CheckLevel' ] = None ) -> 'CheckInfoMapping' :
1396
1405
"""Fetch and return a mapping of check information indexed by check name.
1397
1406
1398
1407
Args:
@@ -1405,7 +1414,7 @@ def get_checks(
1405
1414
checks = self ._pebble .get_checks (names = check_names or None , level = level ) # type: ignore
1406
1415
return CheckInfoMapping (checks )
1407
1416
1408
- def get_check (self , check_name : str ) -> 'pebble. CheckInfo' :
1417
+ def get_check (self , check_name : str ) -> 'CheckInfo' :
1409
1418
"""Get check information for a single named check.
1410
1419
1411
1420
Raises :class:`ModelError` if check_name is not found.
@@ -1471,7 +1480,7 @@ def push(self,
1471
1480
group_id = group_id , group = group ) # type: ignore
1472
1481
1473
1482
def list_files (self , path : StrOrPath , * , pattern : Optional [str ] = None ,
1474
- itself : bool = False ) -> List ['pebble. FileInfo' ]:
1483
+ itself : bool = False ) -> List ['FileInfo' ]:
1475
1484
"""Return list of directory entries from given path on remote system.
1476
1485
1477
1486
Despite the name, this method returns a list of files *and*
@@ -1644,7 +1653,7 @@ def pull_path(self,
1644
1653
raise MultiPushPullError ('failed to pull one or more files' , errors )
1645
1654
1646
1655
@staticmethod
1647
- def _build_fileinfo (path : StrOrPath ) -> 'pebble. FileInfo' :
1656
+ def _build_fileinfo (path : StrOrPath ) -> 'FileInfo' :
1648
1657
"""Constructs a FileInfo object by stat'ing a local path."""
1649
1658
path = Path (path )
1650
1659
if path .is_symlink ():
@@ -1673,8 +1682,8 @@ def _build_fileinfo(path: StrOrPath) -> 'pebble.FileInfo':
1673
1682
1674
1683
@staticmethod
1675
1684
def _list_recursive (list_func : Callable [[Path ],
1676
- Iterable ['pebble. FileInfo' ]],
1677
- path : Path ) -> Generator ['pebble. FileInfo' , None , None ]:
1685
+ Iterable ['FileInfo' ]],
1686
+ path : Path ) -> Generator ['FileInfo' , None , None ]:
1678
1687
"""Recursively lists all files under path using the given list_func.
1679
1688
1680
1689
Args:
@@ -1788,7 +1797,7 @@ def exec(
1788
1797
stderr : Optional [Union [TextIO , BinaryIO ]] = None ,
1789
1798
encoding : str = 'utf-8' ,
1790
1799
combine_stderr : bool = False
1791
- ) -> 'pebble. ExecProcess' :
1800
+ ) -> 'ExecProcess' :
1792
1801
"""Execute the given command on the remote system.
1793
1802
1794
1803
See :meth:`ops.pebble.Client.exec` for documentation of the parameters
@@ -1853,14 +1862,14 @@ def __repr__(self):
1853
1862
return repr (self ._containers )
1854
1863
1855
1864
1856
- class ServiceInfoMapping (Mapping [str , 'pebble. ServiceInfo' ]):
1865
+ class ServiceInfoMapping (Mapping [str , 'ServiceInfo' ]):
1857
1866
"""Map of service names to :class:`ops.pebble.ServiceInfo` objects.
1858
1867
1859
1868
This is done as a mapping object rather than a plain dictionary so that we
1860
1869
can extend it later, and so it's not mutable.
1861
1870
"""
1862
1871
1863
- def __init__ (self , services : Iterable ['pebble. ServiceInfo' ]):
1872
+ def __init__ (self , services : Iterable ['ServiceInfo' ]):
1864
1873
self ._services = {s .name : s for s in services }
1865
1874
1866
1875
def __getitem__ (self , key : str ):
@@ -1876,14 +1885,14 @@ def __repr__(self):
1876
1885
return repr (self ._services )
1877
1886
1878
1887
1879
- class CheckInfoMapping (Mapping [str , 'pebble. CheckInfo' ]):
1888
+ class CheckInfoMapping (Mapping [str , 'CheckInfo' ]):
1880
1889
"""Map of check names to :class:`ops.pebble.CheckInfo` objects.
1881
1890
1882
1891
This is done as a mapping object rather than a plain dictionary so that we
1883
1892
can extend it later, and so it's not mutable.
1884
1893
"""
1885
1894
1886
- def __init__ (self , checks : Iterable ['pebble. CheckInfo' ]):
1895
+ def __init__ (self , checks : Iterable ['CheckInfo' ]):
1887
1896
self ._checks = {c .name : c for c in checks }
1888
1897
1889
1898
def __getitem__ (self , key : str ):
@@ -2344,7 +2353,7 @@ def add_metrics(self, metrics: Mapping[str, 'Numerical'],
2344
2353
cmd .extend (metric_args )
2345
2354
self ._run (* cmd )
2346
2355
2347
- def get_pebble (self , socket_path : str ) -> 'pebble. Client' :
2356
+ def get_pebble (self , socket_path : str ) -> 'Client' :
2348
2357
"""Create a pebble.Client instance from given socket path."""
2349
2358
return pebble .Client (socket_path = socket_path )
2350
2359
0 commit comments