Check for assets with size of 0 bytes (#10026)

* Check for assets with size of 0 bytes

* Update spacy/cli/project/assets.py

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>

Co-authored-by: Sofie Van Landeghem <svlandeg@users.noreply.github.com>
This commit is contained in:
Ryn Daniels 2022-01-12 10:34:23 +01:00 committed by GitHub
parent 5ba4171b19
commit 057b8c64c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,6 +1,7 @@
from typing import Any, Dict, Optional from typing import Any, Dict, Optional
from pathlib import Path from pathlib import Path
from wasabi import msg from wasabi import msg
import os
import re import re
import shutil import shutil
import requests import requests
@ -129,10 +130,17 @@ def fetch_asset(
the asset failed. the asset failed.
""" """
dest_path = (project_path / dest).resolve() 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 there's already a file, check for checksum
if checksum:
if checksum == get_checksum(dest_path): if checksum == get_checksum(dest_path):
msg.good(f"Skipping download with matching checksum: {dest}") 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:
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 # 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 # case the asset dir isn't listed as a dir to create in the project.yml
if not dest_path.parent.exists(): if not dest_path.parent.exists():