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

Commit

Permalink
fix: install en_core_web_sm at runtime instead of via poetry (#60)
Browse files Browse the repository at this point in the history
### 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")
```
  • Loading branch information
lars-reimann authored Mar 19, 2023
1 parent b4113a4 commit ba80c2d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 deletions.
22 changes: 2 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ numpydoc = "^1.5"
scipy = "^1.10.1"
spacy = "^3.5.1"

[tool.poetry.dependencies.en_core_web_sm]
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"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.1"
pytest-cov = "^4.0.0"
Expand Down
15 changes: 10 additions & 5 deletions tests/processing/dependencies/test_get_dependency.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import spacy
import spacy.cli
from library_analyzer.processing.api.model import (
Parameter,
ParameterAssignment,
Expand All @@ -18,18 +19,22 @@
extract_lefts_and_rights,
)

nlp = spacy.load("en_core_web_sm")
try:
nlp = spacy.load("en_core_web_sm")
except OSError:
spacy.cli.download("en_core_web_sm")
nlp = spacy.load("en_core_web_sm")


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


def test_extract_action():
def test_extract_action() -> None:
action_is_ignored = nlp(
"this parameter is ignored when fit_intercept is set to False."
)
Expand Down Expand Up @@ -66,7 +71,7 @@ def test_extract_action():
assert action == Action(action=", X is assumed to be a kernel matrix")


def test_extract_condition():
def test_extract_condition() -> None:
condition_is_none = nlp(
"If func is None , then func will be the identity function."
)
Expand Down Expand Up @@ -94,7 +99,7 @@ def test_extract_condition():
assert condition == Condition(condition="If metric is a string")


def test_extract_dependencies_from_docstring_pattern_adverbial_clause():
def test_extract_dependencies_from_docstring_pattern_adverbial_clause() -> None:
param_docstring_nlp = nlp("ignored when probability is False")
dependent_param = Parameter(
id_="sklearn/sklearn.linear_model/LogisticRegression/random_state",
Expand Down

0 comments on commit ba80c2d

Please sign in to comment.