From 9646d9209874033038c80b8fcf3e8443e983bf41 Mon Sep 17 00:00:00 2001 From: Ryn Daniels Date: Tue, 11 Jan 2022 15:45:03 +0200 Subject: [PATCH 1/2] Check for assets with size of 0 bytes --- spacy/cli/project/assets.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/spacy/cli/project/assets.py b/spacy/cli/project/assets.py index b5057e40168..eaee5979cf0 100644 --- a/spacy/cli/project/assets.py +++ b/spacy/cli/project/assets.py @@ -1,6 +1,7 @@ from typing import Any, Dict, Optional from pathlib import Path from wasabi import msg +import os import re import shutil import requests @@ -129,10 +130,17 @@ def fetch_asset( the asset failed. """ dest_path = (project_path / dest).resolve() - if dest_path.exists() and checksum: + if dest_path.exists(): # If there's already a file, check for checksum - if checksum == get_checksum(dest_path): - msg.good(f"Skipping download with matching checksum: {dest}") + if checksum: + if checksum == get_checksum(dest_path): + msg.good(f"Skipping download with matching checksum: {dest}") + return + else: + # If there's not a checksum, make sure the file is a possibly valid size + if os.path.getsize(dest_path) == 0: + os.remove(dest_path) + msg.warn(f"Asset exists but with size of 0 bytes, deleting: {dest}") # We might as well support the user here and create parent directories in # case the asset dir isn't listed as a dir to create in the project.yml if not dest_path.parent.exists(): From 86b1b0b866641ee21e143df1523d2d76acca026e Mon Sep 17 00:00:00 2001 From: Ryn Daniels <397565+ryndaniels@users.noreply.github.com> Date: Tue, 11 Jan 2022 15:02:24 +0100 Subject: [PATCH 2/2] Update spacy/cli/project/assets.py Co-authored-by: Sofie Van Landeghem --- spacy/cli/project/assets.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spacy/cli/project/assets.py b/spacy/cli/project/assets.py index eaee5979cf0..5e0cdfdf2ca 100644 --- a/spacy/cli/project/assets.py +++ b/spacy/cli/project/assets.py @@ -139,8 +139,8 @@ def fetch_asset( else: # If there's not a checksum, make sure the file is a possibly valid size if os.path.getsize(dest_path) == 0: - os.remove(dest_path) msg.warn(f"Asset exists but with size of 0 bytes, deleting: {dest}") + os.remove(dest_path) # We might as well support the user here and create parent directories in # case the asset dir isn't listed as a dir to create in the project.yml if not dest_path.parent.exists():