mirror of
https://github.com/explosion/spaCy.git
synced 2024-11-10 19:57:17 +03:00
[v1.x] Backport 2.x's avoidance of 'import pip'
This commit is contained in:
commit
6ba07bfe8a
|
@ -14,4 +14,3 @@ requests>=2.11.0,<3.0.0
|
||||||
regex>=2017.4.1,<2017.12.1
|
regex>=2017.4.1,<2017.12.1
|
||||||
ftfy>=4.4.2,<5.0.0
|
ftfy>=4.4.2,<5.0.0
|
||||||
pytest>=3.0.6,<4.0.0
|
pytest>=3.0.6,<4.0.0
|
||||||
pip>=9.0.0,<10.0.0
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
# coding: utf8
|
# coding: utf8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import pip
|
import pkg_resources
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import importlib
|
import importlib
|
||||||
from ..compat import unicode_, symlink_to
|
from ..compat import unicode_, symlink_to
|
||||||
|
@ -69,10 +69,14 @@ def get_meta(package_path, package):
|
||||||
meta = util.parse_package_meta(package_path, package)
|
meta = util.parse_package_meta(package_path, package)
|
||||||
return meta
|
return meta
|
||||||
|
|
||||||
|
def is_package(name):
|
||||||
def is_package(origin):
|
"""Check if string maps to a package installed via pip.
|
||||||
packages = pip.get_installed_distributions()
|
name (unicode): Name of package.
|
||||||
|
RETURNS (bool): True if installed package, False if not.
|
||||||
|
"""
|
||||||
|
name = name.lower() # compare package name against lowercase name
|
||||||
|
packages = pkg_resources.working_set.by_key.keys()
|
||||||
for package in packages:
|
for package in packages:
|
||||||
if package.project_name.replace('-', '_') == origin:
|
if package.lower().replace('-', '_') == name:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from ..cli.download import download, get_compatibility, get_version, check_error_depr
|
from ..cli.download import download, get_compatibility, get_version, check_error_depr
|
||||||
|
from ..cli.link import is_package
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
@ -24,3 +25,9 @@ def test_cli_download_get_matching_version_fails(model):
|
||||||
def test_cli_download_no_model_depr_error(model):
|
def test_cli_download_no_model_depr_error(model):
|
||||||
with pytest.raises(SystemExit):
|
with pytest.raises(SystemExit):
|
||||||
check_error_depr(model)
|
check_error_depr(model)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('package', ['numpy'])
|
||||||
|
def test_cli_link_is_package(package):
|
||||||
|
"""Test that an installed package via pip is recognised by link.is_package."""
|
||||||
|
assert is_package(package)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user