Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix use of the changelog CLI without configuration file #279

Merged
merged 1 commit into from
Jan 22, 2024
Merged
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
15 changes: 11 additions & 4 deletions qgispluginci/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ def cli():
)
changelog_parser.add_argument(
"release_version",
help="The version to be released. If nothing is speficied, \
the latest version specified into the changelog is used.",
help=(
"The version to be released. If nothing is specified, the latest version specified into the changelog is "
"used."
),
default="latest",
)

Expand Down Expand Up @@ -182,11 +184,12 @@ def cli():

exit_val = 0

# Initialize Parameters
parameters = Parameters.make_from(args=args)
# CHANGELOG
if args.command == "changelog":
try:
# Initialize Parameters
# Configuration file is optional at this stage
parameters = Parameters.make_from(args=args, optional_configuration=True)
c = ChangelogParser(
changelog_path=parameters.changelog_path,
)
Expand All @@ -198,6 +201,10 @@ def cli():

return exit_val

# Initialize Parameters
# Configuration file is now required
parameters = Parameters.make_from(args=args)

# PACKAGE
if args.command == "package":
release(
Expand Down
19 changes: 13 additions & 6 deletions qgispluginci/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,11 @@ class Parameters:

@classmethod
def make_from(
cls, *, args: Optional[Any] = None, path_to_config_file: Optional[Path] = None
cls,
*,
args: Optional[Any] = None,
path_to_config_file: Optional[Path] = None,
optional_configuration: bool = False,
) -> "Parameters":
"""
Instantiate from a config file or by exploring the filesystem
Expand Down Expand Up @@ -157,6 +161,9 @@ def explore_config() -> Dict[str, Any]:
pass
raise configuration_not_found

if optional_configuration and not path_to_config_file:
return cls({})

if path_to_config_file:
file_name = path_to_config_file.name

Expand All @@ -172,6 +179,11 @@ def explore_config() -> Dict[str, Any]:

def __init__(self, definition: Dict[str, Any]):
self.plugin_path = definition.get("plugin_path")
self.changelog_path = definition.get("changelog_path", "CHANGELOG.md")

if not self.plugin_path:
# This tool can be used outside of a QGIS plugin to read a changelog file
return

get_metadata = self.collect_metadata()
self.plugin_name = get_metadata("name")
Expand Down Expand Up @@ -230,13 +242,8 @@ def __init__(self, definition: Dict[str, Any]):
self.changelog_number_of_entries = definition.get(
"changelog_number_of_entries", 3
)
self.changelog_path = definition.get("changelog_path", "CHANGELOG.md")

# read from metadata
if not self.plugin_path:
# This tool can be used outside of a QGIS plugin to read a changelog file
return

self.author = get_metadata("author", "")
self.description = get_metadata("description")
self.qgis_minimum_version = get_metadata("qgisMinimumVersion")
Expand Down
16 changes: 16 additions & 0 deletions test/test_parameters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#! /usr/bin/env python

# standard
import unittest

# Project
from qgispluginci.parameters import Parameters


class TestParameters(unittest.TestCase):
def test_changelog_parameters(self):
"""Test parameters for changelog command."""
# For the changelog command, the configuration file is optional.
parameters = Parameters.make_from(args={}, optional_configuration=True)
self.assertEqual("CHANGELOG.md", parameters.changelog_path)
self.assertIsNone(parameters.plugin_path)