You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by ds...@apache.org on 2021/04/14 05:07:10 UTC
[airflow] branch master updated: S3Hook.load_file should accept
Path object in addition to str (#15232)
This is an automated email from the ASF dual-hosted git repository.
dstandish pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/master by this push:
new a82de56 S3Hook.load_file should accept Path object in addition to str (#15232)
a82de56 is described below
commit a82de56b9d16713cbba4dee42d6797cc12b59cfe
Author: Daniel Standish <15...@users.noreply.github.com>
AuthorDate: Tue Apr 13 22:06:58 2021 -0700
S3Hook.load_file should accept Path object in addition to str (#15232)
Co-authored-by: Daniel Standish <ds...@users.noreply.github.com>
---
airflow/providers/amazon/aws/hooks/s3.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/airflow/providers/amazon/aws/hooks/s3.py b/airflow/providers/amazon/aws/hooks/s3.py
index 65bfa65..2e18754 100644
--- a/airflow/providers/amazon/aws/hooks/s3.py
+++ b/airflow/providers/amazon/aws/hooks/s3.py
@@ -26,6 +26,7 @@ import shutil
from functools import wraps
from inspect import signature
from io import BytesIO
+from pathlib import Path
from tempfile import NamedTemporaryFile
from typing import Any, Callable, Dict, List, Optional, Tuple, TypeVar, Union, cast
from urllib.parse import urlparse
@@ -464,7 +465,7 @@ class S3Hook(AwsBaseHook):
@unify_bucket_name_and_key
def load_file(
self,
- filename: str,
+ filename: Union[Path, str],
key: str,
bucket_name: Optional[str] = None,
replace: bool = False,
@@ -475,8 +476,8 @@ class S3Hook(AwsBaseHook):
"""
Loads a local file to S3
- :param filename: name of the file to load.
- :type filename: str
+ :param filename: path to the file to load.
+ :type filename: Union[Path, str]
:param key: S3 key that will point to the file
:type key: str
:param bucket_name: Name of the bucket in which to store the file
@@ -494,6 +495,7 @@ class S3Hook(AwsBaseHook):
uploaded to the S3 bucket.
:type acl_policy: str
"""
+ filename = str(filename)
if not replace and self.check_for_key(key, bucket_name):
raise ValueError(f"The key {key} already exists.")