Skip to content

Refactor to avoid duplication of config-file source of metadata - #141

Merged
dwhswenson merged 10 commits into
mainfrom
refactor-config-source
Mar 29, 2026
Merged

Refactor to avoid duplication of config-file source of metadata#141
dwhswenson merged 10 commits into
mainfrom
refactor-config-source

Conversation

@dwhswenson

Copy link
Copy Markdown
Owner

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.cfg using setup.py or 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:

  • Added autorelease metadata name and autorelease metadata version CLI commands to reliably fetch the project name and version from setup.cfg, replacing previous ad hoc parsing and direct python setup.py calls. (autorelease/scripts/cli.py, autorelease/scripts/cli.pyR81-R123)
  • Refactored utility functions in autorelease/version.py to generalize fetching arbitrary metadata fields, and added dedicated get_setup_name and get_setup_version helpers. (autorelease/version.py, autorelease/version.pyL117-R139)
  • Updated tests to cover the new metadata extraction functions for both name and version. (autorelease/tests/test_version.py, autorelease/tests/test_version.pyR30-R39)

CI/CD and script updates:

  • Updated all CI/CD scripts and jobs to use the new autorelease metadata commands instead of python setup.py for 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:

  • Refactored bump_dev_version.py to use the new shared metadata extraction logic, removing duplicated config parsing code. (autorelease/scripts/bump_dev_version.py, [1] [2]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 name and autorelease metadata version CLI commands for retrieving package metadata
  • Refactored metadata extraction logic in autorelease/version.py with new generalized get_setup_value function and dedicated get_setup_name and get_setup_version helpers
  • 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.

Comment thread autorelease/tests/test_version.py Outdated
Comment thread autorelease/version.py Outdated
Comment thread autorelease/scripts/cli.py
Comment thread autorelease/scripts/cli.py
Comment thread autorelease/scripts/bump_dev_version.py Outdated
Comment on lines +95 to +122
@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)

Copilot AI Feb 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Deciding not to address this. The duplicated code is minimal.

Comment thread autorelease/scripts/bump_dev_version.py Outdated
Comment thread autorelease/scripts/cli.py

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread autorelease/scripts/bump_dev_version.py Outdated
Comment thread autorelease/scripts/cli.py
Comment thread autorelease/scripts/cli.py
Comment thread autorelease/version.py Outdated
Distinguish between missing and malformed; raise different errors

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread autorelease/scripts/cli.py
Comment thread autorelease/scripts/cli.py
Comment thread autorelease/version.py Outdated
Comment on lines 102 to 104
directory for setup.cfg, relative to cwd; default '.'
filename : str
filename for setup.cfg; default 'setup.cfg'

Copilot AI Mar 23, 2026

Copy link

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Resolved in 995399c

@dwhswenson
dwhswenson merged commit 213b26e into main Mar 29, 2026
6 checks passed
@dwhswenson
dwhswenson deleted the refactor-config-source branch March 29, 2026 18:45
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.

2 participants