Skip to content

Commit 0bf05c1

Browse files
committed
add return types, more positconnectservers
1 parent 6b4ef79 commit 0bf05c1

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

rsconnect/api.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ def __init__(
259259
self.api_key = None
260260
self.bootstrap_jwt = None
261261

262-
def token_endpoint(self):
262+
def token_endpoint(self) -> str:
263263
params = get_connection_parameters(self.snowflake_connection_name)
264264

265265
if params is None:
266266
raise RSConnectException("No Snowflake connection found.")
267267

268268
return "https://{}.snowflakecomputing.com/".format(params["account"])
269269

270-
def fmt_payload(self):
270+
def fmt_payload(self) -> str:
271271
params = get_connection_parameters(self.snowflake_connection_name)
272272

273273
if params is None:
@@ -282,7 +282,7 @@ def fmt_payload(self):
282282
payload = urlencode(payload)
283283
return payload
284284

285-
def exchange_token(self):
285+
def exchange_token(self) -> str | bytes:
286286
try:
287287
server = HTTPServer(url=self.token_endpoint())
288288
payload = self.fmt_payload()
@@ -1880,7 +1880,7 @@ def verify_api_key(connect_server: RSConnectServer) -> str:
18801880
return result["username"]
18811881

18821882

1883-
def get_python_info(connect_server: RSConnectServer):
1883+
def get_python_info(connect_server: PositConnectServer):
18841884
"""
18851885
Return information about versions of Python that are installed on the indicated
18861886
Connect server.
@@ -1894,7 +1894,7 @@ def get_python_info(connect_server: RSConnectServer):
18941894
return result
18951895

18961896

1897-
def get_app_info(connect_server: RSConnectServer, app_id: str):
1897+
def get_app_info(connect_server: PositConnectServer, app_id: str):
18981898
"""
18991899
Return information about an application that has been created in Connect.
19001900
@@ -1915,7 +1915,7 @@ def get_posit_app_info(server: PositServer, app_id: str):
19151915
return response["source"]
19161916

19171917

1918-
def get_app_config(connect_server: RSConnectServer, app_id: str):
1918+
def get_app_config(connect_server: PositConnectServer, app_id: str):
19191919
"""
19201920
Return the configuration information for an application that has been created
19211921
in Connect.
@@ -1931,7 +1931,7 @@ def get_app_config(connect_server: RSConnectServer, app_id: str):
19311931

19321932

19331933
def emit_task_log(
1934-
connect_server: RSConnectServer,
1934+
connect_server: PositConnectServer,
19351935
app_id: str,
19361936
task_id: str,
19371937
log_callback: Optional[Callable[[str], None]],
@@ -1967,7 +1967,7 @@ def emit_task_log(
19671967

19681968

19691969
def retrieve_matching_apps(
1970-
connect_server: RSConnectServer,
1970+
connect_server: PositConnectServer,
19711971
filters: Optional[dict[str, str | int]] = None,
19721972
limit: Optional[int] = None,
19731973
mapping_function: Optional[Callable[[RSConnectClient, ContentItemV0], AbbreviatedAppItem | None]] = None,
@@ -2043,7 +2043,7 @@ class AbbreviatedAppItem(TypedDict):
20432043
config_url: str
20442044

20452045

2046-
def override_title_search(connect_server: RSConnectServer, app_id: str, app_title: str):
2046+
def override_title_search(connect_server: PositConnectServer, app_id: str, app_title: str):
20472047
"""
20482048
Returns a list of abbreviated app data that contains apps with a title
20492049
that matches the given one and/or the specific app noted by its ID.
@@ -2124,7 +2124,7 @@ def find_unique_name(remote_server: TargetableServer, name: str):
21242124
:param name: the default name for an app.
21252125
:return: the name, potentially with a suffixed number to guarantee uniqueness.
21262126
"""
2127-
if isinstance(remote_server, RSConnectServer):
2127+
if isinstance(remote_server, PositConnectServer):
21282128
existing_names = retrieve_matching_apps(
21292129
remote_server,
21302130
filters={"search": name},

rsconnect/metadata.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828

2929

3030
if TYPE_CHECKING:
31-
from .api import RSConnectServer
31+
from .api import PositConnectServer
3232

3333
from .exception import RSConnectException
3434
from .log import logger
@@ -602,7 +602,7 @@ class ContentBuildStore(DataStore[Dict[str, object]]):
602602

603603
def __init__(
604604
self,
605-
server: RSConnectServer,
605+
server: PositConnectServer,
606606
base_dir: str = os.getenv("CONNECT_CONTENT_BUILD_DIR", DEFAULT_BUILD_DIR),
607607
):
608608
# This type declaration is a bit of a hack. It is needed because data model used

rsconnect/snowflake.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
1+
# pyright: reportMissingTypeStubs=false, reportUnusedImport=false
12
import json
2-
from subprocess import CalledProcessError, run
3-
from typing import Optional
3+
from subprocess import CalledProcessError, CompletedProcess, run
4+
from typing import Any, Dict, List, Optional
45

56
from .exception import RSConnectException
67
from .log import logger
78

89

9-
def snow(*args: str):
10+
def snow(*args: str) -> CompletedProcess[str]:
1011
ensure_snow_installed()
1112
return run(["snow"] + list(args), capture_output=True, text=True, check=True)
1213

1314

1415
def ensure_snow_installed() -> None:
1516
try:
16-
import snowflake.cli # noqa
17+
import snowflake.cli # noqa: F401
1718

1819
logger.debug("snowflake-cli is installed.")
1920

@@ -27,7 +28,7 @@ def ensure_snow_installed() -> None:
2728
raise RSConnectException("snow cannot be found.")
2829

2930

30-
def list_connections():
31+
def list_connections() -> List[Dict[str, Any]]:
3132

3233
try:
3334
res = snow("connection", "list", "--format", "json")
@@ -37,7 +38,7 @@ def list_connections():
3738
raise RSConnectException("Could not list snowflake connections.")
3839

3940

40-
def get_connection_parameters(name: Optional[str] = None):
41+
def get_connection_parameters(name: Optional[str] = None) -> Optional[Dict[str, Any]]:
4142

4243
connection_list = list_connections()
4344
# return parameters for default connection if configured
@@ -55,7 +56,7 @@ def get_connection_parameters(name: Optional[str] = None):
5556
raise RSConnectException(f"No Snowflake connection found with name '{name}'.")
5657

5758

58-
def generate_jwt(name: Optional[str] = None):
59+
def generate_jwt(name: Optional[str] = None) -> str:
5960

6061
_ = get_connection_parameters(name)
6162
connection_name = "" if name is None else name

0 commit comments

Comments
 (0)