Skip to content

Commit

Permalink
Gate the poetry backend on whether we find a poetry section in it
Browse files Browse the repository at this point in the history
  • Loading branch information
blast-hardcheese committed Feb 14, 2024
1 parent d2b6ddb commit eff7c2b
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions internal/backends/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ type pyprojectPackageCfg struct {
// file.
type pyprojectTOML struct {
Tool struct {
Poetry struct {
Poetry *struct {
Name string `json:"name"`
// interface{} because they can be either
// strings or maps (why?? good lord).
Expand Down Expand Up @@ -266,12 +266,13 @@ func searchPypi(query string) []api.PkgInfo {
// (either a full path or just a name like "python3") to use when invoking Python.
func makePythonPoetryBackend(python string) api.LanguageBackend {
return api.LanguageBackend{
Name: "python3-poetry",
Alias: "python-python3-poetry",
Specfile: "pyproject.toml",
Lockfile: "poetry.lock",
IsAvailable: poetryIsAvailable,
FilenamePatterns: []string{"*.py"},
Name: "python3-poetry",
Alias: "python-python3-poetry",
Specfile: "pyproject.toml",
IsSpecfileCompatible: verifyPoetrySpecfile,
Lockfile: "poetry.lock",
IsAvailable: poetryIsAvailable,
FilenamePatterns: []string{"*.py"},
Quirks: api.QuirksAddRemoveAlsoLocks |
api.QuirksAddRemoveAlsoInstalls,
NormalizePackageArgs: normalizePackageArgs,
Expand Down Expand Up @@ -567,6 +568,15 @@ func readPyproject() (*pyprojectTOML, error) {
return &cfg, nil
}

func verifyPoetrySpecfile(path string) (bool, error) {
cfg, err := readPyproject()
if err != nil {
return false, err
}

return cfg.Tool.Poetry != nil, nil
}

func listPoetrySpecfile() (map[api.PkgName]api.PkgSpec, error) {
cfg, err := readPyproject()
if err != nil {
Expand Down

0 comments on commit eff7c2b

Please sign in to comment.