Skip to content

Commit 92aed8a

Browse files
authored
Merge branch 'go-python:master' into master
2 parents 9421b6b + 965bc08 commit 92aed8a

6 files changed

Lines changed: 159 additions & 90 deletions

File tree

.github/workflows/ci.yml

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
schedule:
9+
- cron: '0 2 * * 1-5'
10+
11+
env:
12+
GOPROXY: "https://proxy.golang.org"
13+
TAGS: "-tags=ci"
14+
COVERAGE: "-coverpkg=github.com/go-python/gpython/..."
15+
16+
jobs:
17+
18+
build:
19+
name: Build
20+
strategy:
21+
matrix:
22+
go-version: [1.17.x, 1.16.x]
23+
platform: [ubuntu-latest, macos-latest, windows-latest]
24+
runs-on: ${{ matrix.platform }}
25+
steps:
26+
- name: Install Go
27+
uses: actions/setup-go@v2
28+
with:
29+
go-version: ${{ matrix.go-version }}
30+
31+
- name: Setup Git for Windows
32+
run: |
33+
git config --global core.autocrlf false
34+
git config --global core.eol lf
35+
36+
- name: Checkout code
37+
uses: actions/checkout@v2
38+
39+
- name: Cache-Go
40+
uses: actions/cache@v1
41+
with:
42+
# In order:
43+
# * Module download cache
44+
# * Build cache (Linux)
45+
# * Build cache (Mac)
46+
# * Build cache (Windows)
47+
path: |
48+
~/go/pkg/mod
49+
~/.cache/go-build
50+
~/Library/Caches/go-build
51+
'%LocalAppData%\go-build'
52+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
53+
restore-keys: |
54+
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
55+
56+
- name: Install Linux packages
57+
if: matrix.platform == 'ubuntu-latest'
58+
run: |
59+
sudo apt-get update
60+
sudo apt-get install -qq pkg-config python3
61+
62+
- name: Build-Linux-32b
63+
if: matrix.platform == 'ubuntu-latest'
64+
run: |
65+
GOARCH=386 go install -v $TAGS ./...
66+
- name: Build-Linux-64b
67+
if: matrix.platform == 'ubuntu-latest'
68+
run: |
69+
GOARCH=amd64 go install -v $TAGS ./...
70+
- name: Build-Windows
71+
if: matrix.platform == 'windows-latest'
72+
run: |
73+
go install -v $TAGS ./...
74+
- name: Build-Darwin
75+
if: matrix.platform == 'macos-latest'
76+
run: |
77+
go install -v $TAGS ./...
78+
- name: Test Linux
79+
if: matrix.platform == 'ubuntu-latest'
80+
run: |
81+
GOARCH=386 go test $TAGS ./...
82+
GOARCH=amd64 go run ./ci/run-tests.go $TAGS -race $COVERAGE
83+
## FIXME(sbinet): bring back python3.4 or upgrade gpython to python3.x
84+
## python3 py3test.py
85+
- name: Test Windows
86+
if: matrix.platform == 'windows-latest'
87+
run: |
88+
go run ./ci/run-tests.go $TAGS -race
89+
- name: Test Darwin
90+
if: matrix.platform == 'macos-latest'
91+
run: |
92+
go run ./ci/run-tests.go $TAGS -race
93+
- name: Upload-Coverage
94+
if: matrix.platform == 'ubuntu-latest'
95+
uses: codecov/codecov-action@v1

.travis.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# gpython
22

3-
[![Build Status](https://travis-ci.org/go-python/gpython.svg?branch=master)](https://travis-ci.org/go-python/gpython)
3+
[![Build Status](https://github.com/go-python/gpython/workflows/CI/badge.svg)](https://github.com/go-python/gpython/actions)
44
[![codecov](https://codecov.io/gh/go-python/gpython/branch/master/graph/badge.svg)](https://codecov.io/gh/go-python/gpython)
55
[![GoDoc](https://godoc.org/github.com/go-python/gpython?status.svg)](https://godoc.org/github.com/go-python/gpython)
66
[![License](https://img.shields.io/badge/License-BSD--3-blue.svg)](https://github.com/go-python/gpython/blob/master/LICENSE)

appveyor.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

ci/run-tests.go

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
// Copyright 2018 The go-python Authors. All rights reserved.
1+
// Copyright ©2018 The go-python Authors. All rights reserved.
22
// Use of this source code is governed by a BSD-style
33
// license that can be found in the LICENSE file.
44

5+
//go:build ignore
56
// +build ignore
67

78
package main
@@ -10,32 +11,33 @@ import (
1011
"bufio"
1112
"bytes"
1213
"flag"
13-
"io/ioutil"
14+
"fmt"
1415
"log"
1516
"os"
1617
"os/exec"
1718
"strings"
19+
"time"
1820
)
1921

2022
func main() {
2123
log.SetPrefix("ci: ")
2224
log.SetFlags(0)
2325

26+
start := time.Now()
27+
defer func() {
28+
log.Printf("elapsed time: %v\n", time.Since(start))
29+
}()
30+
2431
var (
25-
race = flag.Bool("race", false, "enable race detector")
26-
cover = flag.Bool("cover", false, "enable code coverage")
27-
tags = flag.String("tags", "", "build tags")
32+
race = flag.Bool("race", false, "enable race detector")
33+
cover = flag.String("coverpkg", "", "apply coverage analysis in each test to packages matching the patterns.")
34+
tags = flag.String("tags", "", "build tags")
35+
verbose = flag.Bool("v", false, "enable verbose output")
2836
)
2937

3038
flag.Parse()
3139

32-
out := new(bytes.Buffer)
33-
cmd := exec.Command("go", "list", "./...")
34-
cmd.Stdout = out
35-
cmd.Stderr = os.Stderr
36-
cmd.Stdin = os.Stdin
37-
38-
err := cmd.Run()
40+
pkgs, err := pkgList()
3941
if err != nil {
4042
log.Fatal(err)
4143
}
@@ -48,23 +50,24 @@ func main() {
4850

4951
args := []string{"test"}
5052

51-
if *cover {
52-
args = append(args, "-coverprofile=profile.out", "-covermode=atomic")
53+
if *verbose {
54+
args = append(args, "-v")
55+
}
56+
if *cover != "" {
57+
args = append(args, "-coverprofile=profile.out", "-covermode=atomic", "-coverpkg="+*cover)
5358
}
5459
if *tags != "" {
5560
args = append(args, "-tags="+*tags)
5661
}
57-
if *race {
58-
args = append(args, "-race")
62+
switch {
63+
case *race:
64+
args = append(args, "-race", "-timeout=20m")
65+
default:
66+
args = append(args, "-timeout=10m")
5967
}
6068
args = append(args, "")
6169

62-
scan := bufio.NewScanner(out)
63-
for scan.Scan() {
64-
pkg := scan.Text()
65-
if strings.Contains(pkg, "vendor") {
66-
continue
67-
}
70+
for _, pkg := range pkgs {
6871
args[len(args)-1] = pkg
6972
cmd := exec.Command("go", args...)
7073
cmd.Stdin = os.Stdin
@@ -74,8 +77,8 @@ func main() {
7477
if err != nil {
7578
log.Fatal(err)
7679
}
77-
if *cover {
78-
profile, err := ioutil.ReadFile("profile.out")
80+
if *cover != "" {
81+
profile, err := os.ReadFile("profile.out")
7982
if err != nil {
8083
log.Fatal(err)
8184
}
@@ -92,3 +95,28 @@ func main() {
9295
log.Fatal(err)
9396
}
9497
}
98+
99+
func pkgList() ([]string, error) {
100+
out := new(bytes.Buffer)
101+
cmd := exec.Command("go", "list", "./...")
102+
cmd.Stdout = out
103+
cmd.Stderr = os.Stderr
104+
cmd.Stdin = os.Stdin
105+
106+
err := cmd.Run()
107+
if err != nil {
108+
return nil, fmt.Errorf("could not get package list: %w", err)
109+
}
110+
111+
var pkgs []string
112+
scan := bufio.NewScanner(out)
113+
for scan.Scan() {
114+
pkg := scan.Text()
115+
if strings.Contains(pkg, "vendor") {
116+
continue
117+
}
118+
pkgs = append(pkgs, pkg)
119+
}
120+
121+
return pkgs, nil
122+
}

time/time.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ func time_time(self py.Object) (py.Object, error) {
2121
return py.Float(time.Now().UnixNano()) / 1e9, nil
2222
}
2323

24+
const time_ns_doc = `time_ns() -> int
25+
26+
Return the current time in nanoseconds since the Epoch.
27+
`
28+
29+
func time_time_ns(self py.Object) (py.Object, error) {
30+
return py.Int(time.Now().UnixNano()), nil
31+
}
32+
2433
// func floatclock(_Py_clock_info_t *info) (py.Object, error) {
2534
// value := clock()
2635
// if value == (clock_t)-1 {
@@ -979,6 +988,7 @@ func PyInit_timezone(m py.Object) {
979988
func init() {
980989
methods := []*py.Method{
981990
py.MustNewMethod("time", time_time, 0, time_doc),
991+
py.MustNewMethod("time_ns", time_time_ns, 0, time_ns_doc),
982992
py.MustNewMethod("clock", time_clock, 0, clock_doc),
983993
py.MustNewMethod("clock_gettime", time_clock_gettime, 0, clock_gettime_doc),
984994
py.MustNewMethod("clock_settime", time_clock_settime, 0, clock_settime_doc),
@@ -1043,6 +1053,7 @@ tzname -- tuple of (standard time zone name, DST time zone name)
10431053
Functions:
10441054
10451055
time() -- return current time in seconds since the Epoch as a float
1056+
time_ns() -- return current time in nanoseconds since the Epoch
10461057
clock() -- return CPU time since process start as a float
10471058
sleep() -- delay for a number of seconds given as a float
10481059
gmtime() -- convert seconds since Epoch to UTC tuple

0 commit comments

Comments
 (0)