Skip to content
Merged
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ requires-python = ">=3.8"

dependencies = [
"six>=1.14.0",
"click>=7.0.0",
"pip>=10.0.0",
"semver>=2.0.0,<3.0.0",
"pyjwt>=2.4.0",
Expand Down
16 changes: 7 additions & 9 deletions rsconnect/actions.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Public API for managing settings and deploying content.
"""
from __future__ import annotations

import contextlib
import json
Expand All @@ -11,7 +12,8 @@
import subprocess
import sys
import traceback
from typing import IO
import typing
from typing import IO, Optional
from warnings import warn
from os.path import abspath, basename, dirname, exists, isdir, join, relpath, splitext
from .exception import RSConnectException
Expand Down Expand Up @@ -46,10 +48,6 @@
import click
from six.moves.urllib_parse import urlparse

try:
import typing
except ImportError:
typing = None

line_width = 45
_module_pattern = re.compile(r"^[A-Za-z0-9_]+:[A-Za-z0-9_]+$")
Expand Down Expand Up @@ -153,7 +151,7 @@ def inspect_environment(
return MakeEnvironment(**json.loads(environment_json)) # type: ignore


def _verify_server(connect_server):
def _verify_server(connect_server: api.RSConnectServer):
"""
Test whether the server identified by the given full URL can be reached and is
running Connect.
Expand Down Expand Up @@ -188,7 +186,7 @@ def _to_server_check_list(url):
return [item % url for item in items]


def test_server(connect_server):
def test_server(connect_server: api.RSConnectServer) -> tuple[api.RSConnectServer, object]:
"""
Test whether the given server can be reached and is running Connect. The server
may be provided with or without a scheme. If a scheme is omitted, the server will
Expand Down Expand Up @@ -228,7 +226,7 @@ def test_rstudio_server(server: api.PositServer):
raise RSConnectException("Failed to verify with {} ({}).".format(server.remote_name, exc))


def test_api_key(connect_server):
def test_api_key(connect_server: api.RSConnectServer) -> str:
"""
Test that an API Key may be used to authenticate with the given Posit Connect server.
If the API key verifies, we return the username of the associated user.
Expand Down Expand Up @@ -424,7 +422,7 @@ def validate_entry_point(entry_point, directory):
return entry_point


def which_quarto(quarto=None):
def which_quarto(quarto: Optional[str] = None) -> str:
"""
Identify a valid Quarto executable. When a Quarto location is not provided
as input, an attempt is made to discover Quarto from the PATH and other
Expand Down
15 changes: 11 additions & 4 deletions rsconnect/actions_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,16 @@
Public API for administering content.
"""

from __future__ import annotations

import json
import time
import traceback
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime, timedelta
import semver

from .api import RSConnectClient, emit_task_log
from .api import RSConnectClient, RSConnectServer, emit_task_log
from .log import logger
from .models import BuildStatus, ContentGuidWithBundle
from .metadata import ContentBuildStore
Expand All @@ -18,7 +20,7 @@
_content_build_store = None # type: ContentBuildStore


def init_content_build_store(connect_server):
def init_content_build_store(connect_server: RSConnectServer):
global _content_build_store
if not _content_build_store:
logger.info("Initializing ContentBuildStore for %s" % connect_server.url)
Expand Down Expand Up @@ -64,7 +66,12 @@ def build_add_content(connect_server, content_guids_with_bundle):
_content_build_store.set_content_item_build_status(content["guid"], BuildStatus.NEEDS_BUILD)


def build_remove_content(connect_server, guid, all=False, purge=False):
def build_remove_content(
connect_server: RSConnectServer,
guid: str,
all: bool = False,
purge: bool = False,
) -> list[str]:
"""
:return: A list of guids of the content items that were removed
"""
Expand All @@ -73,7 +80,7 @@ def build_remove_content(connect_server, guid, all=False, purge=False):
raise RSConnectException(
"There is a build running on this server, " + "please wait for it to finish before removing content."
)
guids = [guid]
guids: list[str] = [guid]
if all:
guids = [c["guid"] for c in _content_build_store.get_content_items()]
for guid in guids:
Expand Down
4 changes: 2 additions & 2 deletions rsconnect/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -1454,7 +1454,7 @@ def do_deploy(self, bundle_id, app_id):
raise e


def verify_server(connect_server):
def verify_server(connect_server: RSConnectServer):
"""
Verify that the given server information represents a Connect instance that is
reachable, active and appears to be actually running Posit Connect. If the
Expand All @@ -1473,7 +1473,7 @@ def verify_server(connect_server):
raise RSConnectException("There is an SSL/TLS configuration problem: %s" % ssl_error)


def verify_api_key(connect_server):
def verify_api_key(connect_server: RSConnectServer) -> str:
"""
Verify that an API Key may be used to authenticate with the given Posit Connect server.
If the API key verifies, we return the username of the associated user.
Expand Down
48 changes: 24 additions & 24 deletions rsconnect/bundle.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from mimetypes import guess_type
from pathlib import Path
from copy import deepcopy
from typing import Optional, Any
from typing import Optional, Any, Sequence
import click

from os.path import basename, dirname, exists, isdir, join, relpath, splitext, isfile, abspath
Expand Down Expand Up @@ -844,12 +844,12 @@ def make_api_manifest(
entry_point: str,
app_mode: AppMode,
environment: Environment,
extra_files: list[str],
excludes: list[str],
extra_files: Sequence[str],
excludes: Sequence[str],
image: Optional[str] = None,
env_management_py: Optional[bool] = None,
env_management_r: Optional[bool] = None,
) -> typing.Tuple[typing.Dict[str, typing.Any], typing.List[str]]:
) -> tuple[dict[str, Any], list[str]]:
"""
Makes a manifest for an API.

Expand Down Expand Up @@ -1237,8 +1237,8 @@ def make_api_bundle(

def _create_quarto_file_list(
directory: str,
extra_files: typing.List[str],
excludes: typing.List[str],
extra_files: Sequence[str],
excludes: Sequence[str],
) -> typing.List[str]:
"""
Builds a full list of files under the given directory that should be included
Expand Down Expand Up @@ -1269,8 +1269,8 @@ def make_quarto_manifest(
quarto_inspection: typing.Dict[str, typing.Any],
app_mode: AppMode,
environment: Environment,
extra_files: typing.List[str],
excludes: typing.List[str],
extra_files: Sequence[str],
excludes: Sequence[str],
image: str = None,
env_management_py: bool = None,
env_management_r: bool = None,
Expand Down Expand Up @@ -1406,7 +1406,7 @@ def validate_extra_files(directory: str, extra_files: typing.Sequence[str], use_
return result


def validate_manifest_file(file_or_directory):
def validate_manifest_file(file_or_directory: str) -> str:
"""
Validates that the name given represents either an existing manifest.json file or
a directory that contains one. If not, an exception is raised.
Expand Down Expand Up @@ -1674,12 +1674,12 @@ def write_notebook_manifest_json(
entry_point_file: str,
environment: Environment,
app_mode: AppMode,
extra_files: typing.List[str],
hide_all_input: bool,
hide_tagged_input: bool,
image: str = None,
env_management_py: bool = None,
env_management_r: bool = None,
extra_files: Sequence[str],
hide_all_input: Optional[bool],
hide_tagged_input: Optional[bool],
image: Optional[str] = None,
env_management_py: Optional[bool] = None,
env_management_r: Optional[bool] = None,
) -> bool:
"""
Creates and writes a manifest.json file for the given entry point file. If
Expand Down Expand Up @@ -1840,8 +1840,8 @@ def write_voila_manifest_json(
entrypoint: str,
environment: Environment,
app_mode: AppMode = AppModes.JUPYTER_VOILA,
extra_files: typing.List[str] = None,
excludes: typing.List[str] = None,
extra_files: Sequence[str] = None,
excludes: Sequence[str] = None,
force_generate: bool = True,
image: str = None,
env_management_py: bool = None,
Expand Down Expand Up @@ -1932,11 +1932,11 @@ def write_api_manifest_json(
entry_point: str,
environment: Environment,
app_mode: AppMode,
extra_files: typing.List[str],
excludes: typing.List[str],
image: str = None,
env_management_py: bool = None,
env_management_r: bool = None,
extra_files: Sequence[str],
excludes: Sequence[str],
image: Optional[str] = None,
env_management_py: Optional[bool] = None,
env_management_r: Optional[bool] = None,
) -> bool:
"""
Creates and writes a manifest.json file for the given entry point file. If
Expand Down Expand Up @@ -2015,8 +2015,8 @@ def write_quarto_manifest_json(
inspect: typing.Any,
app_mode: AppMode,
environment: Environment,
extra_files: typing.List[str],
excludes: typing.List[str],
extra_files: Sequence[str],
excludes: Sequence[str],
image: str = None,
env_management_py: bool = None,
env_management_r: bool = None,
Expand Down
Loading