mirror of
https://github.com/ralsina/tartrazine.git
synced 2025-05-24 08:18:52 -03:00
generator: CLI tool fix to support win paths
On Win `make code-generate` produces unreasonable Bayesian classifier weights from Linguist samples silently, failing only the final classification tests. TestPlan: - go test ./internal/code-generator/... \ -run Test_GeneratorTestSuite -testify.m TestGenerationFiles Signed-off-by: Alexander Bezzubov <bzz@apache.org>
This commit is contained in:
parent
78d8f43a88
commit
b0f94ad693
@ -3,81 +3,84 @@ package main
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/go-enry/go-enry/v2/internal/code-generator/generator"
|
"github.com/go-enry/go-enry/v2/internal/code-generator/generator"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
var (
|
||||||
// languages info file
|
// directories
|
||||||
languagesYAML = ".linguist/lib/linguist/languages.yml"
|
samplesDir = filepath.Join(".linguist", "samples")
|
||||||
|
libDir = filepath.Join(".linguist", "lib", "linguist")
|
||||||
|
assetsDir = filepath.Join("internal", "code-generator", "assets")
|
||||||
|
|
||||||
// linguist's samples directory
|
// languages info file
|
||||||
samplesDir = ".linguist/samples"
|
languagesYAML = filepath.Join(libDir, "languages.yml")
|
||||||
|
|
||||||
// extension.go generation
|
// extension.go generation
|
||||||
extensionsFile = "data/extension.go"
|
extensionsFile = filepath.Join("data", "extension.go")
|
||||||
extensionsTmplPath = "internal/code-generator/assets/extension.go.tmpl"
|
extensionsTmplPath = filepath.Join(assetsDir, "extension.go.tmpl")
|
||||||
extensionsTmpl = "extension.go.tmpl"
|
extensionsTmpl = "extension.go.tmpl"
|
||||||
|
|
||||||
// content.go generation
|
// content.go generation
|
||||||
heuristicsYAML = ".linguist/lib/linguist/heuristics.yml"
|
heuristicsYAML = filepath.Join(libDir, "heuristics.yml")
|
||||||
contentFile = "data/content.go"
|
contentFile = filepath.Join("data", "content.go")
|
||||||
contentTmplPath = "internal/code-generator/assets/content.go.tmpl"
|
contentTmplPath = filepath.Join(assetsDir, "content.go.tmpl")
|
||||||
contentTmpl = "content.go.tmpl"
|
contentTmpl = "content.go.tmpl"
|
||||||
|
|
||||||
// vendor.go generation
|
// vendor.go generation
|
||||||
vendorYAML = ".linguist/lib/linguist/vendor.yml"
|
vendorYAML = filepath.Join(libDir, "vendor.yml")
|
||||||
vendorFile = "data/vendor.go"
|
vendorFile = filepath.Join("data", "vendor.go")
|
||||||
vendorTmplPath = "internal/code-generator/assets/vendor.go.tmpl"
|
vendorTmplPath = filepath.Join(assetsDir, "vendor.go.tmpl")
|
||||||
vendorTmpl = "vendor.go.tmpl"
|
vendorTmpl = "vendor.go.tmpl"
|
||||||
|
|
||||||
// documentation.go generation
|
// documentation.go generation
|
||||||
documentationYAML = ".linguist/lib/linguist/documentation.yml"
|
documentationYAML = filepath.Join(libDir, "documentation.yml")
|
||||||
documentationFile = "data/documentation.go"
|
documentationFile = filepath.Join("data", "documentation.go")
|
||||||
documentationTmplPath = "internal/code-generator/assets/documentation.go.tmpl"
|
documentationTmplPath = filepath.Join(assetsDir, "documentation.go.tmpl")
|
||||||
documentationTmpl = "documentation.go.tmpl"
|
documentationTmpl = "documentation.go.tmpl"
|
||||||
|
|
||||||
// type.go generation
|
// type.go generation
|
||||||
typeFile = "data/type.go"
|
typeFile = filepath.Join("data", "type.go")
|
||||||
typeTmplPath = "internal/code-generator/assets/type.go.tmpl"
|
typeTmplPath = filepath.Join(assetsDir, "type.go.tmpl")
|
||||||
typeTmpl = "type.go.tmpl"
|
typeTmpl = "type.go.tmpl"
|
||||||
|
|
||||||
// interpreter.go generation
|
// interpreter.go generation
|
||||||
interpretersFile = "data/interpreter.go"
|
interpretersFile = filepath.Join("data", "interpreter.go")
|
||||||
interpretersTmplPath = "internal/code-generator/assets/interpreter.go.tmpl"
|
interpretersTmplPath = filepath.Join(assetsDir, "interpreter.go.tmpl")
|
||||||
interpretersTmpl = "interpreter.go.tmpl"
|
interpretersTmpl = "interpreter.go.tmpl"
|
||||||
|
|
||||||
// filename.go generation
|
// filename.go generation
|
||||||
filenamesFile = "data/filename.go"
|
filenamesFile = filepath.Join("data", "filename.go")
|
||||||
filenamesTmplPath = "internal/code-generator/assets/filename.go.tmpl"
|
filenamesTmplPath = filepath.Join(assetsDir, "filename.go.tmpl")
|
||||||
filenamesTmpl = "filename.go.tmpl"
|
filenamesTmpl = "filename.go.tmpl"
|
||||||
|
|
||||||
// alias.go generation
|
// alias.go generation
|
||||||
aliasesFile = "data/alias.go"
|
aliasesFile = filepath.Join("data", "alias.go")
|
||||||
aliasesTmplPath = "internal/code-generator/assets/alias.go.tmpl"
|
aliasesTmplPath = filepath.Join(assetsDir, "alias.go.tmpl")
|
||||||
aliasesTmpl = "alias.go.tmpl"
|
aliasesTmpl = "alias.go.tmpl"
|
||||||
|
|
||||||
// frequencies.go generation
|
// frequencies.go generation
|
||||||
frequenciesFile = "data/frequencies.go"
|
frequenciesFile = filepath.Join("data", "frequencies.go")
|
||||||
frequenciesTmplPath = "internal/code-generator/assets/frequencies.go.tmpl"
|
frequenciesTmplPath = filepath.Join(assetsDir, "frequencies.go.tmpl")
|
||||||
frequenciesTmpl = "frequencies.go.tmpl"
|
frequenciesTmpl = "frequencies.go.tmpl"
|
||||||
|
|
||||||
// commit.go generation
|
// commit.go generation
|
||||||
commitFile = "data/commit.go"
|
commitFile = filepath.Join("data", "commit.go")
|
||||||
commitTmplPath = "internal/code-generator/assets/commit.go.tmpl"
|
commitTmplPath = filepath.Join(assetsDir, "commit.go.tmpl")
|
||||||
commitTmpl = "commit.go.tmpl"
|
commitTmpl = "commit.go.tmpl"
|
||||||
|
|
||||||
// mimeType.go generation
|
// mimeType.go generation
|
||||||
mimeTypeFile = "data/mimeType.go"
|
mimeTypeFile = filepath.Join("data", "mimeType.go")
|
||||||
mimeTypeTmplPath = "internal/code-generator/assets/mimeType.go.tmpl"
|
mimeTypeTmplPath = filepath.Join(assetsDir, "mimeType.go.tmpl")
|
||||||
mimeTypeTmpl = "mimeType.go.tmpl"
|
mimeTypeTmpl = "mimeType.go.tmpl"
|
||||||
|
|
||||||
// colors.go generation
|
// colors.go generation
|
||||||
colorsFile = "data/colors.go"
|
colorsFile = filepath.Join("data", "colors.go")
|
||||||
colorsTmplPath = "internal/code-generator/assets/colors.go.tmpl"
|
colorsTmplPath = filepath.Join(assetsDir, "colors.go.tmpl")
|
||||||
colorsTmpl = "colors.go.tmpl"
|
colorsTmpl = "colors.go.tmpl"
|
||||||
|
|
||||||
commitPath = ".linguist/.git/HEAD"
|
commitPath = filepath.Join(".linguist", ".git", "HEAD")
|
||||||
)
|
)
|
||||||
|
|
||||||
type generatorFiles struct {
|
type generatorFiles struct {
|
||||||
@ -125,7 +128,7 @@ func getCommit(path string) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if string(commit) == "ref: refs/heads/master\n" {
|
if string(commit) == "ref: refs/heads/master\n" {
|
||||||
path = ".linguist/.git/" + string(commit[5:len(commit)-1])
|
path = filepath.Join(".linguist", ".git/", string(commit[5:len(commit)-1]))
|
||||||
commit, err = ioutil.ReadFile(path)
|
commit, err = ioutil.ReadFile(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user