Skip to content

Commit 4e64f39

Browse files
PietroPasottirwcarlsen
authored andcommitted
fixed issue with pebble imports (#810)
1 parent 1c58468 commit 4e64f39

File tree

1 file changed

+26
-17
lines changed

1 file changed

+26
-17
lines changed

ops/model.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@
5555
from ops.jujuversion import JujuVersion
5656

5757
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+
)
5867
from typing_extensions import TypedDict
5968

6069
_StorageDictType = Dict[str, Optional[List['Storage']]]
@@ -1247,16 +1256,16 @@ class Container:
12471256
"""
12481257

12491258
def __init__(self, name: str, backend: '_ModelBackend',
1250-
pebble_client: Optional['pebble.Client'] = None):
1259+
pebble_client: Optional['Client'] = None):
12511260
self.name = name
12521261

12531262
if pebble_client is None:
12541263
socket_path = '/charm/containers/{}/pebble.socket'.format(name)
12551264
pebble_client = backend.get_pebble(socket_path)
1256-
self._pebble = pebble_client # type: 'pebble.Client'
1265+
self._pebble = pebble_client # type: 'Client'
12571266

12581267
@property
1259-
def pebble(self) -> 'pebble.Client':
1268+
def pebble(self) -> 'Client':
12601269
"""The low-level :class:`ops.pebble.Client` instance for this container."""
12611270
return self._pebble
12621271

@@ -1362,7 +1371,7 @@ def add_layer(self, label: str, layer: '_Layer', *, combine: bool = False):
13621371
# fixme: remove ignore once pebble.py is typed
13631372
self._pebble.add_layer(label, layer, combine=combine) # type: ignore
13641373

1365-
def get_plan(self) -> 'pebble.Plan':
1374+
def get_plan(self) -> 'Plan':
13661375
"""Get the current effective pebble configuration."""
13671376
return self._pebble.get_plan()
13681377

@@ -1377,7 +1386,7 @@ def get_services(self, *service_names: str) -> '_ServiceInfoMapping':
13771386
services = self._pebble.get_services(names) # type: ignore
13781387
return ServiceInfoMapping(services)
13791388

1380-
def get_service(self, service_name: str) -> 'pebble.ServiceInfo':
1389+
def get_service(self, service_name: str) -> 'ServiceInfo':
13811390
"""Get status information for a single named service.
13821391
13831392
Raises :class:`ModelError` if service_name is not found.
@@ -1392,7 +1401,7 @@ def get_service(self, service_name: str) -> 'pebble.ServiceInfo':
13921401
def get_checks(
13931402
self,
13941403
*check_names: str,
1395-
level: Optional['pebble.CheckLevel'] = None) -> 'CheckInfoMapping':
1404+
level: Optional['CheckLevel'] = None) -> 'CheckInfoMapping':
13961405
"""Fetch and return a mapping of check information indexed by check name.
13971406
13981407
Args:
@@ -1405,7 +1414,7 @@ def get_checks(
14051414
checks = self._pebble.get_checks(names=check_names or None, level=level) # type: ignore
14061415
return CheckInfoMapping(checks)
14071416

1408-
def get_check(self, check_name: str) -> 'pebble.CheckInfo':
1417+
def get_check(self, check_name: str) -> 'CheckInfo':
14091418
"""Get check information for a single named check.
14101419
14111420
Raises :class:`ModelError` if check_name is not found.
@@ -1471,7 +1480,7 @@ def push(self,
14711480
group_id=group_id, group=group) # type: ignore
14721481

14731482
def list_files(self, path: StrOrPath, *, pattern: Optional[str] = None,
1474-
itself: bool = False) -> List['pebble.FileInfo']:
1483+
itself: bool = False) -> List['FileInfo']:
14751484
"""Return list of directory entries from given path on remote system.
14761485
14771486
Despite the name, this method returns a list of files *and*
@@ -1644,7 +1653,7 @@ def pull_path(self,
16441653
raise MultiPushPullError('failed to pull one or more files', errors)
16451654

16461655
@staticmethod
1647-
def _build_fileinfo(path: StrOrPath) -> 'pebble.FileInfo':
1656+
def _build_fileinfo(path: StrOrPath) -> 'FileInfo':
16481657
"""Constructs a FileInfo object by stat'ing a local path."""
16491658
path = Path(path)
16501659
if path.is_symlink():
@@ -1673,8 +1682,8 @@ def _build_fileinfo(path: StrOrPath) -> 'pebble.FileInfo':
16731682

16741683
@staticmethod
16751684
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]:
16781687
"""Recursively lists all files under path using the given list_func.
16791688
16801689
Args:
@@ -1788,7 +1797,7 @@ def exec(
17881797
stderr: Optional[Union[TextIO, BinaryIO]] = None,
17891798
encoding: str = 'utf-8',
17901799
combine_stderr: bool = False
1791-
) -> 'pebble.ExecProcess':
1800+
) -> 'ExecProcess':
17921801
"""Execute the given command on the remote system.
17931802
17941803
See :meth:`ops.pebble.Client.exec` for documentation of the parameters
@@ -1853,14 +1862,14 @@ def __repr__(self):
18531862
return repr(self._containers)
18541863

18551864

1856-
class ServiceInfoMapping(Mapping[str, 'pebble.ServiceInfo']):
1865+
class ServiceInfoMapping(Mapping[str, 'ServiceInfo']):
18571866
"""Map of service names to :class:`ops.pebble.ServiceInfo` objects.
18581867
18591868
This is done as a mapping object rather than a plain dictionary so that we
18601869
can extend it later, and so it's not mutable.
18611870
"""
18621871

1863-
def __init__(self, services: Iterable['pebble.ServiceInfo']):
1872+
def __init__(self, services: Iterable['ServiceInfo']):
18641873
self._services = {s.name: s for s in services}
18651874

18661875
def __getitem__(self, key: str):
@@ -1876,14 +1885,14 @@ def __repr__(self):
18761885
return repr(self._services)
18771886

18781887

1879-
class CheckInfoMapping(Mapping[str, 'pebble.CheckInfo']):
1888+
class CheckInfoMapping(Mapping[str, 'CheckInfo']):
18801889
"""Map of check names to :class:`ops.pebble.CheckInfo` objects.
18811890
18821891
This is done as a mapping object rather than a plain dictionary so that we
18831892
can extend it later, and so it's not mutable.
18841893
"""
18851894

1886-
def __init__(self, checks: Iterable['pebble.CheckInfo']):
1895+
def __init__(self, checks: Iterable['CheckInfo']):
18871896
self._checks = {c.name: c for c in checks}
18881897

18891898
def __getitem__(self, key: str):
@@ -2344,7 +2353,7 @@ def add_metrics(self, metrics: Mapping[str, 'Numerical'],
23442353
cmd.extend(metric_args)
23452354
self._run(*cmd)
23462355

2347-
def get_pebble(self, socket_path: str) -> 'pebble.Client':
2356+
def get_pebble(self, socket_path: str) -> 'Client':
23482357
"""Create a pebble.Client instance from given socket path."""
23492358
return pebble.Client(socket_path=socket_path)
23502359

0 commit comments

Comments
 (0)