mirror of
https://github.com/explosion/spaCy.git
synced 2024-12-25 09:26:27 +03:00
Backport 2.x's avoidance of 'import pip'
This commit is contained in:
parent
91594fe671
commit
c510be9c0e
|
@ -14,4 +14,3 @@ requests>=2.11.0,<3.0.0
|
|||
regex>=2017.4.1,<2017.12.1
|
||||
ftfy>=4.4.2,<5.0.0
|
||||
pytest>=3.0.6,<4.0.0
|
||||
pip>=9.0.0,<10.0.0
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
# coding: utf8
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import pip
|
||||
import pkg_resources
|
||||
from pathlib import Path
|
||||
import importlib
|
||||
from ..compat import unicode_, symlink_to
|
||||
|
@ -69,10 +69,14 @@ def get_meta(package_path, package):
|
|||
meta = util.parse_package_meta(package_path, package)
|
||||
return meta
|
||||
|
||||
|
||||
def is_package(origin):
|
||||
packages = pip.get_installed_distributions()
|
||||
def is_package(name):
|
||||
"""Check if string maps to a package installed via pip.
|
||||
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:
|
||||
if package.project_name.replace('-', '_') == origin:
|
||||
if package.lower().replace('-', '_') == name:
|
||||
return True
|
||||
return False
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
from ..cli.download import download, get_compatibility, get_version, check_error_depr
|
||||
from ..cli.link import is_package
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -24,3 +25,9 @@ def test_cli_download_get_matching_version_fails(model):
|
|||
def test_cli_download_no_model_depr_error(model):
|
||||
with pytest.raises(SystemExit):
|
||||
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