Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update build matrix and job run conditions #38

Merged
merged 72 commits into from May 10, 2023
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
a3adc3e
Update build matrix and job run conditions.
rmitsch May 9, 2023
c270baa
Limit concurrency.
rmitsch May 9, 2023
f21f9a6
Fix build matrix Python version error. Add missing external markers t…
rmitsch May 9, 2023
f2799cf
Test on installed package.
rmitsch May 9, 2023
3381905
Fix Python version typo.
rmitsch May 9, 2023
95b7d2f
Test commit.
rmitsch May 9, 2023
5e4d61c
Test commit.
rmitsch May 9, 2023
940c493
Add env block.
rmitsch May 9, 2023
f9bb020
Install dev requirements for tests.
rmitsch May 9, 2023
dc9a86f
Remove dependency check from query functions.
rmitsch May 9, 2023
11d2bc3
Use python -m in install from sdist step.
rmitsch May 9, 2023
66297d8
Test uninstalling dotenv before reinstalling it.
rmitsch May 9, 2023
e470f33
Add import guard for minichain and langchain.
rmitsch May 9, 2023
0706b9c
Merge branch 'main' into chore/expand-build-matrix
rmitsch May 9, 2023
21b832f
Add Pytest skip markers for LangChain and MiniChain tests.
rmitsch May 9, 2023
4e1bcc3
Add Pytest skip markers for NER MiniChain tests.
rmitsch May 9, 2023
a12499a
Change backend to REST from minichain.
rmitsch May 9, 2023
22af3a8
Set max-parallel to 2.
rmitsch May 9, 2023
b2302a3
Add Literal to compat.py.
rmitsch May 9, 2023
a57bf8c
Remove max-parallel.
rmitsch May 9, 2023
8bd7e26
Add version guards for minichain and langchain in requirements-dev.txt.
rmitsch May 9, 2023
5aa66a5
Fix env markers in requirements-dev.txt.
rmitsch May 9, 2023
2ff86ac
Remove inheritance in NoopTask_Incorrect.
rmitsch May 9, 2023
3311286
Disable fail-fast for test purposes.
rmitsch May 9, 2023
6f09261
Upgrade pip.
rmitsch May 9, 2023
b876ace
Narrow down Python range for MiniChain.
rmitsch May 9, 2023
db93a1e
Synch with main.
rmitsch May 9, 2023
5f53522
Add pytest config in pyproject.toml.
rmitsch May 10, 2023
aa9e19d
Add external marker to pytest config.
rmitsch May 10, 2023
141ab27
Drop mypy validation step due to fix of pre-commit config in other PR.
rmitsch May 10, 2023
915a52c
Update spacy_llm/tests/backends/test_minichain.py
rmitsch May 10, 2023
0454924
Update spacy_llm/tests/backends/test_langchain.py
rmitsch May 10, 2023
b6e60c3
Use :: instead of : for filterwarnings config.
rmitsch May 10, 2023
f9071cd
Merge branch 'chore/expand-build-matrix' of github.com:explosion/spac…
rmitsch May 10, 2023
2eef245
Reverse package/warning order in filterwarnings config.
rmitsch May 10, 2023
9196df9
Use : instead of :: for filterwarnings config.
rmitsch May 10, 2023
47731b8
Use deprecation warning marker in tests instead of in pytest config.
rmitsch May 10, 2023
93ee640
Reverse filterwarnings order.
rmitsch May 10, 2023
e7146cb
Use : instead of :: for filterwarnings.
rmitsch May 10, 2023
9bcb6b6
Move filterwarning to pyproject.toml.
rmitsch May 10, 2023
b4dcda7
Remove upper Python version bounds for langchain and minichain depend…
rmitsch May 10, 2023
8a61156
Sync with main.
rmitsch May 10, 2023
5d6790d
Limit upper Python version bound for minichain.
rmitsch May 10, 2023
58b291a
Move filterwarnings to new pytest config in setup.cfg.
rmitsch May 10, 2023
6bf0171
Update requirements-dev.txt
rmitsch May 10, 2023
0d5d313
Attempt to fix file path for Jinja NER tests.
rmitsch May 10, 2023
3089de6
Merge branch 'chore/expand-build-matrix' of github.com:explosion/spac…
rmitsch May 10, 2023
994e965
Add MANIFEST.in.
rmitsch May 10, 2023
4e26e6b
Merge branch 'main' into chore/expand-build-matrix
rmitsch May 10, 2023
c1c81cd
Add .json and .jsonl files.
rmitsch May 10, 2023
50149fd
Add test output.
rmitsch May 10, 2023
b02abab
Add test output.
rmitsch May 10, 2023
c9d810a
Fix paths in test_ner.py.
rmitsch May 10, 2023
5ebfe31
Fix EXAMPLES_DIR.
rmitsch May 10, 2023
a381e26
Add pytest mark for filterwarnings in compat.py.
rmitsch May 10, 2023
1269180
Guard pytest import.
rmitsch May 10, 2023
a4528e2
Merge branch 'main' into chore/expand-build-matrix
rmitsch May 10, 2023
c3e8d6c
Move pytest settings to pyproject.toml.
rmitsch May 10, 2023
6ed1ef4
Add testpaths.
rmitsch May 10, 2023
a77ee2d
Remove debugging step. Limit build matrix temporarily.
rmitsch May 10, 2023
9526e50
Remove regex in filter warning.
rmitsch May 10, 2023
a8608aa
Add workaround for depreciation warning originating from minichain.
rmitsch May 10, 2023
f138c3e
Add workaround for depreciation warning originating from minichain.
rmitsch May 10, 2023
7c4db2b
Add ignore in pytest call.
rmitsch May 10, 2023
07e932a
Remove .catch_warnings().
rmitsch May 10, 2023
6e14652
Move pytest config entirely into pyproject.toml.
rmitsch May 10, 2023
65a312d
Ignore all DepreciationWarnings.
rmitsch May 10, 2023
28b7526
Sync with main.
rmitsch May 10, 2023
87fd906
Fix paths in text_textcat.py.
rmitsch May 10, 2023
3019bd4
Fix paths in text_textcat.py.
rmitsch May 10, 2023
621af13
Fix paths in text_textcat.py.
rmitsch May 10, 2023
38558ae
Restore all platforms.
rmitsch May 10, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
88 changes: 78 additions & 10 deletions .github/workflows/test.yml
@@ -1,31 +1,99 @@
name: Regression Tests

on:
push:
branches:
- main
paths-ignore:
- "*.md"
pull_request:
types: [ opened, synchronize, reopened, edited ]
types: [opened, synchronize, reopened, edited]
paths-ignore:
- "*.md"
workflow_dispatch:

env:
MODULE_NAME: 'spacy_llm'
RUN_MYPY: 'false'


jobs:
run:
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
python_version: ["3.11"]
include:
- os: ubuntu-20.04
python_version: "3.6"
- os: windows-latest
python_version: "3.7"
- os: macos-latest
python_version: "3.8"
- os: ubuntu-latest
python_version: "3.9"
- os: windows-latest
python_version: "3.10"

runs-on: ${{ matrix.os }}
rmitsch marked this conversation as resolved.
Show resolved Hide resolved

steps:
- uses: actions/checkout@v3

- name: Set up Python 3.9
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.9
cache: "pip"
python-version: ${{ matrix.python_version }}

- name: Build sdist
run: |
python -m pip install --upgrade pip
python -m pip install -U build pip setuptools
python -m pip install -U -r requirements.txt
python -m build --sdist

- name: Run mypy
shell: bash
if: ${{ env.RUN_MYPY == 'true' }}
run: |
python -m mypy $MODULE_NAME

- name: Delete source directory
shell: bash
run: |
rm -rf $MODULE_NAME

- name: Uninstall all packages
run: |
python -m pip freeze > installed.txt
python -m pip uninstall -y -r installed.txt

- name: Install from sdist
shell: bash
run: |
SDIST=$(python -c "import os;print(os.listdir('./dist')[-1])" 2>&1)
python -m pip uninstall dotenv
python -m pip uninstall python-dotenv
python -m pip install python-dotenv
Comment on lines +76 to +78
Copy link
Collaborator Author

@rmitsch rmitsch May 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't great, but I don't know how to get around this - there seems to be a version of dotenv installed already that doesn't play nice with the dependency that's expected.

python -m pip install dist/$SDIST

- name: Test import
shell: bash
run: |
python -c "import $MODULE_NAME" -Werror

- name: Install dependencies
- name: Install test requirements
run: |
pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
python -m pip install -U -r requirements.txt
python -m pip install -U -r requirements-dev.txt

- name: List content
run: ls -lh

- name: Run tests
shell: bash
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
run: |
pytest spacy_llm/tests
python -m pytest --pyargs $MODULE_NAME -Werror
3 changes: 0 additions & 3 deletions .github/workflows/validate.yml
Expand Up @@ -21,6 +21,3 @@ jobs:

- name: Run all pre-commit checks
run: pre-commit run --all-files --hook-stage manual -c .pre-commit-config.yaml

- name: Run mypy
run: mypy spacy_llm
4 changes: 4 additions & 0 deletions MANIFEST.in
@@ -0,0 +1,4 @@
recursive-include spacy_llm *.py *.txt *.cfg *.jinja *.toml *.yml *.json *.jsonl
include LICENSE
include README.md
include pyproject.toml
4 changes: 2 additions & 2 deletions requirements-dev.txt
Expand Up @@ -7,5 +7,5 @@ mypy>=0.990,<1.1.0; platform_machine != "aarch64" and python_version >= "3.7"
black==22.3.0
types-requests==2.28.11.16
# Prompting libraries needed for testing
langchain>=0.0.144,<0.1
minichain>=0.3,<0.4
langchain>=0.0.144,<0.1; python_version>="3.9"
minichain>=0.3,<0.4; python_version>="3.8" and python_version<"3.11"
4 changes: 3 additions & 1 deletion setup.cfg
Expand Up @@ -50,4 +50,6 @@ allow_redefinition = true

[tool:pytest]
markers =
external: interacts with a (potentially cost-incurring) third-party API
external: interacts with a (potentially cost-incurring) third-party API
filterwarnings =
ignore:pkg_resources:DeprecationWarning
1 change: 0 additions & 1 deletion spacy_llm/backends/langchain.py
Expand Up @@ -25,7 +25,6 @@ def query_langchain() -> Callable[["BaseLLM", Iterable[str]], Iterable[str]]:
RETURNS (Callable[["langchain.llms.BaseLLM", Iterable[str]], Iterable[str]]:): Callable executing simple prompts on
the specified LangChain backend.
"""
_check_installation()

def prompt(backend: "BaseLLM", prompts: Iterable[str]) -> Iterable[str]:
return [backend(pr) for pr in prompts]
Expand Down
1 change: 0 additions & 1 deletion spacy_llm/backends/minichain.py
Expand Up @@ -23,7 +23,6 @@ def query_minichain() -> (
RETURNS (Callable[["minichain.backend.Backend", Iterable[str]], Iterable[str]]): Callable executing simple prompts
on the specified MiniChain backend.
"""
_check_installation()

def prompt(
backend: "minichain.backend.Backend", prompts: Iterable[str]
Expand Down
12 changes: 10 additions & 2 deletions spacy_llm/compat.py
@@ -1,10 +1,18 @@
# mypy: ignore-errors
import sys

try:
import pytest

# Ignore pkg_resources DeprecationWarning that may be raised for MiniChain.
pytestmark = pytest.mark.filterwarnings("ignore:pkg_resources:DeprecationWarning")
except (ImportError, AttributeError):
pass
rmitsch marked this conversation as resolved.
Show resolved Hide resolved

if sys.version_info[:2] >= (3, 8): # Python 3.8+
from typing import Protocol, runtime_checkable
from typing import Protocol, runtime_checkable, Literal
else:
from typing_extensions import Protocol, runtime_checkable # noqa: F401
from typing_extensions import Protocol, runtime_checkable, Literal # noqa: F401

try:
import langchain
Expand Down
7 changes: 5 additions & 2 deletions spacy_llm/tasks/ner.py
@@ -1,10 +1,11 @@
from typing import Any, Callable, Iterable, Literal, Optional, Tuple
from typing import Callable, Iterable, Optional, Tuple, Any

import jinja2
from spacy.tokens import Doc
from spacy.util import filter_spans

from ..registry import noop_normalizer, registry
from ..compat import Literal


def find_substrings(
Expand Down Expand Up @@ -93,7 +94,9 @@ def __init__(
labels: str,
examples: Optional[Callable[[], Iterable[Any]]] = None,
normalizer: Optional[Callable[[str], str]] = None,
alignment_mode: Literal["strict", "contract", "expand"] = "contract",
alignment_mode: Literal[
"strict", "contract", "expand" # noqa: F821
] = "contract",
case_sensitive_matching: bool = False,
single_match: bool = False,
):
Expand Down
3 changes: 3 additions & 0 deletions spacy_llm/tests/backends/test_langchain.py
@@ -1,6 +1,8 @@
import spacy
import pytest

from spacy_llm.compat import has_langchain

PIPE_CFG = {
"backend": {
"@llm_backends": "spacy.LangChain.v1",
Expand All @@ -13,6 +15,7 @@


@pytest.mark.external
@pytest.mark.skipif(has_langchain is False, reason="LangChain is not installed")
def test_initialization():
"""Test initialization and simple run"""
nlp = spacy.blank("en")
Expand Down
2 changes: 2 additions & 0 deletions spacy_llm/tests/backends/test_minichain.py
@@ -1,5 +1,6 @@
import spacy
import pytest
from spacy_llm.compat import has_minichain

PIPE_CFG = {
"backend": {
Expand All @@ -13,6 +14,7 @@


@pytest.mark.external
@pytest.mark.skipif(has_minichain is False, reason="MiniChain is not installed")
def test_initialization():
"""Test initialization and simple run"""
nlp = spacy.blank("en")
Expand Down
2 changes: 2 additions & 0 deletions spacy_llm/tests/backends/test_rest.py
Expand Up @@ -12,13 +12,15 @@
}


@pytest.mark.external
def test_initialization():
"""Test initialization and simple run"""
nlp = spacy.blank("en")
nlp.add_pipe("llm", config=PIPE_CFG)
nlp("This is a test.")


@pytest.mark.external
def test_rest_backend_error_handling():
"""Test error handling for default/minimal REST backend."""
nlp = spacy.blank("en")
Expand Down
3 changes: 1 addition & 2 deletions spacy_llm/tests/pipeline/test_llm.py
Expand Up @@ -7,7 +7,6 @@
from spacy.tokens import Doc

from spacy_llm.tasks import NoopTask
from spacy_llm.ty import LLMTask

from spacy_llm.pipeline import LLMWrapper
from spacy_llm.registry import registry
Expand Down Expand Up @@ -72,7 +71,7 @@ def test_type_checking_invalid() -> None:
"""Test type checking for consistency between functions."""

@registry.llm_tasks("IncorrectTypes.v1")
class NoopTask_Incorrect(LLMTask):
class NoopTask_Incorrect:
def __init__(self):
pass

Expand Down
18 changes: 11 additions & 7 deletions spacy_llm/tests/tasks/test_ner.py
@@ -1,4 +1,6 @@
# mypy: ignore-errors
from pathlib import Path

import pytest
import spacy
from confection import Config
Expand All @@ -7,6 +9,8 @@
from spacy_llm.registry import noop_normalizer, lowercase_normalizer, fewshot_reader
from spacy_llm.tasks.ner import find_substrings, NERTask

EXAMPLES_DIR = Path(__file__).parent / "examples"


@pytest.fixture
def zeroshot_cfg_string():
Expand Down Expand Up @@ -37,7 +41,7 @@ def zeroshot_cfg_string():

@pytest.fixture
def fewshot_cfg_string():
return """
return f"""
[nlp]
lang = "en"
pipeline = ["llm"]
Expand All @@ -54,19 +58,19 @@ def fewshot_cfg_string():

[components.llm.task.examples]
@misc: "spacy.FewShotReader.v1"
path: spacy_llm/tests/tasks/examples/ner_examples.yml
path: {str((Path(__file__).parent / "examples" / "ner_examples.yml"))}

[components.llm.task.normalizer]
@misc: "spacy.LowercaseNormalizer.v1"

[components.llm.backend]
@llm_backends: "spacy.REST.v1"
api: "OpenAI"
config: {}
config: {{}}
"""


@pytest.mark.parametrize("cfg_string", ["zeroshot_cfg_string", "fewshot_cfg_string"])
@pytest.mark.parametrize("cfg_string", ["fewshot_cfg_string"]) # "zeroshot_cfg_string",
def test_ner_config(cfg_string, request):
cfg_string = request.getfixturevalue(cfg_string)
orig_config = Config().from_str(cfg_string)
Expand Down Expand Up @@ -368,9 +372,9 @@ def test_jinja_template_rendering_without_examples():
@pytest.mark.parametrize(
"examples_path",
[
"spacy_llm/tests/tasks/examples/ner_examples.json",
"spacy_llm/tests/tasks/examples/ner_examples.yml",
"spacy_llm/tests/tasks/examples/ner_examples.jsonl",
str(EXAMPLES_DIR / "ner_examples.json"),
str(EXAMPLES_DIR / "ner_examples.yml"),
str(EXAMPLES_DIR / "ner_examples.jsonl"),
],
)
def test_jinja_template_rendering_with_examples(examples_path):
Expand Down