Refactor to avoid duplication of config-file source of metadata - #141
Conversation
There was a problem hiding this comment.
Pull request overview
This pull request refactors metadata retrieval to provide a single source of truth for package metadata (name and version) by introducing new CLI commands and centralizing the extraction logic. The changes replace direct calls to python setup.py --name and python setup.py --version with robust CLI commands autorelease metadata name and autorelease metadata version, improving reliability and maintainability across CI/CD pipelines and scripts.
Changes:
- Added new
autorelease metadata nameandautorelease metadata versionCLI commands for retrieving package metadata - Refactored metadata extraction logic in
autorelease/version.pywith new generalizedget_setup_valuefunction and dedicatedget_setup_nameandget_setup_versionhelpers - Updated all CI/CD workflow templates, deployment scripts, and internal tools to use the new CLI commands instead of
python setup.py
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| autorelease/scripts/cli.py | Adds new metadata CLI group with name and version subcommands, plus helper function _conf_parts for path parsing |
| autorelease/version.py | Introduces generalized get_setup_value function and refactors get_setup_version to use it; adds new get_setup_name function |
| autorelease/tests/test_version.py | Adds test for the new get_setup_name and get_setup_version functions |
| autorelease/scripts/bump_dev_version.py | Refactors to use shared metadata extraction utilities from autorelease/version.py; adds _setup_path_parts helper function |
| script_stages/install-testpypi | Updates to use autorelease metadata name instead of python setup.py --name |
| script_stages/deploy-pypi | Updates to use autorelease metadata version instead of python setup.py --version |
| autorelease/gh_actions_stages/autorelease-prep.yml | Updates workflow template to use autorelease metadata version |
| autorelease/gh_actions_stages/autorelease-gh-rel.yml | Updates workflow template to use both autorelease metadata name and version |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| @metadata.command(name="version") | ||
| @click.option("-c", "--conf", type=str, default="setup.cfg", | ||
| help="setup.cfg file to use") | ||
| def metadata_version(conf): | ||
| directory, filename = _conf_parts(conf) | ||
| value = get_setup_version(None, directory=directory, filename=filename) | ||
| field = "version" | ||
|
|
||
| if value is None: | ||
| raise click.ClickException( | ||
| "Missing [metadata] " + field + " in " + conf | ||
| ) | ||
| click.echo(value) | ||
|
|
||
|
|
||
| @metadata.command(name="name") | ||
| @click.option("-c", "--conf", type=str, default="setup.cfg", | ||
| help="setup.cfg file to use") | ||
| def metadata_name(conf): | ||
| directory, filename = _conf_parts(conf) | ||
| value = get_setup_name(None, directory=directory, filename=filename) | ||
| field = "name" | ||
|
|
||
| if value is None: | ||
| raise click.ClickException( | ||
| "Missing [metadata] " + field + " in " + conf | ||
| ) | ||
| click.echo(value) |
There was a problem hiding this comment.
The two metadata commands (metadata_version and metadata_name) have significant code duplication. They differ only in the getter function called and the field name used. Consider refactoring to reduce duplication by creating a shared helper function or parameterizing the common logic. This would make the code more maintainable and reduce the chance of inconsistencies between the two commands.
There was a problem hiding this comment.
Deciding not to address this. The duplicated code is minimal.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Distinguish between missing and malformed; raise different errors
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 12 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| directory for setup.cfg, relative to cwd; default '.' | ||
| filename : str | ||
| filename for setup.cfg; default 'setup.cfg' |
There was a problem hiding this comment.
The get_setup_cfg docstring still says it loads setup.cfg "as a dict-of-dict", but the function actually returns a ConfigParser instance (or None). Updating the docstring (including the parameter docs here) to reflect the real return type would avoid confusion for callers.
This is intended to make it so we have a single source of truth for some metadata we usually get from the config file (package-defined version; package name) and that we also expose that as CLI commands to be used in scripts.
This pull request refactors how project metadata (specifically the name and version) is retrieved throughout the autorelease workflow. Instead of directly parsing
setup.cfgusingsetup.pyor custom code, new CLI commands are introduced to robustly fetch these fields, and supporting utility functions are added and tested. This improves reliability, consistency, and maintainability across scripts and CI pipelines.Core infrastructure improvements:
autorelease metadata nameandautorelease metadata versionCLI commands to reliably fetch the project name and version fromsetup.cfg, replacing previous ad hoc parsing and directpython setup.pycalls. (autorelease/scripts/cli.py, autorelease/scripts/cli.pyR81-R123)autorelease/version.pyto generalize fetching arbitrary metadata fields, and added dedicatedget_setup_nameandget_setup_versionhelpers. (autorelease/version.py, autorelease/version.pyL117-R139)autorelease/tests/test_version.py, autorelease/tests/test_version.pyR30-R39)CI/CD and script updates:
autorelease metadatacommands instead ofpython setup.pyfor retrieving project name and version. (autorelease/gh_actions_stages/autorelease-gh-rel.yml, [1];autorelease/gh_actions_stages/autorelease-prep.yml, [2];script_stages/deploy-pypi, [3];script_stages/install-testpypi, [4]Internal code cleanup:
bump_dev_version.pyto use the new shared metadata extraction logic, removing duplicated config parsing code. (autorelease/scripts/bump_dev_version.py, [1] [2]