<commit_before>/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package util

import (
	"encoding/json"
	"fmt"
	"go/build"
	"log"
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
)

// K8s returns $GOPATH/src/k8s.io/...
func K8s(projectName string, parts ...string) string {
	return getProjectDir("k8s.io", projectName, parts...)
}

// K8sSigs returns $GOPATH/src/sigs.k8s.io/...
func K8sSigs(projectName string, parts ...string) string {
	return getProjectDir("sigs.k8s.io", projectName, parts...)
}

// GetProjectDir returns $GOPATH/src/<project-namespace>/...
func getProjectDir(namespace, projectName string, parts ...string) string {
	gopathList := filepath.SplitList(build.Default.GOPATH)
	found := false
	var projectDir string
	for _, gopath := range gopathList {
		projectDir = filepath.Join(gopath, "src", namespace, projectName)
		if _, err := os.Stat(projectDir); !os.IsNotExist(err) {
			found = true
			break
		}
	}
	if !found {
		// Default to the first item in GOPATH list.
		projectDir = filepath.Join(gopathList[0], "src", "k8s.io", projectName)
		log.Printf(
			"Warning: Couldn't find directory src/%s/%s under any of GOPATH %s, defaulting to %s",
			namespace, projectName, build.Default.GOPATH, projectDir)
	}
	p := []string{projectDir}
	p = append(p, parts...)
	return filepath.Join(p...)
}

// AppendError does append(errs, err) if err != nil
func AppendError(errs []error, err error) []error {
	if err != nil {
		return append(errs, err)<commit_msg>Stop assuming GOPATH is non-empty<commit_after>/*
Copyright 2017 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package util

import (
	"encoding/json"
	"fmt"
	"go/build"
	"log"
	"net/url"
	"os"
	"os/exec"
	"path/filepath"
	"strings"
)

// K8s returns $GOPATH/src/k8s.io/...
func K8s(projectName string, parts ...string) string {
	return getProjectDir("k8s.io", projectName, parts...)
}

// K8sSigs returns $GOPATH/src/sigs.k8s.io/...
func K8sSigs(projectName string, parts ...string) string {
	return getProjectDir("sigs.k8s.io", projectName, parts...)
}

// GetProjectDir returns $GOPATH/src/<project-namespace>/...
func getProjectDir(namespace, projectName string, parts ...string) string {
	gopathList := filepath.SplitList(build.Default.GOPATH)
	var found bool
	var projectDir string
	for _, gopath := range gopathList {
		projectDir = filepath.Join(gopath, "src", namespace, projectName)
		if _, err := os.Stat(projectDir); !os.IsNotExist(err) {
			found = true
			break
		}
	}
	if !found && len(gopathList) > 0 {
		// Default to the first item in GOPATH list.
		projectDir = filepath.Join(gopathList[0], "src", "k8s.io", projectName)
		log.Printf(
			"Warning: Couldn't find directory src/%s/%s under any of GOPATH %s, defaulting to %s",
			namespace, projectName, build.Default.GOPATH, projectDir)
	}
	p := []string{projectDir}
	p = append(p, parts...)
	return filepath.Join(p...)
}

// AppendError does append(errs, err) if err != nil
func AppendError(errs []error, err error) []error {
	if err != nil {
		return append(errs, err)
{'fraction_non_alphanumeric': 0.12601927353595255, 'fraction_numerical': 0.00914257474672597, 'mean_word_length': 3.9975308641975307, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3060380', 'n_tokens_mistral': 1387, 'n_tokens_neox': 1331, 'n_words': 434}