From 3889747119a6302da96d91502479081ad2036aa4 Mon Sep 17 00:00:00 2001 From: svlandeg Date: Thu, 10 Sep 2020 14:36:53 +0200 Subject: [PATCH] asset fix & UX --- spacy/cli/project/assets.py | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/spacy/cli/project/assets.py b/spacy/cli/project/assets.py index 2b623675d..0d54a8d05 100644 --- a/spacy/cli/project/assets.py +++ b/spacy/cli/project/assets.py @@ -38,38 +38,45 @@ def project_assets(project_dir: Path) -> None: msg.warn(f"No assets specified in {PROJECT_FILE}", exits=0) msg.info(f"Fetching {len(assets)} asset(s)") for asset in assets: - dest = Path(asset["dest"]) + dest = project_dir / asset["dest"] checksum = asset.get("checksum") - if "git" in asset: - if dest.exists(): - # If there's already a file, check for checksum - if checksum and checksum == get_checksum(dest): - msg.good(f"Skipping download with matching checksum: {dest}") - continue - else: + if dest.exists(): + # If there's already a file, check for checksum + if checksum and checksum == get_checksum(dest): + msg.good(f"Skipping download with matching checksum: {dest}") + continue + else: + msg.good(f"Removing asset with outdated checksum: {dest} ") + if dest.is_dir(): shutil.rmtree(dest) + else: + dest.unlink() + if "git" in asset: git_sparse_checkout( asset["git"]["repo"], asset["git"]["path"], dest, branch=asset["git"].get("branch"), ) - else: + elif "url" in asset: url = asset.get("url") if not url: # project.yml defines asset without URL that the user has to place check_private_asset(dest, checksum) continue fetch_asset(project_path, url, dest, checksum) + else: + msg.warn(f"Could not fetch asset {dest} as neither a 'git' or 'url' parameter is specified.") def check_private_asset(dest: Path, checksum: Optional[str] = None) -> None: """Check and validate assets without a URL (private assets that the user has to provide themselves) and give feedback about the checksum. - dest (Path): Desintation path of the asset. + dest (Path): Destination path of the asset. checksum (Optional[str]): Optional checksum of the expected file. """ + print("path", dest) if not Path(dest).exists(): err = f"No URL provided for asset. You need to add this file yourself: {dest}" msg.warn(err)