Use import to find data package

This commit is contained in:
Matthew Honnibal 2017-03-19 01:39:36 +01:00
parent 5941fb9e92
commit 797f286c38

View File

@ -3,7 +3,7 @@ from __future__ import unicode_literals
import pip
from pathlib import Path
from distutils.sysconfig import get_python_lib
import importlib
from .. import util
@ -14,11 +14,16 @@ def link(origin, link_name, force=False):
symlink(origin, link_name, force)
def link_package(origin, link_name, force=False):
package_path = get_python_lib()
meta = get_meta(package_path, origin)
data_dir = origin + '-' + meta['version']
model_path = Path(package_path) / origin / data_dir
def link_package(package_name, link_name, force=False):
# Here we're importing the module just to find it. This is worryingly
# indirect, but it's otherwise very difficult to find the package.
# Python's installation and import rules are very complicated.
pkg = importlib.import_module(package_name)
package_path = Path(pkg.__file__).parent.parent
meta = get_meta(package_path, package_name)
model_name = package_name + '-' + meta['version']
model_path = package_path / package_name / model_name
symlink(model_path, link_name, force)