Skip to content

Commit e349870

Browse files
committed
add link to parent
1 parent 279fcd6 commit e349870

File tree

3 files changed

+47
-14
lines changed

3 files changed

+47
-14
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
from pathlib import Path
2+
3+
from posit import connect
4+
5+
6+
class TestContent:
7+
@classmethod
8+
def setup_class(cls):
9+
cls.client = connect.Client()
10+
cls.content = cls.client.content.create(name="example-quarto-minimal")
11+
12+
@classmethod
13+
def teardown_class(cls):
14+
cls.content.delete()
15+
assert cls.client.content.count() == 0
16+
17+
def test(self):
18+
content = self.content
19+
20+
path = Path("../../../resources/connect/bundles/example-quarto-minimal/bundle.tar.gz")
21+
path = Path(__file__).parent / path
22+
path = path.resolve()
23+
path = str(path)
24+
25+
bundle = content.bundles.create(path)
26+
bundle.deploy()
27+
28+
jobs = content.jobs
29+
assert len(jobs) == 1

src/posit/connect/jobs.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,12 +99,13 @@ class _Job(TypedDict):
9999
tag: Required[JobTag]
100100
"""A tag categorizing the job type. Options are build_jupyter, build_report, build_site, configure_report, git, packrat_restore, python_restore, render_shiny, run_api, run_app, run_bokeh_app, run_dash_app, run_fastapi_app, run_pyshiny_app, run_python_api, run_streamlit, run_tensorflow, run_voila_app, testing, unknown, val_py_ext_pkg, val_r_ext_pkg, and val_r_install."""
101101

102-
def __init__(self, /, params, **kwargs: Unpack[_Job]):
103-
super().__init__(params, **kwargs)
102+
def __init__(self, ctx, parent: Active, **kwargs: Unpack[_Job]):
103+
super().__init__(ctx, parent, **kwargs)
104+
self._parent = parent
104105

105106
@property
106107
def _endpoint(self) -> str:
107-
return self._ctx.url + f"v1/content/{self['app_id']}/jobs/{self['key']}"
108+
return self._ctx.url + f"v1/content/{self._parent['guid']}/jobs/{self['key']}"
108109

109110
def destroy(self) -> None:
110111
"""Destroy the job.
@@ -128,7 +129,7 @@ class Jobs(ActiveFinderMethods[Job]):
128129
_uid = "key"
129130

130131
def __init__(self, cls, ctx, parent: Active):
131-
super().__init__(cls, ctx)
132+
super().__init__(cls, ctx, parent)
132133
self._parent = parent
133134

134135
@property
@@ -267,11 +268,6 @@ def find_by(self, **conditions) -> Optional[Job]:
267268
class JobsMixin(Active, Resource):
268269
"""Mixin class to add a jobs attribute to a resource."""
269270

270-
class HasGuid(TypedDict):
271-
"""Has a guid."""
272-
273-
guid: Required[str]
274-
275271
def __init__(self, ctx, **kwargs):
276272
super().__init__(ctx, **kwargs)
277273
self.jobs = Jobs(Job, ctx, self)

src/posit/connect/resources.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import warnings
33
from abc import ABC, abstractmethod
44
from dataclasses import dataclass
5-
from typing import Any, Generic, List, Optional, Sequence, Type, TypeVar
5+
from typing import Any, Generic, List, Optional, Sequence, Type, TypeVar, overload
66

77
import requests
88

@@ -54,17 +54,19 @@ def __init__(self, params: ResourceParameters) -> None:
5454

5555

5656
class Active(Resource):
57-
def __init__(self, ctx: Context, **kwargs):
57+
def __init__(self, ctx: Context, parent: Optional["Active"] = None, **kwargs):
5858
params = ResourceParameters(ctx.session, ctx.url)
5959
super().__init__(params, **kwargs)
6060
self._ctx = ctx
61+
self._parent = parent
6162

6263

6364
class ActiveReader(ABC, Generic[T], Sequence[T]):
64-
def __init__(self, cls: Type[T], ctx: Context):
65+
def __init__(self, cls: Type[T], ctx: Context, parent: Optional[Active] = None):
6566
super().__init__()
6667
self._cls = cls
6768
self._ctx = ctx
69+
self._parent = parent
6870
self._cache = None
6971

7072
@property
@@ -79,9 +81,15 @@ def _data(self) -> List[T]:
7981

8082
response = self._ctx.session.get(self._endpoint)
8183
results = response.json()
82-
self._cache = [self._cls(self._ctx, **result) for result in results]
84+
self._cache = [self._cls(self._ctx, self._parent, **result) for result in results]
8385
return self._cache
8486

87+
@overload
88+
def __getitem__(self, index: int) -> T: ...
89+
90+
@overload
91+
def __getitem__(self, index: slice) -> Sequence[T]: ...
92+
8593
def __getitem__(self, index):
8694
"""Retrieve an item or slice from the sequence."""
8795
return self._data[index]
@@ -112,7 +120,7 @@ def find(self, uid) -> T:
112120
endpoint = posixpath.join(self._endpoint + uid)
113121
response = self._ctx.session.get(endpoint)
114122
result = response.json()
115-
result = self._cls(self._ctx, **result)
123+
result = self._cls(self._ctx, self._parent, **result)
116124

117125
if not result:
118126
raise ValueError("")

0 commit comments

Comments
 (0)