Skip to content

Conversation

@CCFenner
Copy link
Member

@CCFenner CCFenner commented Sep 25, 2025

Description

Handle version of pyproject.toml file.

Requires #5463

Checklist

  • Tests
  • Documentation
  • Inner source library needs updating

return "", fmt.Errorf("no version information found in file '%v'", p.Pip.path)
}
return values[1], nil
}
Copy link
Member

@maxcask maxcask Oct 1, 2025

Choose a reason for hiding this comment

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

To parse TOML it's better to use BurntSushi/toml, less fragile and provides robust parsing:

import (
    "github.com/BurntSushi/toml"
)

type pyproject struct {
    Project struct {
        Name    string `toml:"name"`
        Version string `toml:"version"`
    } `toml:"project"`
}

func (p *Toml) parsePyproject() (*pyproject, error) {
    var py pyproject
    if _, err := toml.Decode(p.Pip.buildDescriptorContent, &py); err != nil {
        return nil, err
    }
    return &py, nil
}

func (p *Toml) GetName() (string, error) {
    py, err := p.parsePyproject()
    if err != nil {
        return "", err
    }
    if py.Project.Name == "" {
        return "", fmt.Errorf("no name information found in file '%v'", p.Pip.path)
    }
    return py.Project.Name, nil
}

func (p *Toml) GetVersion() (string, error) {
    py, err := p.parsePyproject()
    if err != nil {
        return "", err
    }
    if py.Project.Version == "" {
        return "", fmt.Errorf("no version information found in file '%v'", p.Pip.path)
    }
    return py.Project.Version, nil
}

Copy link
Member

@maxcask maxcask left a comment

Choose a reason for hiding this comment

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

LGTM

@maxcask
Copy link
Member

maxcask commented Oct 2, 2025

/it-go

@petkodimitrov24
Copy link
Contributor

/it-go

@CCFenner CCFenner marked this pull request as ready for review October 29, 2025 09:28
@CCFenner CCFenner requested a review from a team as a code owner October 29, 2025 09:28
@sonarqubecloud
Copy link

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.

4 participants