Skip to content

docs: fix tool versions hook example#114

Merged
hofbi merged 2 commits into
hofbi:masterfrom
cbachhuber:docs/fix-sync-tool-versions
Apr 22, 2026
Merged

docs: fix tool versions hook example#114
hofbi merged 2 commits into
hofbi:masterfrom
cbachhuber:docs/fix-sync-tool-versions

Conversation

@cbachhuber
Copy link
Copy Markdown
Collaborator

@cbachhuber cbachhuber commented Apr 22, 2026

Yaml recognizes value 3.12 as float, not str:

from ruamel.yaml import YAML
yaml = YAML(typ="safe")
config=r"""name: tool-versions
sync_versions:
  - name: python
    version: 3.12
    entries:
      - path: .python-version
        pattern: ([0-9]+\.[0-9]+)
"""
data = yaml.load(config)
type(data['sync_versions'][0]['version'])  # prints '<class 'float'>'

This causes dev_tools/sync_tool_versions.py to raise

  Error: invalid config in /home/chris/improvements/.versions.yaml: Each sync_versions entry must have a non-empty 'version' in /home/chris/improvements/.versions.yaml

with the config from the example. This doesn't hint to the root problem. Thus, improve the error message and fix the example in the docs. Alternatively, we could convert float to str to simplify the config file.

Btw:

>>> from ruamel.yaml import YAML
>>> yaml = YAML(typ="safe")
>>> type(yaml.load("version: 1.91.0")['version'])
<class 'str'>

Comment thread dev_tools/sync_tool_versions.py Outdated
Comment thread .pre-commit-config.yaml
@cbachhuber cbachhuber marked this pull request as ready for review April 22, 2026 07:54
@hofbi hofbi merged commit ff512e8 into hofbi:master Apr 22, 2026
12 checks passed
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