diff --git a/luigi/contrib/azureblob.py b/luigi/contrib/azureblob.py index 20de24224a..60a2f88569 100644 --- a/luigi/contrib/azureblob.py +++ b/luigi/contrib/azureblob.py @@ -179,7 +179,8 @@ def __init__(self, container, blob, client, download_when_reading, **kwargs): self.closed = False self.download_when_reading = download_when_reading self.azure_blob_options = kwargs - self.download_file_location = os.path.join(tempfile.mkdtemp(prefix=str(datetime.datetime.utcnow())), blob) + self.download_file_location = os.path.join(tempfile.mkdtemp(prefix=str(datetime.datetime.utcnow())), + os.path.basename(blob)) self.fid = None def read(self, n=None): diff --git a/scripts/ci/install_start_azurite.sh b/scripts/ci/install_start_azurite.sh index 9fccbbaad5..9ff556ed34 100755 --- a/scripts/ci/install_start_azurite.sh +++ b/scripts/ci/install_start_azurite.sh @@ -1,5 +1,6 @@ #!/usr/bin/env bash -docker pull arafato/azurite +AZURITE_IMAGE=mcr.microsoft.com/azure-storage/azurite +docker pull $AZURITE_IMAGE mkdir -p blob_emulator $1/stop_azurite.sh -docker run -e executable=blob -d -t -p 10000:10000 -v blob_emulator:/opt/azurite/folder arafato/azurite \ No newline at end of file +docker run -e executable=blob -d -t -p 10000:10000 -v blob_emulator:/opt/azurite/folder $AZURITE_IMAGE diff --git a/scripts/ci/stop_azurite.sh b/scripts/ci/stop_azurite.sh index 834f5e7bd6..6fffe7d48d 100755 --- a/scripts/ci/stop_azurite.sh +++ b/scripts/ci/stop_azurite.sh @@ -1,2 +1,2 @@ #!/usr/bin/env bash -docker stop $(docker ps -q --filter ancestor=arafato/azurite) \ No newline at end of file +docker stop $(docker ps -q --filter ancestor=mcr.microsoft.com/azure-storage/azurite) diff --git a/test/contrib/azureblob_test.py b/test/contrib/azureblob_test.py index 2c06086de0..8c894a8e80 100644 --- a/test/contrib/azureblob_test.py +++ b/test/contrib/azureblob_test.py @@ -117,7 +117,7 @@ def test_upload_copy_move_remove_blob(self): class MovieScriptTask(luigi.Task): def output(self): - return AzureBlobTarget("luigi-test", "movie-cheesy.txt", client, download_when_reading=False) + return AzureBlobTarget("luigi-test", "path/to/movie-cheesy.txt", client, download_when_reading=False) def run(self): client.connection.create_container("luigi-test") @@ -170,3 +170,12 @@ def tearDown(self): def test_AzureBlobTarget(self): luigi.build([FinalTask()], local_scheduler=True, log_level='NOTSET') + + def test_AzureBlobTarget_download_when_reading(self): + task = MovieScriptTask() + task.run() + target = task.output() + # Test reading a target blob with a context manager and download_when_reading=True + target.download_when_reading = True + with target.open("r") as f: + assert "James Bond" in f.read()