Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add packages and content packages #313

Merged
merged 14 commits into from
Nov 12, 2024
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"
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")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will bump this to 2024.11.0 after the release.

def packages(self) -> Packages:
return Packages(self._ctx, "v1/packages")

@property
def vanities(self) -> Vanities:
return Vanities(self.resource_params)
Expand Down
3 changes: 2 additions & 1 deletion src/posit/connect/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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 +172,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
schloerke marked this conversation as resolved.
Show resolved Hide resolved
Loading
Loading