Skip to content

Commit b182233

Browse files
authored
fix: add fetch to packages protocol (#359)
1 parent 380a3ca commit b182233

File tree

3 files changed

+95
-20
lines changed

3 files changed

+95
-20
lines changed

src/posit/connect/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
if TYPE_CHECKING:
2525
from .environments import Environments
26-
from .packages import _Packages
26+
from .packages import Packages
2727

2828

2929
class Client(ContextManager):
@@ -299,7 +299,7 @@ def oauth(self) -> OAuth:
299299

300300
@property
301301
@requires(version="2024.11.0")
302-
def packages(self) -> _Packages:
302+
def packages(self) -> Packages:
303303
return _PaginatedResourceSequence(self._ctx, "v1/packages", uid="name")
304304

305305
@property

src/posit/connect/content.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
if TYPE_CHECKING:
3434
from .context import Context
3535
from .jobs import Jobs
36-
from .packages import _ContentPackages
36+
from .packages import ContentPackages
3737
from .tasks import Task
3838

3939

@@ -519,7 +519,7 @@ def jobs(self) -> Jobs:
519519

520520
@property
521521
@requires(version="2024.11.0")
522-
def packages(self) -> _ContentPackages:
522+
def packages(self) -> ContentPackages:
523523
path = posixpath.join(self._path, "packages")
524524
return _ResourceSequence(self._ctx, path, uid="name")
525525

src/posit/connect/packages.py

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,56 @@
11
from __future__ import annotations
22

3-
from collections.abc import Mapping, Sized
4-
from typing import Any, Literal, Protocol, SupportsIndex, overload
5-
6-
7-
class _ContentPackage(Mapping[str, Any]):
3+
from typing_extensions import (
4+
Any,
5+
Iterable,
6+
Literal,
7+
Mapping,
8+
Protocol,
9+
Sized,
10+
SupportsIndex,
11+
overload,
12+
)
13+
14+
15+
class ContentPackage(Mapping[str, Any]):
816
pass
917

1018

11-
class _ContentPackages(Sized, Protocol):
19+
class ContentPackages(Sized, Protocol):
1220
@overload
13-
def __getitem__(self, index: SupportsIndex) -> _ContentPackage: ...
21+
def __getitem__(self, index: SupportsIndex) -> ContentPackage: ...
1422

1523
@overload
16-
def __getitem__(self, index: slice) -> _ContentPackage: ...
24+
def __getitem__(self, index: slice) -> ContentPackage: ...
25+
26+
def fetch(
27+
self,
28+
*,
29+
language: Literal["python", "r"] = ...,
30+
name: str = ...,
31+
version: str = ...,
32+
hash: str | None = ..., # noqa: A002
33+
) -> Iterable[ContentPackage]:
34+
"""
35+
Fetch all records matching the specified conditions.
36+
37+
Parameters
38+
----------
39+
language : {"python", "r"}, not required
40+
Programming language ecosystem, options are 'python' and 'r'
41+
name : str, not required
42+
The package name
43+
version : str, not required
44+
The package version
45+
hash : str or None, optional, not required
46+
Package description hash for R packages.
47+
48+
Returns
49+
-------
50+
List[ContentPackage]
51+
The first record matching the specified conditions, or `None` if no such record exists.
52+
"""
53+
...
1754

1855
def find_by(
1956
self,
@@ -22,7 +59,7 @@ def find_by(
2259
name: str = ...,
2360
version: str = ...,
2461
hash: str | None = ..., # noqa: A002
25-
) -> _ContentPackage | None:
62+
) -> ContentPackage | None:
2663
"""
2764
Find the first record matching the specified conditions.
2865
@@ -41,22 +78,60 @@ def find_by(
4178
4279
Returns
4380
-------
44-
_ContentPackage | None
81+
ContentPackage | None
4582
The first record matching the specified conditions, or `None` if no such record exists.
4683
"""
4784
...
4885

4986

50-
class _Package(Mapping[str, Any]):
87+
class Package(Mapping[str, Any]):
5188
pass
5289

5390

54-
class _Packages(Sized, Protocol):
91+
class Packages(Sized, Protocol):
5592
@overload
56-
def __getitem__(self, index: SupportsIndex) -> _ContentPackage: ...
93+
def __getitem__(self, index: SupportsIndex) -> ContentPackage: ...
5794

5895
@overload
59-
def __getitem__(self, index: slice) -> _ContentPackage: ...
96+
def __getitem__(self, index: slice) -> ContentPackage: ...
97+
98+
def fetch(
99+
self,
100+
*,
101+
language: Literal["python", "r"] = ...,
102+
name: str = ...,
103+
version: str = ...,
104+
hash: str | None = ..., # noqa: A002,
105+
bundle_id: str = ...,
106+
app_id: str = ...,
107+
app_guid: str = ...,
108+
) -> Iterable[Package]:
109+
"""
110+
Fetch all records matching the specified conditions.
111+
112+
Parameters
113+
----------
114+
language : {"python", "r"}, not required
115+
Programming language ecosystem, options are 'python' and 'r'
116+
name : str, not required
117+
The package name
118+
version : str, not required
119+
The package version
120+
hash : str or None, optional, not required
121+
Package description hash for R packages.
122+
bundle_id: str, not required
123+
The unique identifier of the bundle this package is associated with.
124+
app_id: str, not required
125+
The numerical identifier of the application this package is associated with.
126+
app_guid: str, not required
127+
The unique identifier of the application this package is associated with.
128+
129+
Returns
130+
-------
131+
List[Package]
132+
The first record matching the specified conditions, or `None` if no such record exists.
133+
"""
134+
...
60135

61136
def find_by(
62137
self,
@@ -68,7 +143,7 @@ def find_by(
68143
bundle_id: str = ...,
69144
app_id: str = ...,
70145
app_guid: str = ...,
71-
) -> _ContentPackage | None:
146+
) -> Package | None:
72147
"""
73148
Find the first record matching the specified conditions.
74149
@@ -93,7 +168,7 @@ def find_by(
93168
94169
Returns
95170
-------
96-
_Package | None
171+
Package | None
97172
The first record matching the specified conditions, or `None` if no such record exists.
98173
"""
99174
...

0 commit comments

Comments
 (0)