Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion invenio_cli/cli/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,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)

Expand Down
2 changes: 1 addition & 1 deletion invenio_cli/cli/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,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"]
Expand Down
35 changes: 16 additions & 19 deletions invenio_cli/helpers/cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# Copyright (C) 2019-2020 Northwestern University.
# Copyright (C) 2021 Esteban J. G. Gabancho.
# Copyright (C) 2024 Graz University of Technology.
# Copyright (C) 2025-2026 KTH Royal Institute of Technology.
#
# Invenio-Cli is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -99,7 +100,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."""
Expand Down Expand Up @@ -169,24 +170,15 @@ def get_web_host(self):
"""Returns web host."""
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"]

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"
)
@staticmethod
def get_db_type():
"""Returns the database type."""
return "postgresql"

@staticmethod
def get_search_type():
"""Returns the search type."""
return "opensearch2"

def get_file_storage(self):
"""Returns the file storage (local, s3, etc.)."""
Expand Down Expand Up @@ -227,11 +219,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`,`search`to exist.
# Database,Search backend choice has been removed and postgresql, opensearch2 is fixed.
config_parser[cls.COOKIECUTTER_SECTION]["database"] = cls.get_db_type()
config_parser[cls.COOKIECUTTER_SECTION]["search"] = cls.get_search_type()

# Generated files section
config_parser[cls.FILES_SECTION] = get_created_files(project_dir)
Expand Down
35 changes: 31 additions & 4 deletions tests/helpers/test_cli_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# Copyright (C) 2019-2020 CERN.
# Copyright (C) 2019-2021 Northwestern University.
# Copyright (C) 2025-2026 KTH Royal Institute of Technology.
#
# Invenio-Cli is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -10,6 +11,7 @@

import os
import tempfile
from configparser import ConfigParser
from pathlib import Path

import pytest
Expand All @@ -33,8 +35,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
}
}
Expand Down Expand Up @@ -66,8 +66,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
}
}
Expand Down Expand Up @@ -120,3 +118,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"