Skip to content

Commit 53ffe59

Browse files
committed
feat: deprecates field access by attribute.
Removes all @Property annotated methods used for direct field access on concrete resources. A new __getattr__ implementation is added to Resource to maintain backwards compatiblity. This implementation calls __getitem__ when the key exists in self. A noisy deprecation warning is issued to alert users that this functionality will be removed in v1.0.0.
1 parent e98e0f2 commit 53ffe59

File tree

13 files changed

+111
-684
lines changed

13 files changed

+111
-684
lines changed

src/posit/connect/bundles.py

Lines changed: 13 additions & 133 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."""
14222
path = f"v1/content/{self.content_guid}/bundles/{self.id}"
143-
url = self.url + path
144-
self.session.delete(url)
23+
url = self.params.url + path
24+
self.params.session.delete(url)
14525

14626
def deploy(self) -> tasks.Task:
14727
"""Deploy the bundle.
@@ -160,8 +40,8 @@ def deploy(self) -> tasks.Task:
16040
None
16141
"""
16242
path = f"v1/content/{self.content_guid}/deploy"
163-
url = self.url + path
164-
response = self.session.post(url, json={"bundle_id": self.id})
43+
url = self.params.url + path
44+
response = self.params.session.post(url, json={"bundle_id": self.id})
16545
result = response.json()
16646
ts = tasks.Tasks(self.params)
16747
return ts.get(result["task_id"])
@@ -198,8 +78,8 @@ def download(self, output: io.BufferedWriter | str) -> None:
19878
)
19979

20080
path = f"v1/content/{self.content_guid}/bundles/{self.id}/download"
201-
url = self.url + path
202-
response = self.session.get(url, stream=True)
81+
url = self.params.url + path
82+
response = self.params.session.get(url, stream=True)
20383
if isinstance(output, io.BufferedWriter):
20484
for chunk in response.iter_content():
20585
output.write(chunk)
@@ -284,8 +164,8 @@ def create(self, archive: io.BufferedReader | bytes | str) -> Bundle:
284164
)
285165

286166
path = f"v1/content/{self.content_guid}/bundles"
287-
url = self.url + path
288-
response = self.session.post(url, data=data)
167+
url = self.params.url + path
168+
response = self.params.session.post(url, data=data)
289169
result = response.json()
290170
return Bundle(self.params, **result)
291171

@@ -298,8 +178,8 @@ def find(self) -> List[Bundle]:
298178
List of all found bundles.
299179
"""
300180
path = f"v1/content/{self.content_guid}/bundles"
301-
url = self.url + path
302-
response = self.session.get(url)
181+
url = self.params.url + path
182+
response = self.params.session.get(url)
303183
results = response.json()
304184
return [Bundle(self.params, **result) for result in results]
305185

@@ -328,7 +208,7 @@ def get(self, uid: str) -> Bundle:
328208
The bundle with the specified ID.
329209
"""
330210
path = f"v1/content/{self.content_guid}/bundles/{uid}"
331-
url = self.url + path
332-
response = self.session.get(url)
211+
url = self.params.url + path
212+
response = self.params.session.get(url)
333213
result = response.json()
334214
return Bundle(self.params, **result)

0 commit comments

Comments
 (0)