Skip to content

Commit

Permalink
Merge pull request #9 from arnavrneo/test
Browse files Browse the repository at this point in the history
[UPDATE] Visual Enhancement
  • Loading branch information
arnavrneo authored Dec 27, 2023
2 parents 3bd6c05 + 2b8eb7c commit 25c2666
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
18 changes: 12 additions & 6 deletions cmd/clean/clean.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bufio"
"bytes"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"os"
"pyreqs/cmd/create"
Expand All @@ -17,11 +18,14 @@ import (

var reqPath string

var blue = color.New(color.FgBlue)
var bGreen = color.New(color.FgGreen)

func cleanReq(reqPath string, dirPath string, venvPath string, ignoreDirs string, printReq bool, debug bool) {

// TODO: better way of showing errors
if reqPath == " " {
panic("Path to requirements.txt not passed!")
panic(color.RedString("Path to requirements.txt not passed!"))
}

pyFiles, dirList := create.GetPaths(dirPath, ignoreDirs)
Expand Down Expand Up @@ -62,9 +66,10 @@ func cleanReq(reqPath string, dirPath string, venvPath string, ignoreDirs string
}

if debug {
fmt.Print("Imports from project: => ")
blue.Print(("Imports from project: => "))
for i := range importsInfo {
fmt.Print(i, " ")
bGreen.Print(i)
fmt.Print(" ")
}
fmt.Println()
}
Expand All @@ -90,9 +95,10 @@ func cleanReq(reqPath string, dirPath string, venvPath string, ignoreDirs string
}

if debug {
fmt.Print("Imports Matched: => ")
blue.Print("Imports Matched: => ")
for _, i := range matchedImports {
fmt.Print(i, " ")
bGreen.Print(i)
fmt.Print(" ")
}
}

Expand All @@ -103,7 +109,7 @@ func cleanReq(reqPath string, dirPath string, venvPath string, ignoreDirs string
_, err = buf.WriteTo(reqFile)
utils.Check(err)

fmt.Print("\nSuccessfully cleaned requirements.txt!\n")
fmt.Print("\nSuccessfully cleaned " + color.GreenString("requirements.txt!\n"))
}

// Cmd represents the clean command
Expand Down
21 changes: 11 additions & 10 deletions cmd/create/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"embed"
"encoding/json"
"fmt"
"github.com/fatih/color"
"github.com/spf13/cobra"
"io"
"maps"
Expand All @@ -17,6 +18,7 @@ import (
"path/filepath"
"pyreqs/cmd/utils"
"regexp"
"strconv"
"strings"
"time"
)
Expand Down Expand Up @@ -85,7 +87,7 @@ func GetPaths(dirs string, ignoreDirs string) ([]string, []string) {
for _, l := range ignoreDirList {
if f.Name() == l.Name() {
if debug {
fmt.Println("Skipped Directory: ", l)
fmt.Println(color.BlueString("Skipping Directory: "), l.Name())
}
return filepath.SkipDir
}
Expand All @@ -106,7 +108,7 @@ func GetPaths(dirs string, ignoreDirs string) ([]string, []string) {
}

if debug {
fmt.Print("Found ", len(pyFiles), " .py files.\n")
fmt.Println(color.BlueString("Found ") + color.GreenString(strconv.Itoa(len(pyFiles))) + color.BlueString(" .py files."))
}

return pyFiles, dirList
Expand Down Expand Up @@ -212,10 +214,10 @@ func ReadImports(pyFiles []string, dirList []string) map[string]struct{} {
}

if debug {
fmt.Println("Total Imports: ", totalImportCount)
fmt.Println("Total Directory Imports: ", len(dirImports))
fmt.Println("Total Python Inbuilt Imports: ", inbuiltImportCount)
fmt.Println("Total User Imports: ", totalImportCount-(len(dirImports)+inbuiltImportCount))
fmt.Println(color.BlueString("Total Imports: ") + color.GreenString(strconv.Itoa(totalImportCount)))
fmt.Println(color.BlueString("Total Directory Imports: ") + color.GreenString(strconv.Itoa(len(dirImports))))
fmt.Println(color.BlueString("Total Python Inbuilt Imports: ") + color.GreenString(strconv.Itoa(inbuiltImportCount)))
fmt.Println(color.BlueString("Total User Imports: ") + color.GreenString(strconv.Itoa(totalImportCount-(len(dirImports)+inbuiltImportCount))))
}

return imports
Expand Down Expand Up @@ -357,8 +359,8 @@ func writeRequirements(venvDir string, codesDir string, savePath string, print b
pypiSet := FetchPyPIServer(pypiStore)

if debug {
fmt.Println("Total Local Imports (from venv): ", len(localSet))
fmt.Println("Total PyPI server Imports: ", len(pypiSet))
fmt.Println(color.BlueString("Total Local Imports (from venv): ") + color.GreenString(strconv.Itoa(len(localSet))))
fmt.Println(color.BlueString("Total PyPI server Imports: ") + color.GreenString(strconv.Itoa(len(pypiSet))))
}

importsInfo := make(map[string]string)
Expand Down Expand Up @@ -389,8 +391,7 @@ func writeRequirements(venvDir string, codesDir string, savePath string, print b
}
}

fmt.Printf("Created successfully!\nSaved to %s\n", savePath+"requirements.txt")

fmt.Printf("Created successfully!\nSaved to %s\n", color.GreenString(savePath+"requirements.txt"))
}

// Cmd represents the create command
Expand Down
8 changes: 7 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ module pyreqs

go 1.21

require github.com/spf13/cobra v1.8.0
require (
github.com/fatih/color v1.16.0
github.com/spf13/cobra v1.8.0
)

require (
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/spf13/pflag v1.0.5 // indirect
golang.org/x/sys v0.14.0 // indirect
)
11 changes: 11 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q=
golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright © 2023 NAME HERE <EMAIL ADDRESS>
Copyright © 2023 ARNAV <[email protected]>
*/
package main

Expand Down

0 comments on commit 25c2666

Please sign in to comment.