Skip to content

Commit

Permalink
Merge branch 'main' into schloerke/324-merge-api-and-resource
Browse files Browse the repository at this point in the history
  • Loading branch information
schloerke authored Nov 13, 2024
2 parents 9bc8701 + 540c693 commit bc31ad2
Show file tree
Hide file tree
Showing 29 changed files with 440 additions and 140 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
matrix:
CONNECT_VERSION:
- preview
- 2024.09.0
- 2024.08.0
- 2024.06.0
- 2024.05.0
Expand Down
49 changes: 25 additions & 24 deletions integration/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,34 @@ CONNECT_BOOTSTRAP_SECRETKEY ?= $(shell head -c 32 /dev/random | base64)
.PHONY: $(CONNECT_VERSIONS) \
all \
build \
down \
down-% \
latest \
test \
up \
up-% \
help
down \
down-% \
latest \
test \
up \
up-% \
help

# Versions
CONNECT_VERSIONS := 2024.08.0 \
CONNECT_VERSIONS := 2024.09.0 \
2024.08.0 \
2024.06.0 \
2024.05.0 \
2024.04.1 \
2024.04.0 \
2024.03.0 \
2024.02.0 \
2024.01.0 \
2023.12.0 \
2023.10.0 \
2023.09.0 \
2023.07.0 \
2023.06.0 \
2023.05.0 \
2023.01.1 \
2023.01.0 \
2022.12.0 \
2022.11.0
2024.05.0 \
2024.04.1 \
2024.04.0 \
2024.03.0 \
2024.02.0 \
2024.01.0 \
2023.12.0 \
2023.10.0 \
2023.09.0 \
2023.07.0 \
2023.06.0 \
2023.05.0 \
2023.01.1 \
2023.01.0 \
2022.12.0 \
2022.11.0

clean:
rm -rf logs reports
Expand Down
2 changes: 2 additions & 0 deletions integration/compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ services:
- test
connect:
image: ${DOCKER_CONNECT_IMAGE}:${DOCKER_CONNECT_IMAGE_TAG}
pull_policy: always
environment:
- CONNECT_BOOTSTRAP_ENABLED=true
- CONNECT_BOOTSTRAP_SECRETKEY=${CONNECT_BOOTSTRAP_SECRETKEY}
- CONNECT_APPLICATIONS_PACKAGEAUDITINGENABLED=true
networks:
- test
privileged: true
Expand Down
8 changes: 4 additions & 4 deletions integration/tests/posit/connect/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from packaging import version
from packaging.version import parse

from posit import connect

client = connect.Client()
client_version = client.version
assert client_version is not None
CONNECT_VERSION = version.parse(client_version)
version = client.version
assert version
CONNECT_VERSION = parse(version)
23 changes: 19 additions & 4 deletions integration/tests/posit/connect/test_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
from . import CONNECT_VERSION


@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2023.01.1"),
reason="Quarto not available",
)
class TestJobs:
@classmethod
def setup_class(cls):
Expand All @@ -19,10 +23,6 @@ def teardown_class(cls):
cls.content.delete()
assert cls.client.content.count() == 0

@pytest.mark.skipif(
CONNECT_VERSION <= version.parse("2023.01.1"),
reason="Quarto not available",
)
def test(self):
content = self.content

Expand All @@ -36,3 +36,18 @@ def test(self):

jobs = content.jobs
assert len(jobs) == 1

def test_find_by(self):
content = self.content

path = Path("../../../resources/connect/bundles/example-quarto-minimal/bundle.tar.gz")
path = Path(__file__).parent / path
path = path.resolve()
path = str(path)

bundle = content.bundles.create(path)
task = bundle.deploy()
task.wait_for()

jobs = content.jobs
assert len(jobs) != 0
41 changes: 41 additions & 0 deletions integration/tests/posit/connect/test_packages.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from pathlib import Path

import pytest
from packaging import version

from posit import connect

from . import CONNECT_VERSION


@pytest.mark.skipif(
CONNECT_VERSION < version.parse("2024.10.0-dev"),
reason="Packages API unavailable",
)
class TestPackages:
@classmethod
def setup_class(cls):
cls.client = connect.Client()
cls.content = cls.client.content.create(name=cls.__name__)
path = Path("../../../resources/connect/bundles/example-flask-minimal/bundle.tar.gz")
path = (Path(__file__).parent / path).resolve()
bundle = cls.content.bundles.create(str(path))
task = bundle.deploy()
task.wait_for()

@classmethod
def teardown_class(cls):
cls.content.delete()

def test(self):
assert self.client.packages
assert self.content.packages

def test_find_by(self):
package = self.client.packages.find_by(name="flask")
assert package
assert package["name"] == "flask"

package = self.content.packages.find_by(name="flask")
assert package
assert package["name"] == "flask"
42 changes: 0 additions & 42 deletions src/posit/connect/_typing_extensions.py

This file was deleted.

10 changes: 8 additions & 2 deletions src/posit/connect/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from .groups import Groups
from .metrics import Metrics
from .oauth import OAuth
from .packages import Packages
from .resources import ResourceParameters
from .tasks import Tasks
from .users import User, Users
Expand Down Expand Up @@ -155,7 +156,7 @@ def __init__(self, *args, **kwargs) -> None:
session.hooks["response"].append(hooks.handle_errors)
self.session = session
self.resource_params = ResourceParameters(session, self.cfg.url)
self.ctx = Context(self.session, self.cfg.url)
self._ctx = Context(self.session, self.cfg.url)

@property
def version(self) -> str | None:
Expand All @@ -167,7 +168,7 @@ def version(self) -> str | None:
str
The version of the Posit Connect server.
"""
return self.ctx.version
return self._ctx.version

@property
def me(self) -> User:
Expand Down Expand Up @@ -269,6 +270,11 @@ def oauth(self) -> OAuth:
"""
return OAuth(self.resource_params, self.cfg.api_key)

@property
@requires(version="2024.10.0-dev")
def packages(self) -> Packages:
return Packages(self._ctx, "v1/packages")

@property
def vanities(self) -> Vanities:
return Vanities(self.resource_params)
Expand Down
6 changes: 4 additions & 2 deletions src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@
overload,
)

from typing_extensions import NotRequired, Required, TypedDict, Unpack

from . import tasks
from ._api import ApiDictEndpoint, JsonifiableDict
from ._typing_extensions import NotRequired, Required, TypedDict, Unpack
from .bundles import Bundles
from .context import Context
from .env import EnvVars
from .errors import ClientError
from .jobs import JobsMixin
from .oauth.associations import ContentItemAssociations
from .packages import ContentPackagesMixin as PackagesMixin
from .permissions import Permissions
from .resources import Resource, ResourceParameters, Resources
from .vanities import VanityMixin
Expand Down Expand Up @@ -171,7 +173,7 @@ class ContentItemOwner(Resource):
pass


class ContentItem(JobsMixin, VanityMixin, Resource):
class ContentItem(JobsMixin, PackagesMixin, VanityMixin, Resource):
class _AttrsBase(TypedDict, total=False):
# # `name` will be set by other _Attrs classes
# name: str
Expand Down
4 changes: 2 additions & 2 deletions src/posit/connect/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def requires(version: str):
def decorator(func):
@functools.wraps(func)
def wrapper(instance: ContextManager, *args, **kwargs):
ctx = instance.ctx
ctx = instance._ctx
if ctx.version and Version(ctx.version) < Version(version):
raise RuntimeError(
f"This API is not available in Connect version {ctx.version}. Please upgrade to version {version} or later.",
Expand Down Expand Up @@ -45,4 +45,4 @@ def version(self, value):


class ContextManager(Protocol):
ctx: Context
_ctx: Context
3 changes: 2 additions & 1 deletion src/posit/connect/jobs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import posixpath
from typing import Any, Literal, Optional, overload

from ._typing_extensions import NotRequired, Required, TypedDict, Unpack
from typing_extensions import NotRequired, Required, TypedDict, Unpack

from .context import Context
from .resources import Active, ActiveFinderMethods, ActiveSequence, Resource

Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/oauth/oauth.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Optional

from .._typing_extensions import TypedDict
from typing_extensions import TypedDict

from ..resources import ResourceParameters, Resources
from .integrations import Integrations
from .sessions import Sessions
Expand Down
Loading

0 comments on commit bc31ad2

Please sign in to comment.