From a035ebd32aad197908312ad4bebed4726855ee63 Mon Sep 17 00:00:00 2001 From: ines Date: Sat, 18 Mar 2017 12:59:21 +0100 Subject: [PATCH] Use pathlib.Path instead of os.path --- spacy/link.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/spacy/link.py b/spacy/link.py index abae83b46..ee520c1df 100644 --- a/spacy/link.py +++ b/spacy/link.py @@ -6,6 +6,7 @@ import os import pip import site import plac +from pathlib import Path from . import util @@ -19,7 +20,7 @@ def link(origin, link_name, force=False): either the name of a pip package, or the local path to the model data directory. Linking models allows loading them via spacy.load(link_name).""" if is_package(origin): - link_package(origin, link_name) + link_package(origin, link_name, force) else: symlink(origin, link_name, force) @@ -28,30 +29,30 @@ def link_package(origin, link_name, force=False): package_path = site.getsitepackages()[0] meta = get_meta(package_path, origin) data_dir = origin + '-' + meta['version'] - model_path = os.path.join(package_path, origin, data_dir) + model_path = Path(package_path) / origin / data_dir symlink(model_path, link_name, force) def symlink(model_path, link_name, force): - if not os.path.isdir(model_path): + if not model_path.exists(): util.sys_exit( "The data should be located in {p}".format(p=model_path), title="Can't locate model data") data_path = str(util.get_data_path()) - link_path = os.path.join(os.path.abspath(__file__ + '/../../'), data_path, link_name) + link_path = Path(__file__).parent.parent / data_path / link_name - if os.path.isdir(link_path): + if link_path.exists(): if force: - os.unlink(link_path) + os.unlink(str(link_path)) else: util.sys_exit( "To overwrite an existing link, use the --force flag.", title="Link {l} already exists".format(l=link_name)) - model_path = os.path.abspath(model_path) - os.symlink(model_path, link_path) + + os.symlink(str(model_path), str(link_path)) util.print_msg( - "{a} --> {b}".format(a=model_path, b=link_path), + "{a} --> {b}".format(a=str(model_path), b=str(link_path)), "You can now load the model via spacy.load('{l}').".format(l=link_name), title="Linking successful")