<commit_before>package internal

import (
	"bytes"
	"fmt"
	"go/ast"
	"go/build"
	"go/importer"
	"path/filepath"
	"runtime"
	// "go/internal/gcimporter"

	"go/types"
	"os"
	"os/exec"
	"strings"
)

func GetTypeInfo(pkgCtx *PackageContext, pkgDir, importPath, tempGoSrcDir string) (*types.Info, error) {
	buildPackage, err := build.Import(importPath, tempGoSrcDir, build.AllowBinary)
	if err != nil {
		return nil, err
	}

	deps, err := FindDeps(buildPackage)
	if err != nil {
		return nil, err
	}

	for i, dep := range deps {
		// NOTE: rewrite $dep to $importpath/vendor/$dep if $dep is found in vendor dir
		if pkgCtx.HasVendor {
			if _, err := os.Stat(filepath.Join(pkgCtx.Vendor, dep)); err == nil {
				pkgToVendor, err := filepath.Rel(pkgDir, pkgCtx.Vendor)
				if err != nil {
					return nil, err
				}
				dep = filepath.Join(pkgToVendor, dep)
				if !strings.HasPrefix(dep, ".") {
					dep = "./" + dep
				}
			}
		}

		deps[i] = dep
	}

	if IsBuildableFileSet(pkgCtx.NormalizedFset) {
		deps = append(deps, ".")
	}

	if len(deps) > 0 {
		install := exec.Command("go", "install")
		install.Dir = pkgDir
		install.Stdout = os.Stdout
		b := []byte{}
		buf := bytes.NewBuffer(b)
		install.Stderr = buf
		if Verbose {
			install.Args = append(install.Args, "-v")
		}
		install.Args = append(install.Args, deps...)<commit_msg>chore(translator/internal): simplify vendor deps rewriting<commit_after>package internal

import (
	"bytes"
	"fmt"
	"go/ast"
	"go/build"
	"go/importer"
	"path/filepath"
	"runtime"
	// "go/internal/gcimporter"

	"go/types"
	"os"
	"os/exec"
	"strings"
)

func GetTypeInfo(pkgCtx *PackageContext, pkgDir, importPath, tempGoSrcDir string) (*types.Info, error) {
	buildPackage, err := build.Import(importPath, tempGoSrcDir, build.AllowBinary)
	if err != nil {
		return nil, err
	}

	deps, err := FindDeps(buildPackage)
	if err != nil {
		return nil, err
	}

	// NOTE: rewrite $importpath to ./vendor/$importpath if $importpath is found in vendor dir
	if pkgCtx.HasVendor {
		pkgToVendor, err := filepath.Rel(pkgDir, pkgCtx.Vendor)
		if err != nil {
			return nil, err
		}
		if !strings.HasPrefix(pkgToVendor, ".") {
			pkgToVendor = "./" + pkgToVendor
		}
		for i, dep := range deps {
			if _, err := os.Stat(filepath.Join(pkgCtx.Vendor, dep)); err == nil {
				dep = pkgToVendor + "/" + dep
			}
			deps[i] = dep
		}
	}

	if IsBuildableFileSet(pkgCtx.NormalizedFset) {
		deps = append(deps, ".")
	}

	if len(deps) > 0 {
		install := exec.Command("go", "install")
		install.Dir = pkgDir
		install.Stdout = os.Stdout
		buf := bytes.NewBuffer([]byte{})
		install.Stderr = buf
		if Verbose {
			install.Args = append(install.Args, "-v")
		}
		install.Args = append(install.Args, deps...)
{'fraction_non_alphanumeric': 0.15535055350553506, 'fraction_numerical': 0.0007380073800738007, 'mean_word_length': 3.3585209003215435, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2734825', 'n_tokens_mistral': 1142, 'n_tokens_neox': 1046, 'n_words': 233}