Skip to content

Commit

Permalink
Python improvements
Browse files Browse the repository at this point in the history
* Correct some of the broken python installation

* Use different and complete list of the python versions
  • Loading branch information
markelog committed Jun 8, 2019
1 parent ee40724 commit 3467425
Show file tree
Hide file tree
Showing 7 changed files with 2,194 additions and 3,734 deletions.
22 changes: 22 additions & 0 deletions bin/ec/main_python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ var _ = Describe("python", func() {
command, _ := Command("go", "run", path, "ls", "python").Output()

Expect(strings.Contains(string(command), "♥ 2.6.9")).To(Equal(true))

Command("go", "run", path, "rm", "[email protected]").Output()
})

It(`should install "old" 2.7.0 version`, func() {
Expand All @@ -38,6 +40,8 @@ var _ = Describe("python", func() {
command, _ := Command("go", "run", path, "ls", "python").Output()

Expect(strings.Contains(string(command), "♥ 2.7.0")).To(Equal(true))

Command("go", "run", path, "rm", "[email protected]").Output()
})
})

Expand All @@ -51,6 +55,24 @@ var _ = Describe("python", func() {
Execute("go", "run", path, "[email protected]")
})

It(`should install 2.7.13 version`, func() {
Execute("go", "run", path, "[email protected]")

command, _ := Command("go", "run", path, "ls", "python").Output()

Expect(strings.Contains(string(command), "♥ 2.7.13")).To(Equal(true))

Command("go", "run", path, "rm", "[email protected]").Output()
})

It(`should install latest 2.x.x version`, func() {
Execute("go", "run", path, "python@2")

command, _ := Command("go", "run", path, "ls", "python").Output()

Expect(strings.Contains(string(command), "♥ 2.")).To(Equal(true))
})

It("should list installed versions", func() {
command, _ := Command("go", "run", path, "ls", "python").Output()

Expand Down
4 changes: 1 addition & 3 deletions cmd/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
"time"

"github.com/markelog/curse"

"github.com/markelog/eclectica/cmd/print"
"github.com/markelog/eclectica/cmd/print/spinner"
"github.com/markelog/eclectica/list"
"github.com/markelog/eclectica/plugins"
"github.com/markelog/eclectica/versions"

"github.com/markelog/eclectica/cmd/print/spinner"
)

// Ask for language and version from the user
Expand Down
8 changes: 5 additions & 3 deletions plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ import (
"github.com/chuckpreslar/emission"
"github.com/go-errors/errors"
"github.com/kardianos/osext"
"github.com/markelog/archive"
"github.com/markelog/cprf"
"gopkg.in/cavaliercoder/grab.v1"

"github.com/markelog/archive"
"github.com/markelog/cprf"
"github.com/markelog/eclectica/io"
"github.com/markelog/eclectica/pkg"
"github.com/markelog/eclectica/shell"
Expand Down Expand Up @@ -474,7 +474,9 @@ func (plugin *Plugin) Extract() error {
}

// Just in case archive was downloaded, but not extracted
// i.e. this issue comes up at the second run.
// i.e. this issue comes up at the second run if first one was aborted
// and "Rollback" action, for some reason, did not happen
// I dunno, abrupt reboot?
// Which means we will delete folder with path like this –
// /home/user/.eclectica/versions/go1.7.1.linux-amd64
os.RemoveAll(filepath.Join(extractionPlace, plugin.info["filename"]))
Expand Down
38 changes: 9 additions & 29 deletions plugins/python/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ import (
eStrings "github.com/markelog/eclectica/strings"
"github.com/markelog/eclectica/variables"
"github.com/markelog/eclectica/versions"
"github.com/markelog/release"
)

var (

// VersionLink is the URL link from which we can get all possible versions
VersionLink = "https://hg.python.org/cpython/tags"
VersionLink = "https://www.python.org/downloads/"

remoteVersion = "https://www.python.org/ftp/python"
versionPattern = "^\\d+\\.\\d+(?:\\.\\d)?"
Expand Down Expand Up @@ -203,38 +204,20 @@ func (python Python) ListRemote() (result []string, err error) {
return nil, errors.New(err)
}

tmp := []string{}
version := regexp.MustCompile(versionPattern)
links := doc.Find(".bigtable td:first-child a")
links := doc.Find(".release-number a")

for i := range links.Nodes {
content := links.Eq(i).Text()

content = strings.TrimSpace(content)
content = strings.Replace(content, "v", "", 1)
content = strings.Replace(content, "Python ", "", 1)

if version.MatchString(content) {
tmp = append(tmp, content)
result = append(result, content)
}
}

// Remove < 2.7 versions and "Pre" versions
for _, element := range tmp {
smr, _ := semver.Make(versions.Semverify(element))

if len(smr.Pre) > 0 {
continue
}
if smr.Major < 2 {
continue
}
if smr.Major == 2 && smr.Minor < 7 {
continue
}

result = append(result, element)
}

return
}

Expand Down Expand Up @@ -383,8 +366,8 @@ func (python Python) getOSXEnvs(original []string) []string {

for _, name := range externals {
opt := "/usr/local/opt/"
libFlags += `-L` + filepath.Join(opt, name, "lib") + " "
includeFlags += "-I" + filepath.Join(opt, name, "include") + " "
libFlags += "-L" + filepath.Join(opt, name, "lib") + " "
includeFlags += "-I" + filepath.Join(opt, name, "include") + ""
}

// For zlib
Expand All @@ -394,6 +377,8 @@ func (python Python) getOSXEnvs(original []string) []string {

original = append(original, "CPPFLAGS="+includeFlags)
original = append(original, "LDFLAGS="+libFlags)
// Since otherwise configure breaks for some versions :/
original = append(original, "MACOSX_DEPLOYMENT_TARGET="+release.Version())

return original
}
Expand Down Expand Up @@ -433,11 +418,6 @@ func (python Python) getCmd(args ...string) (
func (python Python) externals() (err error) {
path := variables.Path("python", python.Version)

// Don't need to do anything if we already have pip and setuptools
if hasTools(python.Version) {
return
}

// Now try the "hard" way
err = python.downloadExternals()
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions plugins/python/python_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ var _ = Describe("python", func() {
Expect(err).To(BeNil())
})

It("should exclude some version", func() {
Expect(remotes[0]).To(Equal("3.4.5"))
It("should get first and last versions", func() {
Expect(remotes[0]).To(Equal("3.7.3"))

last := len(remotes) - 1
Expect(remotes[last]).To(Equal("3.0"))
Expect(remotes[last]).To(Equal("2.0.1"))
})
})

Expand Down
Loading

0 comments on commit 3467425

Please sign in to comment.