Skip to content

Commit

Permalink
Fix use of the changelog CLI without configuration file (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry authored Jan 22, 2024
1 parent d3b6048 commit 58bddb2
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 10 deletions.
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)

0 comments on commit 58bddb2

Please sign in to comment.