Skip to content

Commit

Permalink
Allow use of rpc client as an alternative to the metadata client (Jgu…
Browse files Browse the repository at this point in the history
…er#1918)

* use updated aur client

* add logger to rpc client

* update go.mod
  • Loading branch information
Jguer authored Feb 20, 2023
1 parent 2f5fd5c commit f1d086d
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 100 deletions.
9 changes: 7 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module github.com/Jguer/yay/v11

require (
github.com/Jguer/aur v1.1.3
github.com/Jguer/aur v1.2.0
github.com/Jguer/go-alpm/v2 v2.1.2
github.com/Jguer/votar v1.0.0
github.com/Morganamilo/go-pacmanconf v0.0.0-20210502114700-cff030e927a5
Expand All @@ -28,7 +28,12 @@ require (
github.com/deckarep/golang-set/v2 v2.1.0
github.com/itchyny/gojq v0.12.11 // indirect
github.com/itchyny/timefmt-go v0.1.5 // indirect
github.com/ohler55/ojg v1.17.4 // indirect
github.com/ohler55/ojg v1.17.5 // indirect
)

require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
)

go 1.19
21 changes: 9 additions & 12 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/Jguer/aur v1.1.3 h1:wuqz67ZqUnyqS56WjNSwKqrZCJFeDuG+ljWnmmPKg04=
github.com/Jguer/aur v1.1.3/go.mod h1:YWXsL0qywB3kY8gduwAJwklN38opQYRm6+pYMJgtCd0=
github.com/Jguer/aur v1.2.0 h1:hWg0JcGQ9WkPlnElr3tZ6dW+GfD/wZTr9kym5GFY3OE=
github.com/Jguer/aur v1.2.0/go.mod h1:x4iPZX1qZoQtPiYgFepVO/6kbz7zwFkep8gz5tzga64=
github.com/Jguer/go-alpm/v2 v2.1.2 h1:CGTIxzuEpT9Q3a7IBrx0E6acoYoaHX2Z93UOApPDhgU=
github.com/Jguer/go-alpm/v2 v2.1.2/go.mod h1:uLQcTMNM904dRiGU+/JDtDdd7Nd8mVbEVaHjhmziT7w=
github.com/Jguer/votar v1.0.0 h1:drPYpV5Py5BeAQS8xezmT6uCEfLzotNjLf5yfmlHKTg=
Expand All @@ -21,6 +21,11 @@ github.com/deckarep/golang-set/v2 v2.1.0 h1:g47V4Or+DUdzbs8FxCCmgb6VYd+ptPAngjM6
github.com/deckarep/golang-set/v2 v2.1.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542 h1:2VTzZjLZBgl62/EtslCrtky5vbi9dd7HrQPQIx6wqiw=
github.com/h2non/parth v0.0.0-20190131123155-b4df798d6542/go.mod h1:Ow0tF8D4Kplbc8s8sSb3V2oUCygFHVp8gC3Dn6U4MNI=
github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4=
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM=
github.com/itchyny/gojq v0.12.11 h1:YhLueoHhHiN4mkfM+3AyJV6EPcCxKZsOnYf+aVSwaQw=
github.com/itchyny/gojq v0.12.11/go.mod h1:o3FT8Gkbg/geT4pLI0tF3hvip5F3Y/uskjRz9OYa38g=
github.com/itchyny/timefmt-go v0.1.5 h1:G0INE2la8S6ru/ZI5JecgyzbbJNs5lG1RcBqa7Jm6GE=
Expand All @@ -29,10 +34,8 @@ github.com/leonelquinteros/gotext v1.5.1 h1:vmddRn3gHp67YFjZLZE2AZsgYMT4IBTJhua4
github.com/leonelquinteros/gotext v1.5.1/go.mod h1:/A4Y7BvIsf5JHO60E43ZQDVkV3qO+7eP8HjeqD6ChIA=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32 h1:W6apQkHrMkS0Muv8G/TipAy/FJl/rCYT0+EuS8+Z0z4=
github.com/nbio/st v0.0.0-20140626010706-e9e8d9816f32/go.mod h1:9wM+0iRr9ahx58uYLpLIr5fm8diHn0JbqRycJi6w0Ms=
github.com/ohler55/ojg v1.15.0 h1:Z95FvBiMsMOOGP9Nzv5OVV4ND2KnEMxk0GOS8Kvcahg=
github.com/ohler55/ojg v1.15.0/go.mod h1:7Ghirupn8NC8hSSDpI0gcjorPxj+vSVIONDWfliHR1k=
github.com/ohler55/ojg v1.17.4 h1:6Ss87DyAZHU0ODZu6Cmuahj5UiVaRD1n8C4KNm0qMYg=
github.com/ohler55/ojg v1.17.4/go.mod h1:7Ghirupn8NC8hSSDpI0gcjorPxj+vSVIONDWfliHR1k=
github.com/ohler55/ojg v1.17.5 h1:SY6/cdhVzsLinNFIBRNSWhJgihvEWco5Y0TJe46XJ1Y=
github.com/ohler55/ojg v1.17.5/go.mod h1:7Ghirupn8NC8hSSDpI0gcjorPxj+vSVIONDWfliHR1k=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down Expand Up @@ -62,21 +65,15 @@ golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20211019181941-9d821ace8654/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.3.0 h1:w8ZOecv6NaNa/zC8944JTU3vz4u6Lagfk4RPQxv92NQ=
golang.org/x/sys v0.3.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.3.0 h1:qoo4akIqOcDME5bhc/NgxUdovd6BSS2uMsVjB56q1xI=
golang.org/x/term v0.3.0/go.mod h1:q750SLmJuPmVoN1blW3UFBPREJfb1KmY3vwxfr+nFDA=
golang.org/x/term v0.5.0 h1:n2a8QNdAb0sZNpU9R1ALUXBbY+w51fCQDN+7EdxNBsY=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.5.0 h1:OLmvp0KP+FVG99Ct/qFiL/Fhk4zp4QQnZ7b2U+5piUM=
golang.org/x/text v0.5.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.7.0 h1:4BRB4x83lYWy72KwLD/qYDuTu7q9PjSagHvijDw7cLo=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
Expand Down
5 changes: 2 additions & 3 deletions local_install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"testing"

aur "github.com/Jguer/aur"
"github.com/Jguer/aur/metadata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

Expand Down Expand Up @@ -141,7 +140,7 @@ func TestIntegrationLocalInstall(t *testing.T) {
CmdBuilder: cmdBuilder,
VCSStore: &vcs.Mock{},
AURCache: &mockaur.MockAUR{
GetFn: func(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error) {
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
return []aur.Pkg{}, nil
},
},
Expand Down Expand Up @@ -259,7 +258,7 @@ func TestIntegrationLocalInstallMissingDep(t *testing.T) {
CmdBuilder: cmdBuilder,
VCSStore: &vcs.Mock{},
AURCache: &mockaur.MockAUR{
GetFn: func(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error) {
GetFn: func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
return []aur.Pkg{}, nil
},
},
Expand Down
7 changes: 4 additions & 3 deletions pkg/dep/depPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"sync"

"github.com/Jguer/aur"
"github.com/Jguer/aur/rpc"
alpm "github.com/Jguer/go-alpm/v2"
"github.com/leonelquinteros/gotext"

Expand All @@ -29,10 +30,10 @@ type Pool struct {
Groups []string
AlpmExecutor db.Executor
Warnings *query.AURWarnings
aurClient aur.ClientInterface
aurClient rpc.ClientInterface
}

func newPool(dbExecutor db.Executor, aurClient aur.ClientInterface) *Pool {
func newPool(dbExecutor db.Executor, aurClient rpc.ClientInterface) *Pool {
dp := &Pool{
Targets: []Target{},
Explicit: map[string]struct{}{},
Expand Down Expand Up @@ -348,7 +349,7 @@ func (dp *Pool) ResolveRepoDependency(pkg db.IPackage, noDeps bool) {
func GetPool(ctx context.Context, pkgs []string,
warnings *query.AURWarnings,
dbExecutor db.Executor,
aurClient aur.ClientInterface,
aurClient rpc.ClientInterface,
mode parser.TargetMode,
ignoreProviders, noConfirm, provides bool,
rebuild string, splitN int, noDeps bool, noCheckDeps bool, assumeInstalled []string,
Expand Down
13 changes: 4 additions & 9 deletions pkg/dep/dep_graph.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/Jguer/yay/v11/pkg/topo"

aurc "github.com/Jguer/aur"
"github.com/Jguer/aur/metadata"
alpm "github.com/Jguer/go-alpm/v2"
gosrc "github.com/Morganamilo/go-srcinfo"
"github.com/leonelquinteros/gotext"
Expand Down Expand Up @@ -94,13 +93,9 @@ var colorMap = map[Reason]string{
CheckDep: "forestgreen",
}

type AURCache interface {
Get(ctx context.Context, query *metadata.AURQuery) ([]aurc.Pkg, error)
}

type Grapher struct {
dbExecutor db.Executor
aurCache AURCache
aurCache aurc.QueryClient
fullGraph bool // If true, the graph will include all dependencies including already installed ones or repo
noConfirm bool
noDeps bool // If true, the graph will not include dependencies
Expand All @@ -110,7 +105,7 @@ type Grapher struct {
providerCache map[string]*aur.Pkg
}

func NewGrapher(dbExecutor db.Executor, aurCache AURCache,
func NewGrapher(dbExecutor db.Executor, aurCache aurc.QueryClient,
fullGraph, noConfirm bool, output io.Writer, noDeps bool, noCheckDeps bool,
) *Grapher {
return &Grapher{
Expand Down Expand Up @@ -342,7 +337,7 @@ func (g *Grapher) GraphFromAURCache(ctx context.Context,
}

for _, target := range targets {
aurPkgs, _ := g.aurCache.Get(ctx, &metadata.AURQuery{By: aurc.Name, Needles: []string{target}})
aurPkgs, _ := g.aurCache.Get(ctx, &aurc.Query{By: aurc.Name, Needles: []string{target}})
if len(aurPkgs) == 0 {
text.Errorln("No AUR package found for", target)

Expand Down Expand Up @@ -447,7 +442,7 @@ func (g *Grapher) addNodes(
} else {
var errMeta error
aurPkgs, errMeta = g.aurCache.Get(ctx,
&metadata.AURQuery{
&aurc.Query{
Needles: []string{depName},
By: aurc.None,
Contains: false,
Expand Down
12 changes: 6 additions & 6 deletions pkg/dep/dep_graph_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
"os"
"testing"

aurc "github.com/Jguer/aur"
"github.com/stretchr/testify/require"

"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/db/mock"
mockaur "github.com/Jguer/yay/v11/pkg/dep/mock"
aur "github.com/Jguer/yay/v11/pkg/query"

"github.com/Jguer/aur/metadata"
"github.com/stretchr/testify/require"
)

func ptrString(s string) *string {
Expand All @@ -31,7 +31,7 @@ func getFromFile(t *testing.T, filePath string) mockaur.GetFunc {
err = json.Unmarshal(fBytes, &pkgs)
require.NoError(t, err)

return func(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error) {
return func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
return pkgs, nil
}
}
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) {
},
}

mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error) {
mockAUR := &mockaur.MockAUR{GetFn: func(ctx context.Context, query *aurc.Query) ([]aur.Pkg, error) {
if query.Needles[0] == "jellyfin" {
jfinFn := getFromFile(t, "testdata/jellyfin.json")
return jfinFn(ctx, query)
Expand All @@ -93,7 +93,7 @@ func TestGrapher_GraphFromTargets_jellyfin(t *testing.T) {

type fields struct {
dbExecutor db.Executor
aurCache AURCache
aurCache aurc.QueryClient
noDeps bool
noCheckDeps bool
}
Expand Down
5 changes: 2 additions & 3 deletions pkg/dep/mock/aur.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@ import (
"context"

"github.com/Jguer/aur"
"github.com/Jguer/aur/metadata"
)

type GetFunc func(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error)
type GetFunc func(ctx context.Context, query *aur.Query) ([]aur.Pkg, error)

type MockAUR struct {
GetFn GetFunc
}

func (m *MockAUR) Get(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error) {
func (m *MockAUR) Get(ctx context.Context, query *aur.Query) ([]aur.Pkg, error) {
if m.GetFn != nil {
return m.GetFn(ctx, query)
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/query/aur_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"sync"

"github.com/Jguer/aur"
"github.com/Jguer/aur/rpc"
"github.com/leonelquinteros/gotext"

"github.com/Jguer/yay/v11/pkg/intrange"
Expand All @@ -19,7 +20,7 @@ type Pkg = aur.Pkg
// of packages exceeds the number set in config.RequestSplitN.
// If the number does exceed config.RequestSplitN multiple aur requests will be
// performed concurrently.
func AURInfo(ctx context.Context, aurClient aur.ClientInterface, names []string, warnings *AURWarnings, splitN int) ([]Pkg, error) {
func AURInfo(ctx context.Context, aurClient rpc.ClientInterface, names []string, warnings *AURWarnings, splitN int) ([]Pkg, error) {
info := make([]Pkg, 0, len(names))
seen := make(map[string]int)

Expand Down Expand Up @@ -84,7 +85,7 @@ func AURInfo(ctx context.Context, aurClient aur.ClientInterface, names []string,
return info, nil
}

func AURInfoPrint(ctx context.Context, aurClient aur.ClientInterface, names []string, splitN int) ([]Pkg, error) {
func AURInfoPrint(ctx context.Context, aurClient rpc.ClientInterface, names []string, splitN int) ([]Pkg, error) {
text.OperationInfoln(gotext.Get("Querying AUR..."))

warnings := &AURWarnings{}
Expand Down
5 changes: 3 additions & 2 deletions pkg/query/mixed_sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"strings"

"github.com/Jguer/aur"
"github.com/Jguer/aur/rpc"
"github.com/Jguer/go-alpm/v2"
"github.com/adrg/strutil"
"github.com/adrg/strutil/metrics"
Expand Down Expand Up @@ -39,11 +40,11 @@ type MixedSourceQueryBuilder struct {
bottomUp bool
singleLineResults bool

aurClient aur.ClientInterface
aurClient rpc.ClientInterface
}

func NewMixedSourceQueryBuilder(
aurClient aur.ClientInterface,
aurClient rpc.ClientInterface,
sortBy string,
targetMode parser.TargetMode,
searchBy string,
Expand Down
5 changes: 3 additions & 2 deletions pkg/query/mixed_sources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import (
"strings"
"testing"

"github.com/Jguer/aur/rpc"

"github.com/Jguer/yay/v11/pkg/settings/parser"

"github.com/Jguer/aur"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand All @@ -30,7 +31,7 @@ func TestMixedSourceQueryBuilder(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
client, err := aur.NewClient(aur.WithHTTPClient(&mockDoer{}))
client, err := rpc.NewClient(rpc.WithHTTPClient(&mockDoer{}))
queryBuilder := NewMixedSourceQueryBuilder(client, "votes", parser.ModeAny, "", tc.bottomUp, false)
search := []string{"linux"}
mockStore := &mockDB{}
Expand Down
18 changes: 7 additions & 11 deletions pkg/query/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/Jguer/yay/v11/pkg/stringset"
"github.com/Jguer/yay/v11/pkg/text"

"github.com/Jguer/aur/metadata"
"github.com/Jguer/aur/rpc"
)

type SearchVerbosity int
Expand All @@ -28,10 +28,6 @@ const (
Minimal
)

type AURCache interface {
Get(ctx context.Context, query *metadata.AURQuery) ([]aur.Pkg, error)
}

type SourceQueryBuilder struct {
repoQuery
aurQuery
Expand All @@ -43,13 +39,13 @@ type SourceQueryBuilder struct {
bottomUp bool
singleLineResults bool

aurClient aur.ClientInterface
aurCache AURCache
aurClient rpc.ClientInterface
aurCache aur.QueryClient
}

func NewSourceQueryBuilder(
aurClient aur.ClientInterface,
aurCache AURCache,
aurClient rpc.ClientInterface,
aurCache aur.QueryClient,
sortBy string,
targetMode parser.TargetMode,
searchBy string,
Expand Down Expand Up @@ -197,7 +193,7 @@ func filterAURResults(pkgS []string, results []aur.Pkg) []aur.Pkg {

// queryAUR searches AUR and narrows based on subarguments.
func queryAUR(ctx context.Context,
aurClient aur.ClientInterface, aurMetadata AURCache,
aurClient rpc.ClientInterface, aurMetadata aur.QueryClient,
pkgS []string, searchBy string, newEngine bool,
) ([]aur.Pkg, error) {
var (
Expand All @@ -209,7 +205,7 @@ func queryAUR(ctx context.Context,
var r []aur.Pkg

if aurMetadata != nil && newEngine {
q, errM := aurMetadata.Get(ctx, &metadata.AURQuery{
q, errM := aurMetadata.Get(ctx, &aur.Query{
Needles: []string{word},
By: by,
Contains: true,
Expand Down
5 changes: 3 additions & 2 deletions pkg/query/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (
"strings"
"testing"

"github.com/Jguer/aur/rpc"

"github.com/Jguer/yay/v11/pkg/db"
"github.com/Jguer/yay/v11/pkg/db/mock"
"github.com/Jguer/yay/v11/pkg/settings/parser"

"github.com/Jguer/aur"
"github.com/Jguer/go-alpm/v2"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -105,7 +106,7 @@ func TestSourceQueryBuilder(t *testing.T) {

for _, tc := range testCases {
t.Run(tc.desc, func(t *testing.T) {
client, err := aur.NewClient(aur.WithHTTPClient(&mockDoer{}))
client, err := rpc.NewClient(rpc.WithHTTPClient(&mockDoer{}))
require.NoError(t, err)

queryBuilder := NewSourceQueryBuilder(client, nil, "votes", parser.ModeAny, "", tc.bottomUp, false, false)
Expand Down
Loading

0 comments on commit f1d086d

Please sign in to comment.