Skip to content

Commit

Permalink
Fix use of the changelog CLI without configuration file
Browse files Browse the repository at this point in the history
  • Loading branch information
Gustry committed Jan 19, 2024
1 parent d3b6048 commit 222f1a1
Show file tree
Hide file tree
Showing 2 changed files with 21 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
16 changes: 10 additions & 6 deletions qgispluginci/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ 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 +158,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 +176,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 +239,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

0 comments on commit 222f1a1

Please sign in to comment.