Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@ module-root = ""

[tool.ruff]
line-length = 120
target-version = "py311"
extend-exclude = ["rsconnect-build", "rsconnect-build-test", "tests/testdata"]

[tool.ruff.lint]
select = ["E", "F", "W"]
ignore = ["E203", "E231", "E302"]
select = ["E", "F", "W", "UP"]
# Percent formatting has subtly different behavior from str.format.
ignore = ["E203", "E231", "E302", "UP031"]
per-file-ignores = { "tests/test_metadata.py" = ["E501"] }

[tool.coverage.run]
Expand Down
77 changes: 39 additions & 38 deletions rsconnect/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
import typing
from os.path import basename, exists, isdir, join, relpath
from pathlib import PurePath
from typing import NotRequired, Optional, Sequence, TypedDict, cast
from typing import NotRequired, TypedDict, cast
from collections.abc import Sequence
from urllib.parse import urlparse
from warnings import warn

Expand Down Expand Up @@ -187,15 +188,15 @@ def test_rstudio_server(server: api.PositServer):
try:
client.get_current_user()
except RSConnectException as exc:
raise RSConnectException("Failed to verify with {} ({}).".format(server.remote_name, exc))
raise RSConnectException(f"Failed to verify with {server.remote_name} ({exc}).")


def test_spcs_server(server: api.SPCSConnectServer):
with api.RSConnectClient(server) as client:
try:
client.me()
except RSConnectException as exc:
raise RSConnectException("Failed to verify with {} ({}).".format(server.remote_name, exc))
raise RSConnectException(f"Failed to verify with {server.remote_name} ({exc}).")


def test_api_key(connect_server: api.RSConnectServer) -> str:
Expand All @@ -210,7 +211,7 @@ def test_api_key(connect_server: api.RSConnectServer) -> str:
return api.verify_api_key(connect_server)


def which_quarto(quarto: Optional[str] = None) -> str:
def which_quarto(quarto: str | None = 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 Expand Up @@ -342,7 +343,7 @@ def validate_extra_files(directory: str, extra_files: Sequence[str]):
return result


def validate_entry_point(entry_point: Optional[str], directory: str):
def validate_entry_point(entry_point: str | None, directory: str):
"""
Validates the entry point specified by the user, expanding as necessary. If the
user specifies nothing, a module of "app" is assumed. If the user specifies a
Expand All @@ -364,31 +365,31 @@ def validate_entry_point(entry_point: Optional[str], directory: str):


def deploy_app(
name: Optional[str] = None,
server: Optional[str] = None,
api_key: Optional[str] = None,
insecure: Optional[bool] = None,
cacert: Optional[typing.IO[str]] = None,
ca_data: Optional[str] = None,
entry_point: Optional[str] = None,
excludes: Optional[list[str]] = None,
name: str | None = None,
server: str | None = None,
api_key: str | None = None,
insecure: bool | None = None,
cacert: typing.IO[str] | None = None,
ca_data: str | None = None,
entry_point: str | None = None,
excludes: list[str] | None = None,
new: bool = False,
app_id: Optional[str] = None,
title: Optional[str] = None,
python: Optional[str] = None,
app_id: str | None = None,
title: str | None = None,
python: str | None = None,
force_generate: bool = False,
verbose: Optional[bool] = None,
directory: Optional[str] = None,
extra_files: Optional[list[str]] = None,
env_vars: Optional[dict[str, str]] = None,
image: Optional[str] = None,
env_management_py: Optional[bool] = None,
env_management_r: Optional[bool] = None,
account: Optional[str] = None,
token: Optional[str] = None,
secret: Optional[str] = None,
app_mode: Optional[AppMode] = None,
connect_server: Optional[api.TargetableServer] = None,
verbose: bool | None = None,
directory: str | None = None,
extra_files: list[str] | None = None,
env_vars: dict[str, str] | None = None,
image: str | None = None,
env_management_py: bool | None = None,
env_management_r: bool | None = None,
account: str | None = None,
token: str | None = None,
secret: str | None = None,
app_mode: AppMode | None = None,
connect_server: api.TargetableServer | None = None,
**kws: object,
):
kwargs = locals()
Expand Down Expand Up @@ -480,8 +481,8 @@ def deploy_app(
def deploy_python_fastapi(
connect_server: api.TargetableServer,
directory: str,
extra_files: typing.List[str],
excludes: typing.List[str],
extra_files: list[str],
excludes: list[str],
entry_point: str,
new: bool,
app_id: int,
Expand All @@ -490,9 +491,9 @@ def deploy_python_fastapi(
conda_mode: bool,
force_generate: bool,
log_callback: typing.Callable[..., None],
image: Optional[str] = None,
env_management_py: Optional[bool] = None,
env_management_r: Optional[bool] = None,
image: str | None = None,
env_management_py: bool | None = None,
env_management_r: bool | None = None,
):
"""
A function to deploy a Python ASGI API module to Posit Connect. Depending on the files involved
Expand Down Expand Up @@ -531,11 +532,11 @@ def create_quarto_deployment_bundle(
excludes: Sequence[str],
app_mode: AppMode,
inspect: QuartoInspectResult,
environment: Optional[Environment],
image: Optional[str] = None,
env_management_py: Optional[bool] = None,
env_management_r: Optional[bool] = None,
r_environment: Optional[REnvironment] = None,
environment: Environment | None,
image: str | None = None,
env_management_py: bool | None = None,
env_management_r: bool | None = None,
r_environment: REnvironment | None = None,
) -> typing.IO[bytes]:
"""
Create an in-memory bundle, ready to deploy.
Expand Down
55 changes: 27 additions & 28 deletions rsconnect/actions_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import traceback
from concurrent.futures import ThreadPoolExecutor, as_completed
from datetime import datetime, timedelta
from typing import Iterator, Literal, Optional, Sequence, cast, Union
from typing import Literal, cast
from collections.abc import Iterator, Sequence

import semver

Expand All @@ -33,7 +34,7 @@ def content_build_store() -> ContentBuildStore:
return _content_build_store


def ensure_content_build_store(connect_server: Union[RSConnectServer, SPCSConnectServer]) -> ContentBuildStore:
def ensure_content_build_store(connect_server: RSConnectServer | SPCSConnectServer) -> ContentBuildStore:
global _content_build_store
if not _content_build_store:
logger.info("Initializing ContentBuildStore for %s" % connect_server.url)
Expand All @@ -42,7 +43,7 @@ def ensure_content_build_store(connect_server: Union[RSConnectServer, SPCSConnec


def build_add_content(
connect_server: Union[RSConnectServer, SPCSConnectServer],
connect_server: RSConnectServer | SPCSConnectServer,
content_guids_with_bundle: Sequence[ContentGuidWithBundle],
):
"""
Expand Down Expand Up @@ -77,16 +78,16 @@ def build_add_content(
build_store.set_content_item_build_status(content["guid"], BuildStatus.NEEDS_BUILD)


def _validate_build_rm_args(guid: Optional[str], all: bool, purge: bool):
def _validate_build_rm_args(guid: str | None, all: bool, purge: bool):
if guid and all:
raise RSConnectException("You must specify only one of -g/--guid or --all, not both.")
if not guid and not all:
raise RSConnectException("You must specify one of -g/--guid or --all.")


def build_remove_content(
connect_server: Union[RSConnectServer, SPCSConnectServer],
guid: Optional[str],
connect_server: RSConnectServer | SPCSConnectServer,
guid: str | None,
all: bool,
purge: bool,
) -> list[str]:
Expand All @@ -109,20 +110,20 @@ def build_remove_content(
return guids


def build_list_content(connect_server: Union[RSConnectServer, SPCSConnectServer], guid: str, status: Optional[str]):
def build_list_content(connect_server: RSConnectServer | SPCSConnectServer, guid: str, status: str | None):
build_store = ensure_content_build_store(connect_server)
if guid:
return [build_store.get_content_item(g) for g in guid]
else:
return build_store.get_content_items(status=status)


def build_history(connect_server: Union[RSConnectServer, SPCSConnectServer], guid: str):
def build_history(connect_server: RSConnectServer | SPCSConnectServer, guid: str):
return ensure_content_build_store(connect_server).get_build_history(guid)


def build_start(
connect_server: Union[RSConnectServer, SPCSConnectServer],
connect_server: RSConnectServer | SPCSConnectServer,
parallelism: int,
aborted: bool = False,
error: bool = False,
Expand Down Expand Up @@ -251,9 +252,7 @@ def build_start(
build_monitor.shutdown()


def _monitor_build(
connect_server: Union[RSConnectServer, SPCSConnectServer], content_items: list[ContentItemWithBuildState]
):
def _monitor_build(connect_server: RSConnectServer | SPCSConnectServer, content_items: list[ContentItemWithBuildState]):
"""
:return bool: True if the build completed without errors, False otherwise
"""
Expand Down Expand Up @@ -299,7 +298,7 @@ def _monitor_build(


def _build_content_item(
connect_server: Union[RSConnectServer, SPCSConnectServer], content: ContentItemWithBuildState, poll_wait: int
connect_server: RSConnectServer | SPCSConnectServer, content: ContentItemWithBuildState, poll_wait: int
):
build_store = ensure_content_build_store(connect_server)
with RSConnectClient(connect_server) as client:
Expand Down Expand Up @@ -353,15 +352,15 @@ def write_log(line: str):


def emit_build_log(
connect_server: Union[RSConnectServer, SPCSConnectServer],
connect_server: RSConnectServer | SPCSConnectServer,
guid: str,
format: str,
task_id: Optional[str] = None,
task_id: str | None = None,
):
build_store = ensure_content_build_store(connect_server)
log_file = build_store.get_build_log(guid, task_id)
if log_file:
with open(log_file, "r") as f:
with open(log_file) as f:
for line in f.readlines():
if format == "json":
yield json.dumps({"message": line}) + "\n"
Expand All @@ -371,7 +370,7 @@ def emit_build_log(
raise RSConnectException("Log file not found for content: %s" % guid)


def download_bundle(connect_server: Union[RSConnectServer, SPCSConnectServer], guid_with_bundle: ContentGuidWithBundle):
def download_bundle(connect_server: RSConnectServer | SPCSConnectServer, guid_with_bundle: ContentGuidWithBundle):
"""
:param guid_with_bundle: models.ContentGuidWithBundle
"""
Expand All @@ -389,12 +388,12 @@ def download_bundle(connect_server: Union[RSConnectServer, SPCSConnectServer], g
return client.download_bundle(guid_with_bundle.guid, guid_with_bundle.bundle_id)


def download_lockfile(connect_server: Union[RSConnectServer, SPCSConnectServer], guid: str):
def download_lockfile(connect_server: RSConnectServer | SPCSConnectServer, guid: str):
with RSConnectClient(connect_server) as client:
return client.content_lockfile(guid)


def get_content(connect_server: Union[RSConnectServer, SPCSConnectServer], guid: str | list[str]):
def get_content(connect_server: RSConnectServer | SPCSConnectServer, guid: str | list[str]):
"""
:param guid: a single guid as a string or list of guids.
:return: a list of content items.
Expand All @@ -408,14 +407,14 @@ def get_content(connect_server: Union[RSConnectServer, SPCSConnectServer], guid:


def search_content(
connect_server: Union[RSConnectServer, SPCSConnectServer],
connect_server: RSConnectServer | SPCSConnectServer,
published: bool,
unpublished: bool,
content_type: Sequence[str],
r_version: Optional[VersionSearchFilter],
py_version: Optional[VersionSearchFilter],
title_contains: Optional[str],
order_by: Optional[Literal["created", "last_deployed"]],
r_version: VersionSearchFilter | None,
py_version: VersionSearchFilter | None,
title_contains: str | None,
order_by: Literal["created", "last_deployed"] | None,
):
with RSConnectClient(connect_server) as client:
result = client.search_content()
Expand All @@ -430,9 +429,9 @@ def _apply_content_filters(
published: bool,
unpublished: bool,
content_type: Sequence[str],
r_version: Optional[VersionSearchFilter],
py_version: Optional[VersionSearchFilter],
title_search: Optional[str],
r_version: VersionSearchFilter | None,
py_version: VersionSearchFilter | None,
title_search: str | None,
) -> Iterator[ContentItemV1]:
def content_is_published(item: ContentItemV1):
return item.get("bundle_id") is not None
Expand Down Expand Up @@ -495,7 +494,7 @@ def do_filter(item: ContentItemV1) -> bool:

def _order_content_results(
content_list: Iterator[ContentItemV1],
order_by: Optional[Literal["created", "last_deployed"]],
order_by: Literal["created", "last_deployed"] | None,
) -> list[ContentItemV1]:
result = content_list
if order_by == "last_deployed":
Expand Down
Loading
Loading