From 4cc7fd828f29582894a6cb69ec35a8a912fdb544 Mon Sep 17 00:00:00 2001 From: David Douard <david.douard@sdfa3.org> Date: Wed, 30 Oct 2024 15:26:55 +0100 Subject: [PATCH] Adapt entrypoints for swh.core 3.6 The new 'backend' handling mechanism in swh.core 3.6 expect the registered package to be a simple name (without '.'). So this partially revert changes from b681d147, reverting to using 'indexer_storage' as config section name. --- pyproject.toml | 2 +- requirements-swh.txt | 2 +- swh/indexer/cli.py | 8 ++-- swh/indexer/storage/__init__.py | 2 +- swh/indexer/storage/api/server.py | 12 +++--- swh/indexer/tests/conftest.py | 4 +- swh/indexer/tests/storage/test_server.py | 12 +++--- swh/indexer/tests/test_cli.py | 49 ------------------------ 8 files changed, 21 insertions(+), 70 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 7bace6e5..74672064 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -28,7 +28,7 @@ testing = {file = ["requirements-test.txt"]} [project.entry-points."swh.cli.subcommands"] "swh.indexer" = "swh.indexer.cli" -[project.entry-points."swh.indexer.storage.classes"] +[project.entry-points."swh.indexer_storage.classes"] "postgresql" = "swh.indexer.storage:IndexerStorage" "remote" = "swh.indexer.storage.api.client:RemoteStorage" "memory" = "swh.indexer.storage.in_memory:IndexerStorage" diff --git a/requirements-swh.txt b/requirements-swh.txt index 260ccc90..8b849b7d 100644 --- a/requirements-swh.txt +++ b/requirements-swh.txt @@ -1,4 +1,4 @@ -swh.core[db,http] >= 3.6 +swh.core[db,http] >= 3.6.1 swh.model >= 6.13.0 swh.objstorage >= 0.2.2 swh.storage >= 2.0.0 diff --git a/swh/indexer/cli.py b/swh/indexer/cli.py index 146c5483..d2dc484b 100644 --- a/swh/indexer/cli.py +++ b/swh/indexer/cli.py @@ -52,13 +52,13 @@ def indexer_cli_group(ctx, config_file): else: cfg = {} - if "indexer_storage" in cfg: + if "indexer.storage" in cfg: warnings.warn( - "The 'indexer_storage' configuration section should be renamed " - "as 'indexer.storage'", + "The 'indexer.storage' configuration section should be renamed " + "as 'indexer_storage'", DeprecationWarning, ) - cfg["indexer.storage"] = cfg.pop("indexer_storage") + cfg["indexer_storage"] = cfg.pop("indexer.storage") ctx.obj["config"] = cfg diff --git a/swh/indexer/storage/__init__.py b/swh/indexer/storage/__init__.py index 8d64009e..33d59b57 100644 --- a/swh/indexer/storage/__init__.py +++ b/swh/indexer/storage/__init__.py @@ -34,7 +34,7 @@ from .model import ( ) from .writer import JournalWriter -INDEXER_CFG_KEY = "indexer.storage" +INDEXER_CFG_KEY = "indexer_storage" MAPPING_NAMES = ["cff", "codemeta", "gemspec", "maven", "npm", "pkg-info"] diff --git a/swh/indexer/storage/api/server.py b/swh/indexer/storage/api/server.py index 6c90f4b5..1f4dbcd8 100644 --- a/swh/indexer/storage/api/server.py +++ b/swh/indexer/storage/api/server.py @@ -83,15 +83,15 @@ def load_and_check_config( raise FileNotFoundError(f"Configuration file {config_path} does not exist") cfg = config.read(config_path) - if "indexer_storage" in cfg: + if "indexer.storage" in cfg: warnings.warn( - "The 'indexer_storage' configuration section should be renamed " - "as 'indexer.storage'", + "The 'indexer.storage' configuration section should be renamed " + "as 'indexer_storage'", DeprecationWarning, ) - cfg["indexer.storage"] = cfg.pop("indexer_storage") - if "indexer.storage" not in cfg: - raise KeyError("Missing '%indexer.storage' configuration") + cfg["indexer_storage"] = cfg.pop("indexer.storage") + if "indexer_storage" not in cfg: + raise KeyError("Missing '%indexer_storage' configuration") return cfg diff --git a/swh/indexer/tests/conftest.py b/swh/indexer/tests/conftest.py index 65b94608..46565720 100644 --- a/swh/indexer/tests/conftest.py +++ b/swh/indexer/tests/conftest.py @@ -51,7 +51,7 @@ def swh_indexer_config( return { "storage": swh_storage_backend_config, "objstorage": {"cls": "memory"}, - "indexer.storage": idx_storage_backend_config, + "indexer_storage": idx_storage_backend_config, "tools": { "name": "file", "version": "1:5.30-1+deb9u1", @@ -67,7 +67,7 @@ def idx_storage(swh_indexer_config): indexers classes. """ - idx_storage_config = swh_indexer_config["indexer.storage"] + idx_storage_config = swh_indexer_config["indexer_storage"] return get_indexer_storage(**idx_storage_config) diff --git a/swh/indexer/tests/storage/test_server.py b/swh/indexer/tests/storage/test_server.py index 2b249871..a1fd85a9 100644 --- a/swh/indexer/tests/storage/test_server.py +++ b/swh/indexer/tests/storage/test_server.py @@ -49,13 +49,13 @@ def test_load_and_check_inexistent_config_path() -> None: def test_load_and_check_config_wrong_configuration(tmpdir) -> None: """Wrong configuration raises""" config_path = prepare_config_file(tmpdir, "something: useless") - with pytest.raises(KeyError, match="Missing '%indexer.storage' configuration"): + with pytest.raises(KeyError, match="Missing '%indexer_storage' configuration"): load_and_check_config(config_path) def test_load_and_check_config_remote_config_fine(tmpdir) -> None: """'Remote configuration is fine (when changing the default type)""" - config = {"indexer.storage": {"cls": "remote"}} + config = {"indexer_storage": {"cls": "remote"}} config_path = prepare_config_file(tmpdir, config) cfg = load_and_check_config(config_path) @@ -63,9 +63,9 @@ def test_load_and_check_config_remote_config_fine(tmpdir) -> None: def test_load_and_check_config_local_config_fine(tmpdir) -> None: - """'Complete 'local' configuration is fine""" + """'Complete 'postgresql' configuration is fine""" config = { - "indexer.storage": { + "indexer_storage": { "cls": "postgresql", "db": "db", } @@ -78,7 +78,7 @@ def test_load_and_check_config_local_config_fine(tmpdir) -> None: def test_load_and_check_config_deprecated(tmpdir) -> None: """'Complete 'local' configuration is fine""" config = { - "indexer_storage": { + "indexer.storage": { "cls": "postgresql", "db": "db", } @@ -86,4 +86,4 @@ def test_load_and_check_config_deprecated(tmpdir) -> None: config_path = prepare_config_file(tmpdir, config) with pytest.warns(DeprecationWarning): cfg = load_and_check_config(config_path) - assert "indexer.storage" in cfg + assert "indexer_storage" in cfg diff --git a/swh/indexer/tests/test_cli.py b/swh/indexer/tests/test_cli.py index f766d86a..92e611d4 100644 --- a/swh/indexer/tests/test_cli.py +++ b/swh/indexer/tests/test_cli.py @@ -5,7 +5,6 @@ import datetime from functools import reduce -import os import re from typing import Any, Dict, List @@ -13,7 +12,6 @@ import attr from click.testing import CliRunner from confluent_kafka import Consumer import pytest -import yaml from swh.indexer import fossology_license from swh.indexer.cli import indexer_cli_group @@ -560,50 +558,3 @@ def test_cli_journal_client_index__fossology_license( assert len(results) == len(expected_results) for result in results: assert result in expected_results - - -def test_cli_config_deprecated(cli_runner, swh_indexer_config, monkeypatch, tmp_path): - conffile = os.path.join(str(tmp_path), "indexer.yml") - # alter the config to use the deprecated entry - swh_indexer_config["indexer_storage"] = swh_indexer_config.pop("indexer.storage") - with open(conffile, "w") as f: - f.write(yaml.dump(swh_indexer_config)) - monkeypatch.setenv("SWH_CONFIG_FILENAME", conffile) - - expected_output = "\n".join( - [ - "cff", - "codemeta", - "composer", - "gemspec", - "gitea", - "github", - "json-sword-codemeta", - "maven", - "npm", - "nuget", - "pkg-info", - "pubspec", - "sword-codemeta", - "", - ] # must be sorted for test to pass - ) - - with pytest.warns(DeprecationWarning): - result = cli_runner.invoke( - indexer_cli_group, - ["-C", conffile, "mapping", "list"], - catch_exceptions=False, - ) - assert result.exit_code == 0, result.output - assert result.output == expected_output - - # same using SWH_CONFIG_FILENAME env var - with pytest.warns(DeprecationWarning): - result = cli_runner.invoke( - indexer_cli_group, - ["mapping", "list"], - catch_exceptions=False, - ) - assert result.exit_code == 0, result.output - assert result.output == expected_output -- GitLab