Skip to content

Commit

Permalink
Add test and fix a few things
Browse files Browse the repository at this point in the history
Still not sure on source, will consult later.
  • Loading branch information
stefanvanburen committed Sep 7, 2023
1 parent 5515d7a commit 1539631
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 7 deletions.
2 changes: 2 additions & 0 deletions private/bufpkg/bufplugin/bufplugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ func PluginToProtoPluginRegistryType(plugin Plugin) registryv1alpha1.PluginRegis
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_MAVEN
} else if plugin.Registry().Swift != nil {
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_SWIFT
} else if plugin.Registry().Python != nil {
registryType = registryv1alpha1.PluginRegistryType_PLUGIN_REGISTRY_TYPE_PYTHON
}
}
return registryType
Expand Down
4 changes: 2 additions & 2 deletions private/bufpkg/bufplugin/bufpluginconfig/bufpluginconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ type ExternalPythonRegistryConfig struct {
type ExternalPythonRegistryDependencyConfig struct {
// Source is the URL of the Python package.
Source string `json:"source,omitempty" yaml:"source,omitempty"`
// Package is the name of the Swift package.
// Package is the name of the Python package.
Package string `json:"package,omitempty" yaml:"package,omitempty"`
// Version is the version of the Swift package.
// Version is the version of the Python package.
Version string `json:"version,omitempty" yaml:"version,omitempty"`
}

Expand Down
31 changes: 31 additions & 0 deletions private/bufpkg/bufplugin/bufpluginconfig/bufpluginconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,37 @@ func TestParsePluginConfigSwiftYAML(t *testing.T) {
)
}

func TestParsePluginConfigPythonYAML(t *testing.T) {
t.Parallel()
pluginConfig, err := ParseConfig(filepath.Join("testdata", "success", "python", "buf.plugin.yaml"))
require.NoError(t, err)
pluginIdentity, err := bufpluginref.PluginIdentityForString("buf.build/protocolbuffers/python")
require.NoError(t, err)
require.Equal(
t,
&Config{
Name: pluginIdentity,
PluginVersion: "v24.0",
SourceURL: "https://github.com/protocolbuffers/protobuf",
Description: "Base types for Python. Generates message and enum types.",
OutputLanguages: []string{"python"},
Registry: &RegistryConfig{
Python: &PythonRegistryConfig{
Dependencies: []PythonRegistryDependencyConfig{
{
Package: "google-protobuf",
Version: "v24.0",
},
},
},
},
SPDXLicenseID: "BSD-3-Clause",
LicenseURL: "https://github.com/protocolbuffers/protobuf/blob/v24.0/LICENSE",
},
pluginConfig,
)
}

func TestParsePluginConfigOptionsYAML(t *testing.T) {
t.Parallel()
pluginConfig, err := ParseConfig(filepath.Join("testdata", "success", "options", "buf.plugin.yaml"))
Expand Down
11 changes: 6 additions & 5 deletions private/bufpkg/bufplugin/bufpluginconfig/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func newRegistryConfig(externalRegistryConfig ExternalRegistryConfig) (*Registry
isNPMEmpty,
isMavenEmpty,
isSwiftEmpty,
isPythonEmpty,
} {
if !isEmpty {
registryCount++
Expand Down Expand Up @@ -350,17 +351,17 @@ func newPythonRegistryConfig(externalPythonRegistryConfig *ExternalPythonRegistr
}

func pythonExternalDependencyToDependencyConfig(externalDep ExternalPythonRegistryDependencyConfig) (PythonRegistryDependencyConfig, error) {
if externalDep.Source == "" {
return PythonRegistryDependencyConfig{}, errors.New("python runtime dependency requires a non-empty source")
}
// TODO: not sure on source, is this required?
// if externalDep.Source == "" {
// return PythonRegistryDependencyConfig{}, errors.New("python runtime dependency requires a non-empty source")
// }
if externalDep.Package == "" {
return PythonRegistryDependencyConfig{}, errors.New("python runtime dependency requires a non-empty package name")
}
if externalDep.Version == "" {
return PythonRegistryDependencyConfig{}, errors.New("python runtime dependency requires a non-empty version name")
}
// Swift SemVers are typically not prefixed with a "v". The Golang semver library requires a "v" prefix.
if !semver.IsValid(fmt.Sprintf("v%s", externalDep.Version)) {
if !semver.IsValid(externalDep.Version) {
return PythonRegistryDependencyConfig{}, fmt.Errorf("python runtime dependency %s:%s does not have a valid semantic version", externalDep.Package, externalDep.Version)
}
return PythonRegistryDependencyConfig{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
version: v1
name: buf.build/protocolbuffers/python
plugin_version: v24.0
source_url: https://github.com/protocolbuffers/protobuf
description: Base types for Python. Generates message and enum types.
output_languages:
- python
registry:
python:
deps:
- package: 'google-protobuf'
version: 'v24.0'
spdx_license_id: BSD-3-Clause
license_url: https://github.com/protocolbuffers/protobuf/blob/v24.0/LICENSE

0 comments on commit 1539631

Please sign in to comment.