Skip to content

Commit 894a9e7

Browse files
authored
refactor!: drop support field access by attribute. (#271)
BREAKING CHANGE: removes support for accessing resource fields using `__getattr__` (e.g., `user.username`). Use `__getitem__` instead (e.g., `user["username"]`. depends on #265 and #266 closes #262
1 parent 77941bb commit 894a9e7

File tree

20 files changed

+173
-1111
lines changed

20 files changed

+173
-1111
lines changed

integration/tests/posit/connect/test_content.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_count(self):
2323
assert self.client.content.count() == 1
2424

2525
def test_get(self):
26-
assert self.client.content.get(self.content.guid) == self.content
26+
assert self.client.content.get(self.content["guid"]) == self.content
2727

2828
def test_find(self):
2929
assert self.client.content.find()
@@ -34,12 +34,12 @@ def test_find_one(self):
3434
def test_content_item_owner(self):
3535
item = self.client.content.find_one(include=None)
3636
owner = item.owner
37-
assert owner.guid == self.client.me.guid
37+
assert owner["guid"] == self.client.me["guid"]
3838

3939
def test_content_item_owner_from_include(self):
4040
item = self.client.content.find_one(include="owner")
4141
owner = item.owner
42-
assert owner.guid == self.client.me.guid
42+
assert owner["guid"] == self.client.me["guid"]
4343

4444
@pytest.mark.skipif(
4545
CONNECT_VERSION <= version.parse("2024.04.1"),

integration/tests/posit/connect/test_groups.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_count(self):
1414
assert self.client.groups.count() == 1
1515

1616
def test_get(self):
17-
assert self.client.groups.get(self.item.guid)
17+
assert self.client.groups.get(self.item["guid"])
1818

1919
def test_find(self):
2020
assert self.client.groups.find() == [self.item]

src/posit/connect/bundles.py

Lines changed: 20 additions & 136 deletions
Original file line numberDiff line numberDiff line change
@@ -9,139 +9,19 @@
99

1010

1111
class BundleMetadata(resources.Resource):
12-
"""Bundle metadata resource.
13-
14-
Attributes
15-
----------
16-
source : str | None
17-
Source of the bundle.
18-
source_repo : str | None
19-
Source repository of the bundle.
20-
source_branch : str | None
21-
Source branch of the bundle.
22-
source_commit : str | None
23-
Source commit of the bundle.
24-
archive_md5 : str | None
25-
MD5 checksum of the bundle archive.
26-
archive_sha1 : str | None
27-
SHA-1 checksum of the bundle archive.
28-
"""
29-
30-
@property
31-
def source(self) -> str | None:
32-
return self.get("source")
33-
34-
@property
35-
def source_repo(self) -> str | None:
36-
return self.get("source_repo")
37-
38-
@property
39-
def source_branch(self) -> str | None:
40-
return self.get("source_branch")
41-
42-
@property
43-
def source_commit(self) -> str | None:
44-
return self.get("source_commit")
45-
46-
@property
47-
def archive_md5(self) -> str | None:
48-
return self.get("archive_md5")
49-
50-
@property
51-
def archive_sha1(self) -> str | None:
52-
return self.get("archive_sha1")
12+
pass
5313

5414

5515
class Bundle(resources.Resource):
56-
"""Bundle resource.
57-
58-
Attributes
59-
----------
60-
id : str
61-
Identifier of the bundle.
62-
content_guid : str
63-
Content GUID of the bundle.
64-
created_time : str
65-
Creation time of the bundle.
66-
cluster_name : str | None
67-
Cluster name associated with the bundle.
68-
image_name : str | None
69-
Image name of the bundle.
70-
r_version : str | None
71-
R version used in the bundle.
72-
r_environment_management : bool | None
73-
Indicates if R environment management is enabled.
74-
py_version : str | None
75-
Python version used in the bundle.
76-
py_environment_management : bool | None
77-
Indicates if Python environment management is enabled.
78-
quarto_version : str | None
79-
Quarto version used in the bundle.
80-
active : bool | None
81-
Indicates if the bundle is active.
82-
size : int | None
83-
Size of the bundle.
84-
metadata : BundleMetadata
85-
Metadata of the bundle.
86-
"""
87-
88-
@property
89-
def id(self) -> str:
90-
return self["id"]
91-
92-
@property
93-
def content_guid(self) -> str:
94-
return self["content_guid"]
95-
96-
@property
97-
def created_time(self) -> str:
98-
return self["created_time"]
99-
100-
@property
101-
def cluster_name(self) -> str | None:
102-
return self.get("cluster_name")
103-
104-
@property
105-
def image_name(self) -> str | None:
106-
return self.get("image_name")
107-
108-
@property
109-
def r_version(self) -> str | None:
110-
return self.get("r_version")
111-
112-
@property
113-
def r_environment_management(self) -> bool | None:
114-
return self.get("r_environment_management")
115-
116-
@property
117-
def py_version(self) -> str | None:
118-
return self.get("py_version")
119-
120-
@property
121-
def py_environment_management(self) -> bool | None:
122-
return self.get("py_environment_management")
123-
124-
@property
125-
def quarto_version(self) -> str | None:
126-
return self.get("quarto_version")
127-
128-
@property
129-
def active(self) -> bool | None:
130-
return self["active"]
131-
132-
@property
133-
def size(self) -> int | None:
134-
return self["size"]
135-
13616
@property
13717
def metadata(self) -> BundleMetadata:
13818
return BundleMetadata(self.params, **self.get("metadata", {}))
13919

14020
def delete(self) -> None:
14121
"""Delete the bundle."""
142-
path = f"v1/content/{self.content_guid}/bundles/{self.id}"
143-
url = self.url + path
144-
self.session.delete(url)
22+
path = f"v1/content/{self['content_guid']}/bundles/{self['id']}"
23+
url = self.params.url + path
24+
self.params.session.delete(url)
14525

14626
def deploy(self) -> tasks.Task:
14727
"""Deploy the bundle.
@@ -159,9 +39,11 @@ def deploy(self) -> tasks.Task:
15939
>>> task.wait_for()
16040
None
16141
"""
162-
path = f"v1/content/{self.content_guid}/deploy"
163-
url = self.url + path
164-
response = self.session.post(url, json={"bundle_id": self.id})
42+
path = f"v1/content/{self['content_guid']}/deploy"
43+
url = self.params.url + path
44+
response = self.params.session.post(
45+
url, json={"bundle_id": self["id"]}
46+
)
16547
result = response.json()
16648
ts = tasks.Tasks(self.params)
16749
return ts.get(result["task_id"])
@@ -197,9 +79,11 @@ def download(self, output: io.BufferedWriter | str) -> None:
19779
f"download() expected argument type 'io.BufferedWriter` or 'str', but got '{type(output).__name__}'"
19880
)
19981

200-
path = f"v1/content/{self.content_guid}/bundles/{self.id}/download"
201-
url = self.url + path
202-
response = self.session.get(url, stream=True)
82+
path = (
83+
f"v1/content/{self['content_guid']}/bundles/{self['id']}/download"
84+
)
85+
url = self.params.url + path
86+
response = self.params.session.get(url, stream=True)
20387
if isinstance(output, io.BufferedWriter):
20488
for chunk in response.iter_content():
20589
output.write(chunk)
@@ -284,8 +168,8 @@ def create(self, archive: io.BufferedReader | bytes | str) -> Bundle:
284168
)
285169

286170
path = f"v1/content/{self.content_guid}/bundles"
287-
url = self.url + path
288-
response = self.session.post(url, data=data)
171+
url = self.params.url + path
172+
response = self.params.session.post(url, data=data)
289173
result = response.json()
290174
return Bundle(self.params, **result)
291175

@@ -298,8 +182,8 @@ def find(self) -> List[Bundle]:
298182
List of all found bundles.
299183
"""
300184
path = f"v1/content/{self.content_guid}/bundles"
301-
url = self.url + path
302-
response = self.session.get(url)
185+
url = self.params.url + path
186+
response = self.params.session.get(url)
303187
results = response.json()
304188
return [Bundle(self.params, **result) for result in results]
305189

@@ -328,7 +212,7 @@ def get(self, uid: str) -> Bundle:
328212
The bundle with the specified ID.
329213
"""
330214
path = f"v1/content/{self.content_guid}/bundles/{uid}"
331-
url = self.url + path
332-
response = self.session.get(url)
215+
url = self.params.url + path
216+
response = self.params.session.get(url)
333217
result = response.json()
334218
return Bundle(self.params, **result)

0 commit comments

Comments
 (0)