diff --git a/invenio_cli/cli/containers.py b/invenio_cli/cli/containers.py index 0212bb7..1517dcd 100644 --- a/invenio_cli/cli/containers.py +++ b/invenio_cli/cli/containers.py @@ -100,7 +100,7 @@ def setup(cli_config, force, no_demo_data, stop_services, services): def status(ctx, verbose): """Checks if the services are up and running. - NOTE: currently only search, DB (postgresql/mysql) and redis are supported. + NOTE: currently only search (opensearch2), DB (postgresql) and redis are supported. """ ctx.invoke(services_status_cmd, verbose=verbose) diff --git a/invenio_cli/cli/services.py b/invenio_cli/cli/services.py index b85176e..69fce1f 100644 --- a/invenio_cli/cli/services.py +++ b/invenio_cli/cli/services.py @@ -86,7 +86,7 @@ def setup(cli_config, force, no_demo_data, stop_services, services): def status(cli_config, verbose): """Checks if the services are up and running. - NOTE: currently only search (OS/ES), DB (postgresql/mysql) and redis are supported. + NOTE: currently only search (opensearch2), DB (postgresql) and redis are supported. """ commands = ServicesCommands(cli_config) services = ["redis", cli_config.get_db_type(), "search"] diff --git a/invenio_cli/helpers/cli_config.py b/invenio_cli/helpers/cli_config.py index 3592cbe..ca72236 100644 --- a/invenio_cli/helpers/cli_config.py +++ b/invenio_cli/helpers/cli_config.py @@ -2,6 +2,7 @@ # SPDX-FileCopyrightText: 2019-2020 Northwestern University. # SPDX-FileCopyrightText: 2021 Esteban J. G. Gabancho. # SPDX-FileCopyrightText: 2024 Graz University of Technology. +# SPDX-FileCopyrightText: 2025-2026 KTH Royal Institute of Technology. # SPDX-License-Identifier: MIT """Invenio-cli configuration file.""" @@ -95,7 +96,7 @@ def javascript_package_manager(self) -> JavascriptPackageManager: elif manager_name == PNPM.name: return PNPM() - return NPM() + return PNPM() def get_project_dir(self): """Returns path to project directory.""" @@ -166,23 +167,12 @@ def get_web_host(self): return self.private_config[CLIConfig.CLI_SECTION].get("web_host", "127.0.0.1") def get_db_type(self): - """Returns the database type (mysql, postgresql).""" - return self.config[CLIConfig.COOKIECUTTER_SECTION]["database"] + """Returns the database type.""" + return self.config[CLIConfig.COOKIECUTTER_SECTION].get("database", "postgresql") def get_search_type(self): - """Returns the search type (opensearch1, elasticsearch7).""" - sections = self.config[CLIConfig.COOKIECUTTER_SECTION] - if "elasticsearch" in sections: - # cookiecutter < v10 - version = sections["elasticsearch"] - return f"elasticsearch{version}" - elif "search" in sections: - # cookiecutter >= v10 - return sections["search"] - else: - raise InvenioCLIConfigError( - "`search` or `elasticsearch` field not set in .invenio file" - ) + """Returns the search type.""" + return self.config[CLIConfig.COOKIECUTTER_SECTION].get("search", "opensearch2") def get_file_storage(self): """Returns the file storage (local, s3, etc.).""" @@ -223,11 +213,16 @@ def write(cls, project_dir, flavour, replay): config_parser[cls.CLI_SECTION] = {} config_parser[cls.CLI_SECTION]["flavour"] = flavour config_parser[cls.CLI_SECTION]["logfile"] = "/logs/invenio-cli.log" + config_parser[cls.CLI_SECTION]["javascript_package_manager"] = PNPM.name # Cookiecutter user input section config_parser[cls.COOKIECUTTER_SECTION] = {} for key, value in replay[cls.COOKIECUTTER_SECTION].items(): config_parser[cls.COOKIECUTTER_SECTION][key] = str(value) + # Keep compatibility with older tooling that expects `database` and `search` to exist. + # Backend choice has been removed; PostgreSQL and OpenSearch2 are fixed. + config_parser[cls.COOKIECUTTER_SECTION]["database"] = "postgresql" + config_parser[cls.COOKIECUTTER_SECTION]["search"] = "opensearch2" # Generated files section config_parser[cls.FILES_SECTION] = get_created_files(project_dir) diff --git a/tests/helpers/test_cli_config.py b/tests/helpers/test_cli_config.py index 071b64e..3eabbfa 100644 --- a/tests/helpers/test_cli_config.py +++ b/tests/helpers/test_cli_config.py @@ -1,11 +1,13 @@ # SPDX-FileCopyrightText: 2019-2020 CERN. # SPDX-FileCopyrightText: 2019-2021 Northwestern University. +# SPDX-FileCopyrightText: 2025-2026 KTH Royal Institute of Technology. # SPDX-License-Identifier: MIT """Module config_file tests.""" import os import tempfile +from configparser import ConfigParser from pathlib import Path import pytest @@ -29,8 +31,6 @@ def test_cli_config_write(): "author_name": "CERN", "author_email": "info@my-site.com", "year": "2022", - "database": "postgresql", - "search": "opensearch1", "_template": "https://github.com/inveniosoftware/cookiecutter-invenio-rdm.git", # noqa } } @@ -62,8 +62,6 @@ def config_dir(): "author_name": "CERN", "author_email": "info@my-site.com", "year": "2022", - "database": "postgresql", - "search": "opensearch1", "_template": "https://github.com/inveniosoftware/cookiecutter-invenio-rdm.git", # noqa } } @@ -116,3 +114,32 @@ def test_cli_config_get_project_shortname(config_dir): cli_config = CLIConfig(config_dir) assert cli_config.get_project_shortname() == "my-site" + + +def test_package_manager_and_service_defaults(tmpdir): + """Test package manager, database, and search defaults in CLI config.""" + project_dir = tmpdir.mkdir("test-project") + flavour = "RDM" + replay = { + "cookiecutter": { + "project_name": "My Site", + "project_shortname": "my-site", + "project_site": "my-site.com", + "github_repo": "my-site/my-site", + "description": "Invenio RDM My Site Instance", + "author_name": "CERN", + "author_email": "info@my-site.com", + "year": "2022", + "_template": "https://github.com/inveniosoftware/cookiecutter-invenio-rdm.git", # noqa + } + } + CLIConfig.write(str(project_dir), flavour, replay) + + config = ConfigParser() + config_path = project_dir.join(CLIConfig.CONFIG_FILENAME) + config.read(str(config_path)) + + assert config.has_option(CLIConfig.CLI_SECTION, "javascript_package_manager") + assert config.get(CLIConfig.CLI_SECTION, "javascript_package_manager") == "pnpm" + assert config.get(CLIConfig.COOKIECUTTER_SECTION, "database") == "postgresql" + assert config.get(CLIConfig.COOKIECUTTER_SECTION, "search") == "opensearch2"