Skip to content

Fix suboptimal file replacement#348

Open
dmarteau wants to merge 2 commits into
opengisch:masterfrom
dmarteau:fix-suboptimal-replace-in-file
Open

Fix suboptimal file replacement#348
dmarteau wants to merge 2 commits into
opengisch:masterfrom
dmarteau:fix-suboptimal-replace-in-file

Conversation

@dmarteau
Copy link
Copy Markdown
Contributor

@dmarteau dmarteau commented Oct 7, 2025

The 'replace-in-file' calls for modifying metadata is suboptimal: the file is read and written back for each changes in metadata properties.

The actual parsing deos not takes the sections into account: this is error prone if there is properties of the same name in different sections.

Metadata files can be handled with 'ConfigParser' in a simpler way without resorting to custom parsing

@dmarteau dmarteau force-pushed the fix-suboptimal-replace-in-file branch from 3d70154 to 1098843 Compare October 7, 2025 16:34
Copy link
Copy Markdown
Member

@3nids 3nids left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great move!
One question is the removal of the DEBUG variable change.

Comment thread qgispluginci/release.py
# replace any DEBUG=False in all Python files
if not is_prerelease:
for file in glob(f"{parameters.plugin_path}/**/*.py", recursive=True):
replace_in_file(file, r"^DEBUG\s*=\s*True", "DEBUG = False")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to remove this?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May be I'm wrong but I checked for DEBUG global variables in source files and found none: so the code above has no effects.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's checking in Python files of the plugin it self, so it depends of the plugin source code.

https://github.com/opengisch/qgis-plugin-ci?tab=readme-ov-file#debug

It's indeed missing from the HTML documentation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. What is the purpose of this variable ?

IMHO this is an anti-pattern to use litteral global variables as check for DEBUG state. I think this should discouraged. Moreover this is also error prone as you assuming that plugin may defines this variables for other purposes because the name is too generic.

I may put back this code for the sake of retro compatibility, but you really should considering not relying on it or
disabling it in some way or renaming in to something less ambiguous: i.e PLUGIN_CI_DEBUG.

@dmarteau dmarteau force-pushed the fix-suboptimal-replace-in-file branch from 8d8433f to fca730d Compare October 8, 2025 09:08
Copy link
Copy Markdown
Collaborator

@Gustry Gustry left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice move indeed, thanks

Comment thread qgispluginci/release.py
f"commitNumber={len(list(repo.iter_commits()))}",
)

metadata.set("general", "commitNumber", str(sum(1 for _ in repo.iter_commits())))
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commitNumber commitSha1 and dateTime are not necessarily in the general section because they are not "official" items from a metadata.txt according to QGIS documentation https://docs.qgis.org/3.40/en/docs/pyqgis_developer_cookbook/plugins/plugins.html#metadata-txt
It's up to the PyQGIS developer.

https://opengisch.github.io/qgis-plugin-ci/usage/cli_release.html#additional-metadata

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants