Skip to content
This repository was archived by the owner on Nov 23, 2024. It is now read-only.

Commit ba80c2d

Browse files
authored
fix: install en_core_web_sm at runtime instead of via poetry (#60)
### Summary of Changes The previous setup worked perfectly until we tried to publish the package to PyPI: ``` Invalid value for requires_dist. Error: Can't have direct dependency: 'en_core_web_sm @ https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl' ``` So, we must now instead guard every usage of `en_core_web_sm` with this block to ensure it is downloaded before it is loaded: ```py try: nlp = spacy.load("en_core_web_sm") except OSError: spacy.cli.download("en_core_web_sm") nlp = spacy.load("en_core_web_sm") ```
1 parent b4113a4 commit ba80c2d

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

poetry.lock

Lines changed: 2 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@ numpydoc = "^1.5"
2424
scipy = "^1.10.1"
2525
spacy = "^3.5.1"
2626

27-
[tool.poetry.dependencies.en_core_web_sm]
28-
url = "https://github.com/explosion/spacy-models/releases/download/en_core_web_sm-3.5.0/en_core_web_sm-3.5.0-py3-none-any.whl"
29-
3027
[tool.poetry.group.dev.dependencies]
3128
pytest = "^7.2.1"
3229
pytest-cov = "^4.0.0"

tests/processing/dependencies/test_get_dependency.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import spacy
2+
import spacy.cli
23
from library_analyzer.processing.api.model import (
34
Parameter,
45
ParameterAssignment,
@@ -18,18 +19,22 @@
1819
extract_lefts_and_rights,
1920
)
2021

21-
nlp = spacy.load("en_core_web_sm")
22+
try:
23+
nlp = spacy.load("en_core_web_sm")
24+
except OSError:
25+
spacy.cli.download("en_core_web_sm")
26+
nlp = spacy.load("en_core_web_sm")
2227

2328

24-
def test_extract_lefts_and_rights():
29+
def test_extract_lefts_and_rights() -> None:
2530
# string from https://spacy.io/usage/linguistic-features#navigating
2631
doc = nlp("Autonomous cars shift insurance liability toward manufacturers")
2732
doc_head_token = doc[2]
2833
extracted_lefts_and_rights = extract_lefts_and_rights(doc_head_token)
2934
assert extracted_lefts_and_rights == doc.text.split()
3035

3136

32-
def test_extract_action():
37+
def test_extract_action() -> None:
3338
action_is_ignored = nlp(
3439
"this parameter is ignored when fit_intercept is set to False."
3540
)
@@ -66,7 +71,7 @@ def test_extract_action():
6671
assert action == Action(action=", X is assumed to be a kernel matrix")
6772

6873

69-
def test_extract_condition():
74+
def test_extract_condition() -> None:
7075
condition_is_none = nlp(
7176
"If func is None , then func will be the identity function."
7277
)
@@ -94,7 +99,7 @@ def test_extract_condition():
9499
assert condition == Condition(condition="If metric is a string")
95100

96101

97-
def test_extract_dependencies_from_docstring_pattern_adverbial_clause():
102+
def test_extract_dependencies_from_docstring_pattern_adverbial_clause() -> None:
98103
param_docstring_nlp = nlp("ignored when probability is False")
99104
dependent_param = Parameter(
100105
id_="sklearn/sklearn.linear_model/LogisticRegression/random_state",

0 commit comments

Comments
 (0)