diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index 5f8ba9285ac..5f731a31595 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -7,9 +7,12 @@ on: # ** matches 'zero or more of any character' - 'release-v[0-9]+.[0-9]+.[0-9]+**' - 'prerelease-v[0-9]+.[0-9]+.[0-9]+**' + +permissions: {} + jobs: build_wheels: - uses: explosion/gha-cibuildwheel/.github/workflows/cibuildwheel.yml@main + uses: explosion/gha-cibuildwheel/.github/workflows/cibuildwheel.yml@2c98f757f13d112cf73fcf4b627249f1fffb5aae # main permissions: contents: write actions: read diff --git a/.github/workflows/explosionbot.yml b/.github/workflows/explosionbot.yml index 78a27cfa3ba..979385ccb90 100644 --- a/.github/workflows/explosionbot.yml +++ b/.github/workflows/explosionbot.yml @@ -6,6 +6,8 @@ on: - created - edited +permissions: {} + jobs: explosion-bot: if: github.repository_owner == 'explosion' @@ -15,13 +17,15 @@ jobs: env: GITHUB_CONTEXT: ${{ toJson(github) }} run: echo "$GITHUB_CONTEXT" - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 - name: Install and run explosion-bot run: | - pip install git+https://${{ secrets.EXPLOSIONBOT_TOKEN }}@github.com/explosion/explosion-bot + git config --global url."https://x-access-token:${EXPLOSIONBOT_TOKEN}@github.com/".insteadOf "https://github.com/" + pip install git+https://github.com/explosion/explosion-bot python -m explosionbot env: + EXPLOSIONBOT_TOKEN: ${{ secrets.EXPLOSIONBOT_TOKEN }} INPUT_TOKEN: ${{ secrets.EXPLOSIONBOT_TOKEN }} INPUT_BK_TOKEN: ${{ secrets.BUILDKITE_SECRET }} ENABLED_COMMANDS: "test_gpu,test_slow,test_slow_gpu" diff --git a/.github/workflows/issue-manager.yml b/.github/workflows/issue-manager.yml index 6c7d7d5a6f8..264707485e7 100644 --- a/.github/workflows/issue-manager.yml +++ b/.github/workflows/issue-manager.yml @@ -11,12 +11,16 @@ on: types: - labeled +permissions: {} + jobs: issue-manager: + permissions: + issues: write if: github.repository_owner == 'explosion' runs-on: ubuntu-latest steps: - - uses: tiangolo/issue-manager@0.4.0 + - uses: tiangolo/issue-manager@4d1b7e05935a404dc8337d30bd23be46be8bb8e5 # 0.4.0 with: token: ${{ secrets.GITHUB_TOKEN }} config: > diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml index 2bbdd64c771..8fcf3028476 100644 --- a/.github/workflows/lock.yml +++ b/.github/workflows/lock.yml @@ -16,7 +16,7 @@ jobs: if: github.repository_owner == 'explosion' runs-on: ubuntu-latest steps: - - uses: dessant/lock-threads@v5 + - uses: dessant/lock-threads@1bf7ec25051fe7c00bdd17e6a7cf3d7bfb7dc771 # v5 with: process-only: 'issues' issue-inactive-days: '30' diff --git a/.github/workflows/publish_pypi.yml b/.github/workflows/publish_pypi.yml index 9f432874cc2..fcc6f2a9999 100644 --- a/.github/workflows/publish_pypi.yml +++ b/.github/workflows/publish_pypi.yml @@ -8,6 +8,8 @@ on: types: - published +permissions: {} + jobs: upload_pypi: runs-on: ubuntu-latest @@ -21,7 +23,7 @@ jobs: # or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this) # if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') steps: - - uses: robinraju/release-downloader@v1 + - uses: robinraju/release-downloader@daf26c55d821e836577a15f77d86ddc078948b05 # v1 with: tag: ${{ github.event.release.tag_name }} fileName: '*' diff --git a/.github/workflows/spacy_universe_alert.yml b/.github/workflows/spacy_universe_alert.yml index 01731ffe0d7..ec0230699be 100644 --- a/.github/workflows/spacy_universe_alert.yml +++ b/.github/workflows/spacy_universe_alert.yml @@ -5,21 +5,16 @@ on: paths: - "website/meta/universe.json" +permissions: {} + jobs: build: if: github.repository_owner == 'explosion' runs-on: ubuntu-latest steps: - - name: Dump GitHub context - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - PR_NUMBER: ${{github.event.number}} - run: | - echo "$GITHUB_CONTEXT" - - - uses: actions/checkout@v4 - - uses: actions/setup-python@v4 + - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 + - uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 with: python-version: '3.10' - name: Install Bernadette app dependency and send an alert diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index adfce07f50b..b20dba12f04 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -19,6 +19,8 @@ on: - "*.mdx" - "website/**" +permissions: {} + jobs: validate: name: Validate @@ -26,10 +28,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repo - uses: actions/checkout@v4 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Configure Python version - uses: actions/setup-python@v4 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 with: python-version: "3.10" @@ -45,19 +47,19 @@ jobs: name: Test needs: Validate strategy: - fail-fast: true + fail-fast: false matrix: os: [ubuntu-latest, windows-latest, macos-latest] - python_version: ["3.10", "3.11", "3.12", "3.13"] + python_version: ["3.10", "3.11", "3.12", "3.13", "3.14"] runs-on: ${{ matrix.os }} steps: - name: Check out repo - uses: actions/checkout@v4 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Configure Python version - uses: actions/setup-python@v4 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 with: python-version: ${{ matrix.python_version }} @@ -93,7 +95,7 @@ jobs: shell: bash - name: Test import - run: python -W error -c "import spacy" + run: python -W error -W 'ignore:Core Pydantic V1:UserWarning:pydantic' -c "import spacy" - name: "Test download CLI" run: | @@ -154,7 +156,7 @@ jobs: - name: "Run CPU tests" run: | - python -m pytest --pyargs spacy -W error + python -m pytest --pyargs spacy -W error -W 'ignore:Core Pydantic V1:UserWarning:pydantic' if: "!(startsWith(matrix.os, 'macos') && matrix.python_version == '3.11')" - name: "Run CPU tests with thinc-apple-ops" diff --git a/.github/workflows/universe_validation.yml b/.github/workflows/universe_validation.yml index ce7df49dbae..e97850cd4b0 100644 --- a/.github/workflows/universe_validation.yml +++ b/.github/workflows/universe_validation.yml @@ -13,6 +13,8 @@ on: paths: - "website/meta/universe.json" +permissions: {} + jobs: validate: name: Validate @@ -20,10 +22,10 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out repo - uses: actions/checkout@v4 + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6 - name: Configure Python version - uses: actions/setup-python@v4 + uses: actions/setup-python@a309ff8b426b58ec0e2a45f0f869d46889d02405 # v6 with: python-version: "3.7" diff --git a/pyproject.toml b/pyproject.toml index 9e6cab69da3..395c2f7a108 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ requires = [ "cymem>=2.0.2,<2.1.0", "preshed>=3.0.2,<3.1.0", "murmurhash>=0.28.0,<1.1.0", - "thinc>=8.3.4,<8.4.0", + "thinc>=8.3.12,<8.4.0", "numpy>=2.0.0,<3.0.0" ] build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt index 866128b31b6..50c6382bea3 100644 --- a/requirements.txt +++ b/requirements.txt @@ -3,19 +3,19 @@ spacy-legacy>=3.0.11,<3.1.0 spacy-loggers>=1.0.0,<2.0.0 cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 -thinc>=8.3.4,<8.4.0 -ml_datasets>=0.2.0,<0.3.0 +thinc>=8.3.12,<8.4.0 +ml_datasets>=0.2.1,<0.3.0 murmurhash>=0.28.0,<1.1.0 wasabi>=0.9.1,<1.2.0 -srsly>=2.4.3,<3.0.0 +srsly>=2.5.3,<3.0.0 catalogue>=2.0.6,<2.1.0 typer>=0.3.0,<1.0.0 -weasel>=0.4.2,<0.5.0 +weasel>=1.0.0,<2.0.0 # Third party dependencies numpy>=2.0.0,<3.0.0 requests>=2.13.0,<3.0.0 tqdm>=4.38.0,<5.0.0 -pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0 +pydantic>=2.0.0,<3.0.0 jinja2 # Official Python utilities setuptools @@ -34,4 +34,4 @@ types-requests types-setuptools>=57.0.0 ruff>=0.9.0 cython-lint>=0.15.0 -confection>=0.0.4,<1.0.0 +confection>=1.1.0,<2.0.0 diff --git a/setup.cfg b/setup.cfg index 1ef8e303125..66cf942218b 100644 --- a/setup.cfg +++ b/setup.cfg @@ -22,6 +22,7 @@ classifiers = Programming Language :: Python :: 3.11 Programming Language :: Python :: 3.12 Programming Language :: Python :: 3.13 + Programming Language :: Python :: 3.14 Topic :: Scientific/Engineering project_urls = Release notes = https://github.com/explosion/spaCy/releases @@ -41,7 +42,7 @@ setup_requires = cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 murmurhash>=0.28.0,<1.1.0 - thinc>=8.3.4,<8.4.0 + thinc>=8.3.12,<8.4.0 install_requires = # Our libraries spacy-legacy>=3.0.11,<3.1.0 @@ -49,19 +50,19 @@ install_requires = murmurhash>=0.28.0,<1.1.0 cymem>=2.0.2,<2.1.0 preshed>=3.0.2,<3.1.0 - thinc>=8.3.4,<8.4.0 + thinc>=8.3.12,<8.4.0 wasabi>=0.9.1,<1.2.0 - srsly>=2.4.3,<3.0.0 + srsly>=2.5.3,<3.0.0 catalogue>=2.0.6,<2.1.0 - weasel>=0.4.2,<0.5.0 - confection>=0.0.4,<1.0.0 + weasel>=1.0.0,<2.0.0 + confection>=1.1.0,<2.0.0 # Third-party dependencies typer>=0.3.0,<1.0.0 tqdm>=4.38.0,<5.0.0 numpy>=1.15.0; python_version < "3.9" numpy>=1.19.0; python_version >= "3.9" requests>=2.13.0,<3.0.0 - pydantic>=1.7.4,!=1.8,!=1.8.1,<3.0.0 + pydantic>=2.0.0,<3.0.0 jinja2 # Official Python utilities setuptools @@ -135,6 +136,9 @@ formats = gztar markers = slow: mark a test as slow issue: reference specific issue +filterwarnings = + error + ignore:Core Pydantic V1:UserWarning:pydantic [mypy] ignore_missing_imports = True diff --git a/spacy/__init__.py b/spacy/__init__.py index 9d7fdf29ba7..5b3ff25c872 100644 --- a/spacy/__init__.py +++ b/spacy/__init__.py @@ -41,7 +41,7 @@ ConfigSchemaInit, ConfigSchema, ): - _schema.model_rebuild(_types_namespace=_rebuild_ns) + _schema.model_rebuild(_types_namespace=_rebuild_ns) # type: ignore[attr-defined] if sys.maxunicode == 65535: raise SystemError(Errors.E130) diff --git a/spacy/cli/debug_config.py b/spacy/cli/debug_config.py index f049d7fd149..4876b6ff9e1 100644 --- a/spacy/cli/debug_config.py +++ b/spacy/cli/debug_config.py @@ -82,10 +82,10 @@ def debug_config( config = nlp.config.interpolate() msg.divider("Config validation for [initialize]") with show_validation_error(config_path): - T = registry.resolve(config["initialize"], schema=ConfigSchemaInit) + T = registry.resolve(config["initialize"], schema=ConfigSchemaInit) # type: ignore[arg-type] msg.divider("Config validation for [training]") with show_validation_error(config_path): - T = registry.resolve(config["training"], schema=ConfigSchemaTraining) + T = registry.resolve(config["training"], schema=ConfigSchemaTraining) # type: ignore[arg-type] dot_names = [T["train_corpus"], T["dev_corpus"]] util.resolve_dot_names(config, dot_names) msg.good("Config is valid") diff --git a/spacy/cli/debug_data.py b/spacy/cli/debug_data.py index df52250cf90..6ba18e7f224 100644 --- a/spacy/cli/debug_data.py +++ b/spacy/cli/debug_data.py @@ -137,7 +137,7 @@ def debug_data( cfg = util.load_config(config_path, overrides=config_overrides) nlp = util.load_model_from_config(cfg) config = nlp.config.interpolate() - T = registry.resolve(config["training"], schema=ConfigSchemaTraining) + T = registry.resolve(config["training"], schema=ConfigSchemaTraining) # type: ignore[arg-type] # Use original config here, not resolved version sourced_components = get_sourced_components(cfg) frozen_components = T["frozen_components"] diff --git a/spacy/cli/debug_model.py b/spacy/cli/debug_model.py index ec7ffe099d7..dc0de3e1489 100644 --- a/spacy/cli/debug_model.py +++ b/spacy/cli/debug_model.py @@ -89,7 +89,7 @@ def debug_model_cli( with show_validation_error(config_path): nlp = util.load_model_from_config(raw_config) config = nlp.config.interpolate() - T = registry.resolve(config["training"], schema=ConfigSchemaTraining) + T = registry.resolve(config["training"], schema=ConfigSchemaTraining) # type: ignore[arg-type] seed = T["seed"] if seed is not None: msg.info(f"Fixing random seed: {seed}") diff --git a/spacy/cli/find_threshold.py b/spacy/cli/find_threshold.py index 05b6fdc9517..1873f476fcd 100644 --- a/spacy/cli/find_threshold.py +++ b/spacy/cli/find_threshold.py @@ -207,8 +207,10 @@ def filter_config( ), ) if hasattr(pipe, "cfg"): - nlp.get_pipe(pipe_name).cfg = set_nested_item( - pipe.cfg, config_keys, threshold + nlp.get_pipe(pipe_name).cfg = set_nested_item( # type: ignore[attr-defined] + pipe.cfg, + config_keys, + threshold, # type: ignore[attr-defined] ) eval_scores = nlp.evaluate(dev_dataset) diff --git a/spacy/cli/init_config.py b/spacy/cli/init_config.py index 2cb39056d5e..c7081040280 100644 --- a/spacy/cli/init_config.py +++ b/spacy/cli/init_config.py @@ -216,7 +216,7 @@ def init_config( # Filter out duplicates since tok2vec and transformer are added by template pipeline = [pipe for pipe in pipeline if pipe not in ("tok2vec", "transformer")] defaults = RECOMMENDATIONS["__default__"] - reco = RecommendationSchema(**RECOMMENDATIONS.get(lang, defaults)).dict() + reco = RecommendationSchema(**RECOMMENDATIONS.get(lang, defaults)).model_dump() variables = { "lang": lang, "components": pipeline, diff --git a/spacy/compat.py b/spacy/compat.py index abaca49302f..828ed1ba62e 100644 --- a/spacy/compat.py +++ b/spacy/compat.py @@ -35,8 +35,8 @@ try: # Python 3.8+ import importlib.metadata as importlib_metadata except ImportError: - from catalogue import ( - _importlib_metadata as importlib_metadata, # type: ignore[no-redef] # noqa: F401 + from catalogue import ( # type: ignore[no-redef] + _importlib_metadata as importlib_metadata, # noqa: F401 ) from thinc.api import Optimizer # noqa: F401 diff --git a/spacy/lang/es/lemmatizer.py b/spacy/lang/es/lemmatizer.py index 05238a75b70..3102f3b9bc4 100644 --- a/spacy/lang/es/lemmatizer.py +++ b/spacy/lang/es/lemmatizer.py @@ -416,7 +416,7 @@ def lemmatize_verb_pron( rule = self.select_rule("verb", features) verb_lemma = self.lemmatize_verb( verb, - features - {"PronType=Prs"}, + features - {"PronType=Prs"}, # type: ignore[operator] rule, index, # type: ignore[operator] )[0] diff --git a/spacy/language.py b/spacy/language.py index ea9ba3cae8b..8e91018254e 100644 --- a/spacy/language.py +++ b/spacy/language.py @@ -1323,7 +1323,7 @@ def get_examples(): # Make sure the config is interpolated so we can resolve subsections config = self.config.interpolate() # These are the settings provided in the [initialize] block in the config - I = registry.resolve(config["initialize"], schema=ConfigSchemaInit) + I = registry.resolve(config["initialize"], schema=ConfigSchemaInit) # type: ignore[arg-type] before_init = I["before_init"] if before_init is not None: before_init(self) @@ -1353,7 +1353,7 @@ def get_examples(): proc.initialize(get_examples, nlp=self, **p_settings) pretrain_cfg = config.get("pretraining") if pretrain_cfg: - P = registry.resolve(pretrain_cfg, schema=ConfigSchemaPretrain) + P = registry.resolve(pretrain_cfg, schema=ConfigSchemaPretrain) # type: ignore[arg-type] init_tok2vec(self, P, I) self._link_components() self._optimizer = sgd @@ -1823,7 +1823,7 @@ def from_config( orig_pretraining = config.pop("pretraining", None) config["components"] = {} if auto_fill: - filled = registry.fill(config, validate=validate, schema=ConfigSchema) + filled = registry.fill(config, validate=validate, schema=ConfigSchema) # type: ignore[arg-type] else: filled = config filled["components"] = orig_pipeline @@ -1832,7 +1832,9 @@ def from_config( filled["pretraining"] = orig_pretraining config["pretraining"] = orig_pretraining resolved_nlp = registry.resolve( - filled["nlp"], validate=validate, schema=ConfigSchemaNlp + filled["nlp"], + validate=validate, + schema=ConfigSchemaNlp, # type: ignore[arg-type] ) create_tokenizer = resolved_nlp["tokenizer"] create_vectors = resolved_nlp["vectors"] diff --git a/spacy/matcher/phrasematcher.pyx b/spacy/matcher/phrasematcher.pyx index ccc830e35c1..a71f85f6e63 100644 --- a/spacy/matcher/phrasematcher.pyx +++ b/spacy/matcher/phrasematcher.pyx @@ -57,7 +57,7 @@ cdef class PhraseMatcher: attr = "ORTH" if attr == "IS_SENT_START": attr = "SENT_START" - if attr.lower() not in TokenPattern().dict(): + if attr.lower() not in TokenPattern().model_dump(): raise ValueError(Errors.E152.format(attr=attr)) self.attr = IDS.get(attr) diff --git a/spacy/pipeline/_edit_tree_internals/schemas.py b/spacy/pipeline/_edit_tree_internals/schemas.py index 1f12b63607c..ef7a076b6cd 100644 --- a/spacy/pipeline/_edit_tree_internals/schemas.py +++ b/spacy/pipeline/_edit_tree_internals/schemas.py @@ -6,6 +6,7 @@ ConfigDict, Field, RootModel, + StrictBool, StrictInt, StrictStr, ValidationError, diff --git a/spacy/pipeline/factories.py b/spacy/pipeline/factories.py index e76704237ee..8c71067b32e 100644 --- a/spacy/pipeline/factories.py +++ b/spacy/pipeline/factories.py @@ -14,9 +14,10 @@ ) # Import factory default configurations -from ..pipeline.entity_linker import DEFAULT_NEL_MODEL, EntityLinker, EntityLinker_v1 +from ..pipeline.entity_linker import DEFAULT_NEL_MODEL, EntityLinker from ..pipeline.entityruler import DEFAULT_ENT_ID_SEP, EntityRuler from ..pipeline.functions import DocCleaner, TokenSplitter +from ..pipeline.legacy import EntityLinker_v1 from ..pipeline.lemmatizer import Lemmatizer from ..pipeline.morphologizer import DEFAULT_MORPH_MODEL, Morphologizer from ..pipeline.multitask import DEFAULT_MT_MODEL, MultitaskObjective diff --git a/spacy/schemas.py b/spacy/schemas.py index e3200348013..359c3fd0f83 100644 --- a/spacy/schemas.py +++ b/spacy/schemas.py @@ -251,7 +251,7 @@ class TokenPatternOperatorSimple(str, Enum): TokenPatternOperatorMinMax = constr(pattern=r"^(\{\d+\}|\{\d+,\d*\}|\{\d*,\d+\})$") -TokenPatternOperator = Union[TokenPatternOperatorSimple, TokenPatternOperatorMinMax] +TokenPatternOperator = Union[TokenPatternOperatorSimple, TokenPatternOperatorMinMax] # type: ignore[valid-type] StringValue = Union[TokenPatternString, StrictStr] NumberValue = Union[TokenPatternNumber, StrictInt, StrictFloat] UnderscoreValue = Union[ @@ -420,8 +420,8 @@ class ConfigSchemaInit(BaseModel): lookups: Optional[Lookups] = Field(..., title="Vocabulary lookups, e.g. lexeme normalization") vectors: Optional[StrictStr] = Field(..., title="Path to vectors") init_tok2vec: Optional[StrictStr] = Field(..., title="Path to pretrained tok2vec weights") - tokenizer: Dict[StrictStr, Any] = Field(..., help="Arguments to be passed into Tokenizer.initialize") - components: Dict[StrictStr, Dict[StrictStr, Any]] = Field(..., help="Arguments for TrainablePipe.initialize methods of pipeline components, keyed by component") + tokenizer: Dict[StrictStr, Any] = Field(..., title="Arguments to be passed into Tokenizer.initialize") + components: Dict[StrictStr, Dict[StrictStr, Any]] = Field(..., title="Arguments for TrainablePipe.initialize methods of pipeline components, keyed by component") before_init: Optional[Callable[["Language"], "Language"]] = Field(..., title="Optional callback to modify nlp object before initialization") after_init: Optional[Callable[["Language"], "Language"]] = Field(..., title="Optional callback to modify nlp object after initialization") # fmt: on diff --git a/spacy/tests/lang/zh/test_tokenizer.py b/spacy/tests/lang/zh/test_tokenizer.py index cdba5e39709..cb9b4ec539a 100644 --- a/spacy/tests/lang/zh/test_tokenizer.py +++ b/spacy/tests/lang/zh/test_tokenizer.py @@ -1,5 +1,5 @@ import pytest -from thinc.api import ConfigValidationError +from confection import ConfigValidationError from spacy.lang.zh import Chinese, _get_pkuseg_trie_data diff --git a/spacy/tests/package/test_requirements.py b/spacy/tests/package/test_requirements.py index b9276441222..f4c6f056aa2 100644 --- a/spacy/tests/package/test_requirements.py +++ b/spacy/tests/package/test_requirements.py @@ -15,6 +15,7 @@ def test_build_dependencies(): "cython-lint", "black", "isort", + "ruff", "mypy", "types-dataclasses", "types-mock", diff --git a/spacy/tests/pipeline/test_textcat.py b/spacy/tests/pipeline/test_textcat.py index f2bfe003d39..e7499404f63 100644 --- a/spacy/tests/pipeline/test_textcat.py +++ b/spacy/tests/pipeline/test_textcat.py @@ -24,6 +24,7 @@ ) from spacy.pipeline.tok2vec import DEFAULT_TOK2VEC_MODEL from spacy.scorer import Scorer +from spacy.tests.tok2vec import build_lazy_init_tok2vec as _ # noqa: F401 from spacy.tokens import Doc, DocBin from spacy.training import Example from spacy.training.initialize import init_nlp diff --git a/spacy/tests/test_cli.py b/spacy/tests/test_cli.py index 8415e5c92ff..4bac40f0b89 100644 --- a/spacy/tests/test_cli.py +++ b/spacy/tests/test_cli.py @@ -1229,6 +1229,9 @@ def test_download_rejects_relative_urls(monkeypatch): relative path in the filename""" monkeypatch.setattr(download_module, "run_command", lambda cmd: None) + monkeypatch.setattr( + download_module, "_get_pip_install_cmd", lambda: ["pip", "install"] + ) # Check that normal download works download_module.download("en_core_web_sm-3.7.1", direct=True) diff --git a/spacy/training/batchers.py b/spacy/training/batchers.py index 8158e9fdf8f..40e437dcc8c 100644 --- a/spacy/training/batchers.py +++ b/spacy/training/batchers.py @@ -4,6 +4,7 @@ Any, Callable, Iterable, + Iterator, List, Optional, Sequence, diff --git a/spacy/training/corpus.py b/spacy/training/corpus.py index 5cc2733a540..30e32911e6b 100644 --- a/spacy/training/corpus.py +++ b/spacy/training/corpus.py @@ -50,9 +50,10 @@ def create_jsonl_reader( @util.registry.readers("spacy.read_labels.v1") -def read_labels(path: Path, *, require: bool = False): +def read_labels(path: Union[str, Path], *, require: bool = False): # I decided not to give this a generic name, because I don't want people to # use it for arbitrary stuff, as I want this require arg with default False. + path = Path(path) if not require and not path.exists(): return None return srsly.read_json(path) diff --git a/spacy/training/initialize.py b/spacy/training/initialize.py index 64cdddf9c43..164a0867494 100644 --- a/spacy/training/initialize.py +++ b/spacy/training/initialize.py @@ -50,7 +50,7 @@ def init_nlp(config: Config, *, use_gpu: int = -1) -> "Language": logger.info("Set up nlp object from config") config = nlp.config.interpolate() # Resolve all training-relevant sections using the filled nlp config - T = registry.resolve(config["training"], schema=ConfigSchemaTraining) + T = registry.resolve(config["training"], schema=ConfigSchemaTraining) # type: ignore[arg-type] dot_names = [T["train_corpus"], T["dev_corpus"]] if not isinstance(T["train_corpus"], str): raise ConfigValidationError( diff --git a/spacy/training/loop.py b/spacy/training/loop.py index 6f5099858f1..d6f1ad7d608 100644 --- a/spacy/training/loop.py +++ b/spacy/training/loop.py @@ -62,7 +62,7 @@ def train( allocator = config["training"]["gpu_allocator"] if use_gpu >= 0 and allocator: set_gpu_allocator(allocator) - T = registry.resolve(config["training"], schema=ConfigSchemaTraining) + T = registry.resolve(config["training"], schema=ConfigSchemaTraining) # type: ignore[arg-type] dot_names = [T["train_corpus"], T["dev_corpus"]] train_corpus, dev_corpus = resolve_dot_names(config, dot_names) optimizer = T["optimizer"] diff --git a/spacy/training/pretrain.py b/spacy/training/pretrain.py index 14a813a0993..32eada4d749 100644 --- a/spacy/training/pretrain.py +++ b/spacy/training/pretrain.py @@ -42,7 +42,7 @@ def pretrain( config["initialize"]["init_tok2vec"] = None nlp = load_model_from_config(config) _config = nlp.config.interpolate() - P = registry.resolve(_config["pretraining"], schema=ConfigSchemaPretrain) + P = registry.resolve(_config["pretraining"], schema=ConfigSchemaPretrain) # type: ignore[arg-type] corpus = dot_to_object(_config, P["corpus"]) corpus = registry.resolve({"corpus": corpus})["corpus"] batcher = P["batcher"]