Skip to content

Commit 4cc7fd8

Browse files
committed
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 b681d14, reverting to using 'indexer_storage' as config section name.
1 parent 2eb7b04 commit 4cc7fd8

File tree

8 files changed

+21
-70
lines changed

8 files changed

+21
-70
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ testing = {file = ["requirements-test.txt"]}
2828
[project.entry-points."swh.cli.subcommands"]
2929
"swh.indexer" = "swh.indexer.cli"
3030

31-
[project.entry-points."swh.indexer.storage.classes"]
31+
[project.entry-points."swh.indexer_storage.classes"]
3232
"postgresql" = "swh.indexer.storage:IndexerStorage"
3333
"remote" = "swh.indexer.storage.api.client:RemoteStorage"
3434
"memory" = "swh.indexer.storage.in_memory:IndexerStorage"

requirements-swh.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
swh.core[db,http] >= 3.6
1+
swh.core[db,http] >= 3.6.1
22
swh.model >= 6.13.0
33
swh.objstorage >= 0.2.2
44
swh.storage >= 2.0.0

swh/indexer/cli.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@ def indexer_cli_group(ctx, config_file):
5252
else:
5353
cfg = {}
5454

55-
if "indexer_storage" in cfg:
55+
if "indexer.storage" in cfg:
5656
warnings.warn(
57-
"The 'indexer_storage' configuration section should be renamed "
58-
"as 'indexer.storage'",
57+
"The 'indexer.storage' configuration section should be renamed "
58+
"as 'indexer_storage'",
5959
DeprecationWarning,
6060
)
61-
cfg["indexer.storage"] = cfg.pop("indexer_storage")
61+
cfg["indexer_storage"] = cfg.pop("indexer.storage")
6262

6363
ctx.obj["config"] = cfg
6464

swh/indexer/storage/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
)
3535
from .writer import JournalWriter
3636

37-
INDEXER_CFG_KEY = "indexer.storage"
37+
INDEXER_CFG_KEY = "indexer_storage"
3838

3939

4040
MAPPING_NAMES = ["cff", "codemeta", "gemspec", "maven", "npm", "pkg-info"]

swh/indexer/storage/api/server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ def load_and_check_config(
8383
raise FileNotFoundError(f"Configuration file {config_path} does not exist")
8484

8585
cfg = config.read(config_path)
86-
if "indexer_storage" in cfg:
86+
if "indexer.storage" in cfg:
8787
warnings.warn(
88-
"The 'indexer_storage' configuration section should be renamed "
89-
"as 'indexer.storage'",
88+
"The 'indexer.storage' configuration section should be renamed "
89+
"as 'indexer_storage'",
9090
DeprecationWarning,
9191
)
92-
cfg["indexer.storage"] = cfg.pop("indexer_storage")
93-
if "indexer.storage" not in cfg:
94-
raise KeyError("Missing '%indexer.storage' configuration")
92+
cfg["indexer_storage"] = cfg.pop("indexer.storage")
93+
if "indexer_storage" not in cfg:
94+
raise KeyError("Missing '%indexer_storage' configuration")
9595

9696
return cfg
9797

swh/indexer/tests/conftest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def swh_indexer_config(
5151
return {
5252
"storage": swh_storage_backend_config,
5353
"objstorage": {"cls": "memory"},
54-
"indexer.storage": idx_storage_backend_config,
54+
"indexer_storage": idx_storage_backend_config,
5555
"tools": {
5656
"name": "file",
5757
"version": "1:5.30-1+deb9u1",
@@ -67,7 +67,7 @@ def idx_storage(swh_indexer_config):
6767
indexers classes.
6868
6969
"""
70-
idx_storage_config = swh_indexer_config["indexer.storage"]
70+
idx_storage_config = swh_indexer_config["indexer_storage"]
7171
return get_indexer_storage(**idx_storage_config)
7272

7373

swh/indexer/tests/storage/test_server.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,23 @@ def test_load_and_check_inexistent_config_path() -> None:
4949
def test_load_and_check_config_wrong_configuration(tmpdir) -> None:
5050
"""Wrong configuration raises"""
5151
config_path = prepare_config_file(tmpdir, "something: useless")
52-
with pytest.raises(KeyError, match="Missing '%indexer.storage' configuration"):
52+
with pytest.raises(KeyError, match="Missing '%indexer_storage' configuration"):
5353
load_and_check_config(config_path)
5454

5555

5656
def test_load_and_check_config_remote_config_fine(tmpdir) -> None:
5757
"""'Remote configuration is fine (when changing the default type)"""
58-
config = {"indexer.storage": {"cls": "remote"}}
58+
config = {"indexer_storage": {"cls": "remote"}}
5959
config_path = prepare_config_file(tmpdir, config)
6060
cfg = load_and_check_config(config_path)
6161

6262
assert cfg == config
6363

6464

6565
def test_load_and_check_config_local_config_fine(tmpdir) -> None:
66-
"""'Complete 'local' configuration is fine"""
66+
"""'Complete 'postgresql' configuration is fine"""
6767
config = {
68-
"indexer.storage": {
68+
"indexer_storage": {
6969
"cls": "postgresql",
7070
"db": "db",
7171
}
@@ -78,12 +78,12 @@ def test_load_and_check_config_local_config_fine(tmpdir) -> None:
7878
def test_load_and_check_config_deprecated(tmpdir) -> None:
7979
"""'Complete 'local' configuration is fine"""
8080
config = {
81-
"indexer_storage": {
81+
"indexer.storage": {
8282
"cls": "postgresql",
8383
"db": "db",
8484
}
8585
}
8686
config_path = prepare_config_file(tmpdir, config)
8787
with pytest.warns(DeprecationWarning):
8888
cfg = load_and_check_config(config_path)
89-
assert "indexer.storage" in cfg
89+
assert "indexer_storage" in cfg

swh/indexer/tests/test_cli.py

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55

66
import datetime
77
from functools import reduce
8-
import os
98
import re
109
from typing import Any, Dict, List
1110

1211
import attr
1312
from click.testing import CliRunner
1413
from confluent_kafka import Consumer
1514
import pytest
16-
import yaml
1715

1816
from swh.indexer import fossology_license
1917
from swh.indexer.cli import indexer_cli_group
@@ -560,50 +558,3 @@ def test_cli_journal_client_index__fossology_license(
560558
assert len(results) == len(expected_results)
561559
for result in results:
562560
assert result in expected_results
563-
564-
565-
def test_cli_config_deprecated(cli_runner, swh_indexer_config, monkeypatch, tmp_path):
566-
conffile = os.path.join(str(tmp_path), "indexer.yml")
567-
# alter the config to use the deprecated entry
568-
swh_indexer_config["indexer_storage"] = swh_indexer_config.pop("indexer.storage")
569-
with open(conffile, "w") as f:
570-
f.write(yaml.dump(swh_indexer_config))
571-
monkeypatch.setenv("SWH_CONFIG_FILENAME", conffile)
572-
573-
expected_output = "\n".join(
574-
[
575-
"cff",
576-
"codemeta",
577-
"composer",
578-
"gemspec",
579-
"gitea",
580-
"github",
581-
"json-sword-codemeta",
582-
"maven",
583-
"npm",
584-
"nuget",
585-
"pkg-info",
586-
"pubspec",
587-
"sword-codemeta",
588-
"",
589-
] # must be sorted for test to pass
590-
)
591-
592-
with pytest.warns(DeprecationWarning):
593-
result = cli_runner.invoke(
594-
indexer_cli_group,
595-
["-C", conffile, "mapping", "list"],
596-
catch_exceptions=False,
597-
)
598-
assert result.exit_code == 0, result.output
599-
assert result.output == expected_output
600-
601-
# same using SWH_CONFIG_FILENAME env var
602-
with pytest.warns(DeprecationWarning):
603-
result = cli_runner.invoke(
604-
indexer_cli_group,
605-
["mapping", "list"],
606-
catch_exceptions=False,
607-
)
608-
assert result.exit_code == 0, result.output
609-
assert result.output == expected_output

0 commit comments

Comments
 (0)