Skip to content

Commit 51aa0aa

Browse files
committed
initial
1 parent 72e3723 commit 51aa0aa

33 files changed

+3012
-0
lines changed

.github/assets/python3-embed.pc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
prefix=${pcfiledir}/../..
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}
4+
includedir=${prefix}/include
5+
6+
Name: Python
7+
Description: Embed Python into an application
8+
Requires:
9+
Version: 3.13
10+
Libs.private:
11+
Libs: -L${libdir} -lpython313
12+
Cflags: -I${includedir}

.github/workflows/check.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
name: Check
2+
3+
on:
4+
push:
5+
branches: [ "*" ]
6+
pull_request:
7+
branches: [ "*" ]
8+
9+
jobs:
10+
check:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
15+
- name: Set up Node.js
16+
uses: actions/setup-node@v4
17+
with:
18+
node-version: '20'
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v4
22+
with:
23+
go-version: '1.23'
24+
25+
- name: Install embedme
26+
run: npm install -g embedme
27+
28+
- name: Verify README.md embedded code
29+
run: npx embedme --verify README.md
30+
31+
- name: Check formatting
32+
run: |
33+
if [ -n "$(go fmt ./...)" ]; then
34+
echo "Some files are not properly formatted. Please run 'go fmt ./...'"
35+
exit 1
36+
fi

.github/workflows/go.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Go
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
build:
14+
continue-on-error: true
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
os:
19+
- macos-latest
20+
- ubuntu-24.04
21+
- windows-latest
22+
defaults:
23+
run:
24+
shell: bash
25+
runs-on: ${{matrix.os}}
26+
steps:
27+
- uses: actions/checkout@v4
28+
29+
- name: Set up Go
30+
uses: actions/setup-go@v4
31+
with:
32+
go-version: 1.23
33+
34+
- name: Build
35+
run: go install -v ./...
36+
37+
- name: Test with coverage
38+
run: go test -coverprofile=coverage.txt -covermode=atomic ./...
39+
40+
- name: Upload coverage to Codecov
41+
uses: codecov/codecov-action@v4
42+
with:
43+
token: ${{ secrets.CODECOV_TOKEN }}
44+
file: ./coverage.txt
45+
flags: unittests
46+
name: codecov-umbrella
47+
fail_ci_if_error: true

.github/workflows/got.yml

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# This workflow will build a golang project
2+
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
3+
4+
name: Got
5+
6+
on:
7+
push:
8+
branches: [ "main" ]
9+
pull_request:
10+
branches: [ "main" ]
11+
12+
jobs:
13+
test-windows:
14+
runs-on: windows-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: 1.23
22+
23+
- name: Install got
24+
run: go install ./cmd/got
25+
26+
- name: Test init project
27+
run: got init ../foo
28+
29+
- name: Test build project
30+
env:
31+
GP_INJECT_DEBUG: "1"
32+
run: |
33+
Set-PSDebug -Trace 2
34+
cd ../foo
35+
dir .deps/python/lib/pkgconfig
36+
got build -o foo.exe .
37+
got exec dir
38+
$env:PATH=".deps/python;$env:PATH"
39+
$env:PATH
40+
./foo.exe
41+
42+
- name: Test run project
43+
env:
44+
GP_INJECT_DEBUG: "1"
45+
run: |
46+
cd ../foo
47+
got run -v .
48+
49+
- name: Test install project
50+
run: |
51+
cd ../foo
52+
got install -v .
53+
54+
test:
55+
continue-on-error: true
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
os:
60+
- macos-latest
61+
- ubuntu-24.04
62+
defaults:
63+
run:
64+
shell: bash
65+
runs-on: ${{matrix.os}}
66+
steps:
67+
- uses: actions/checkout@v4
68+
69+
- name: Set up Go
70+
uses: actions/setup-go@v4
71+
with:
72+
go-version: 1.23
73+
74+
- name: Install got
75+
run: go install ./cmd/got
76+
77+
- name: Test init project
78+
run: got init $HOME/foo
79+
80+
- name: Test build project
81+
env:
82+
GP_INJECT_DEBUG: "1"
83+
run: |
84+
set -x
85+
cd $HOME/foo
86+
got exec env
87+
ls $HOME/foo/.deps/python/lib/pkgconfig
88+
got build -o foo .
89+
got exec ls -lh
90+
./foo
91+
92+
- name: Test run project
93+
env:
94+
GP_INJECT_DEBUG: "1"
95+
run: |
96+
cd $HOME/foo
97+
got run -v .
98+
99+
- name: Test install project
100+
run: |
101+
cd $HOME/foo
102+
got install -v .

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,22 @@ Features:
77
- Create a project with Go and Python environment configured
88
- Build, run, install Go packages with Python environment configured
99
- Compatible with Windows, Linux, MacOS
10+
11+
## Installation
12+
13+
```bash
14+
go install github.com/gotray/got/cmd/got@latest
15+
```
16+
17+
## Initialize a project
18+
19+
```bash
20+
got init myproject
21+
cd myproject
22+
```
23+
24+
## Run project
25+
26+
```bash
27+
got run .
28+
```

cmd/add.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
9+
"github.com/spf13/cobra"
10+
)
11+
12+
// addCmd represents the add command
13+
var addCmd = &cobra.Command{
14+
Use: "add",
15+
Short: "A brief description of your command",
16+
Long: `A longer description that spans multiple lines and likely contains examples
17+
and usage of using your command. For example:
18+
19+
Cobra is a CLI library for Go that empowers applications.
20+
This application is a tool to generate the needed files
21+
to quickly create a Cobra application.`,
22+
Run: func(cmd *cobra.Command, args []string) {
23+
fmt.Println("add called")
24+
},
25+
}
26+
27+
func init() {
28+
rootCmd.AddCommand(addCmd)
29+
30+
// Here you will define your flags and configuration settings.
31+
32+
// Cobra supports Persistent Flags which will work for this command
33+
// and all subcommands, e.g.:
34+
// addCmd.PersistentFlags().String("foo", "", "A help for foo")
35+
36+
// Cobra supports local flags which will only run when this command
37+
// is called directly, e.g.:
38+
// addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
39+
}

cmd/build.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"os"
9+
10+
"github.com/gotray/got/cmd/internal/rungo"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// buildCmd represents the build command
15+
var buildCmd = &cobra.Command{
16+
Use: "build [flags] [package]",
17+
Short: "Build a Go package with Python environment configured",
18+
Long: func() string {
19+
intro := "Build compiles a Go package with the Python environment properly configured.\n\n"
20+
help, err := rungo.GetGoCommandHelp("build")
21+
if err != nil {
22+
return intro + "Failed to get go help: " + err.Error()
23+
}
24+
return intro + help
25+
}(),
26+
DisableFlagParsing: true,
27+
Run: func(cmd *cobra.Command, args []string) {
28+
if err := rungo.RunCommand("go", append([]string{"build"}, args...)); err != nil {
29+
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
30+
os.Exit(1)
31+
}
32+
},
33+
}
34+
35+
func init() {
36+
rootCmd.AddCommand(buildCmd)
37+
}

cmd/exec.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package cmd
5+
6+
import (
7+
"fmt"
8+
"os"
9+
10+
"github.com/gotray/got/cmd/internal/rungo"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
// execCmd represents the run command
15+
var execCmd = &cobra.Command{
16+
Use: "exec [flags] [arguments...]",
17+
Short: "Exec command with the Go and Python environment properly configured",
18+
Long: "Exec executes a command with the Go and Python environment properly configured.",
19+
DisableFlagParsing: true,
20+
Run: func(cmd *cobra.Command, args []string) {
21+
if len(args) == 0 {
22+
cmd.Help()
23+
return
24+
}
25+
if err := rungo.RunCommand(args[0], args[1:]); err != nil {
26+
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
27+
os.Exit(1)
28+
}
29+
},
30+
}
31+
32+
func init() {
33+
rootCmd.AddCommand(execCmd)
34+
}

cmd/got/gopy.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
3+
*/
4+
package main
5+
6+
import cmd "github.com/gotray/got/cmd"
7+
8+
func main() {
9+
cmd.Execute()
10+
}

0 commit comments

Comments
 (0)