-
Couldn't load subscription status.
- Fork 616
feat(python): support toml file in versioning step #5492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
| return "", fmt.Errorf("no version information found in file '%v'", p.Pip.path) | ||
| } | ||
| return values[1], nil | ||
| } |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
|
/it-go |
|
/it-go |
|



Description
Handle version of
pyproject.tomlfile.Requires #5463
Checklist