Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Fix deployment #169

Merged
merged 7 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- Deployments of `S3Bucket` - [#168](https://github.com/PrefectHQ/prefect-aws/pull/168)

### Security

## 0.2.0
Expand Down
19 changes: 3 additions & 16 deletions prefect_aws/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from prefect.filesystems import WritableDeploymentStorage, WritableFileSystem
from prefect.utilities.asyncutils import run_sync_in_worker_thread, sync_compatible
from prefect.utilities.filesystem import filter_files
from pydantic import Field, root_validator, validator
from pydantic import Field, root_validator

from prefect_aws import AwsCredentials, MinIOCredentials
from prefect_aws.client_parameters import AwsClientParameters
Expand Down Expand Up @@ -269,8 +269,8 @@ class S3Bucket(WritableFileSystem, WritableDeploymentStorage):
description="A block containing your credentials (choose this or "
"AWS Credentials).",
)
basepath: Optional[Path] = Field(
default=None,
basepath: Optional[str] = Field(
default="",
description="Location to write to and read from in the S3 bucket. Defaults to "
"the root of the bucket.",
)
Expand All @@ -280,19 +280,6 @@ class S3Bucket(WritableFileSystem, WritableDeploymentStorage):
"standard AWS S3 endpoint.",
)

@validator("basepath", pre=True)
def cast_pathlib(cls, value):

"""
If basepath provided, it means we aren't writing to the root directory
of the bucket. We need to ensure that it is a valid path. This is called
when the S3Bucket block is instantiated.
"""

if isinstance(value, Path):
return str(value)
return value

@root_validator(pre=True)
def check_credentials(cls, values):

Expand Down
12 changes: 12 additions & 0 deletions tests/test_s3_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest
from botocore.exceptions import ClientError
from moto import mock_s3
from prefect.deployments import Deployment

from prefect_aws import AwsCredentials, MinIOCredentials
from prefect_aws.s3 import S3Bucket
Expand Down Expand Up @@ -312,3 +313,14 @@ def test_write_path_in_sync_context(s3_bucket):
key = s3_bucket.write_path("test.txt", content=b"hello")
content = s3_bucket.read_path(key)
assert content == b"hello"


def test_deployment_default_basepath(s3_bucket):
deployment = Deployment(name="testing", storage=s3_bucket)
assert deployment.location == "/"


def test_deployment_set_basepath(s3_bucket):
s3_bucket.basepath = "home"
deployment = Deployment(name="testing", storage=s3_bucket)
assert deployment.location == "home/"