Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/assets/python3-embed.pc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${exec_prefix}
includedir=${prefix}/include

Name: Python
Description: Embed Python into an application
Requires:
Version: 3.13
Libs.private:
Libs: -L${libdir} -lpython313
Cflags: -I${includedir}
36 changes: 36 additions & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Check

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

jobs:
check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.23'

- name: Install embedme
run: npm install -g embedme

- name: Verify README.md embedded code
run: npx embedme --verify README.md

- name: Check formatting
run: |
if [ -n "$(go fmt ./...)" ]; then
echo "Some files are not properly formatted. Please run 'go fmt ./...'"
exit 1
fi
47 changes: 47 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
continue-on-error: true
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-24.04
- windows-latest
defaults:
run:
shell: bash
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Build
run: go install -v ./...

- name: Test with coverage
run: go test -coverprofile=coverage.txt -covermode=atomic ./...

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
file: ./coverage.txt
flags: unittests
name: codecov-umbrella
fail_ci_if_error: true
102 changes: 102 additions & 0 deletions .github/workflows/got.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Got

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
test-windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install got
run: go install ./cmd/got

- name: Test init project
run: got init ../foo

- name: Test build project
env:
GP_INJECT_DEBUG: "1"
run: |
Set-PSDebug -Trace 2
cd ../foo
dir .deps/python/lib/pkgconfig
got build -o foo.exe .
got exec dir
$env:PATH=".deps/python;$env:PATH"
$env:PATH
./foo.exe

- name: Test run project
env:
GP_INJECT_DEBUG: "1"
run: |
cd ../foo
got run -v .

- name: Test install project
run: |
cd ../foo
got install -v .

test:
continue-on-error: true
strategy:
fail-fast: false
matrix:
os:
- macos-latest
- ubuntu-24.04
defaults:
run:
shell: bash
runs-on: ${{matrix.os}}
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: 1.23

- name: Install got
run: go install ./cmd/got

- name: Test init project
run: got init $HOME/foo

- name: Test build project
env:
GP_INJECT_DEBUG: "1"
run: |
set -x
cd $HOME/foo
got exec env
ls $HOME/foo/.deps/python/lib/pkgconfig
got build -o foo .
got exec ls -lh
./foo

- name: Test run project
env:
GP_INJECT_DEBUG: "1"
run: |
cd $HOME/foo
got run -v .

- name: Test install project
run: |
cd $HOME/foo
got install -v .
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,36 @@

A tool to run Go with Python environment configured.

[![Build Status](https://github.com/gotray/got/actions/workflows/go.yml/badge.svg)](https://github.com/gotray/got/actions/workflows/go.yml)
[![codecov](https://codecov.io/github/gotray/got/graph/badge.svg?token=V0ns2Rzmop)](https://codecov.io/github/gotray/got)
![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/cpunion/go-python)
[![GitHub commits](https://badgen.net/github/commits/cpunion/go-python)](https://GitHub.com/Naereen/cpunion/go-python/commit/)
[![GitHub release](https://img.shields.io/github/v/tag/cpunion/go-python.svg?label=release)](https://github.com/gotray/got/releases)
[![Go Report Card](https://goreportcard.com/badge/github.com/gotray/got)](https://goreportcard.com/report/github.com/gotray/got)
[![Go Reference](https://pkg.go.dev/badge/github.com/gotray/got.svg)](https://pkg.go.dev/github.com/gotray/got)


Features:
- Don't need to install Go and Python, just need to download got
- Create a project with Go and Python environment configured
- Build, run, install Go packages with Python environment configured
- Compatible with Windows, Linux, MacOS

## Installation

```bash
go install github.com/gotray/got/cmd/got@latest
```

## Initialize a project

```bash
got init myproject
cd myproject
```

## Run project

```bash
got run .
```
39 changes: 39 additions & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// addCmd represents the add command
var addCmd = &cobra.Command{
Use: "add",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("add called")
},

Check warning on line 24 in cmd/add.go

View check run for this annotation

Codecov / codecov/patch

cmd/add.go#L22-L24

Added lines #L22 - L24 were not covered by tests
}

func init() {
rootCmd.AddCommand(addCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// addCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

Check warning on line 38 in cmd/add.go

View check run for this annotation

Codecov / codecov/patch

cmd/add.go#L27-L38

Added lines #L27 - L38 were not covered by tests
}
37 changes: 37 additions & 0 deletions cmd/build.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"os"

"github.com/gotray/got/cmd/internal/rungo"
"github.com/spf13/cobra"
)

// buildCmd represents the build command
var buildCmd = &cobra.Command{
Use: "build [flags] [package]",
Short: "Build a Go package with Python environment configured",
Long: func() string {
intro := "Build compiles a Go package with the Python environment properly configured.\n\n"
help, err := rungo.GetGoCommandHelp("build")
if err != nil {
return intro + "Failed to get go help: " + err.Error()
}
return intro + help

Check warning on line 24 in cmd/build.go

View check run for this annotation

Codecov / codecov/patch

cmd/build.go#L18-L24

Added lines #L18 - L24 were not covered by tests
}(),
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
if err := rungo.RunCommand("go", append([]string{"build"}, args...)); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}

Check warning on line 31 in cmd/build.go

View check run for this annotation

Codecov / codecov/patch

cmd/build.go#L27-L31

Added lines #L27 - L31 were not covered by tests
},
}

func init() {
rootCmd.AddCommand(buildCmd)

Check warning on line 36 in cmd/build.go

View check run for this annotation

Codecov / codecov/patch

cmd/build.go#L35-L36

Added lines #L35 - L36 were not covered by tests
}
34 changes: 34 additions & 0 deletions cmd/exec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package cmd

import (
"fmt"
"os"

"github.com/gotray/got/cmd/internal/rungo"
"github.com/spf13/cobra"
)

// execCmd represents the run command
var execCmd = &cobra.Command{
Use: "exec [flags] [arguments...]",
Short: "Exec command with the Go and Python environment properly configured",
Long: "Exec executes a command with the Go and Python environment properly configured.",
DisableFlagParsing: true,
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.Help()
return
}
if err := rungo.RunCommand(args[0], args[1:]); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s\n", err)
os.Exit(1)
}

Check warning on line 28 in cmd/exec.go

View check run for this annotation

Codecov / codecov/patch

cmd/exec.go#L20-L28

Added lines #L20 - L28 were not covered by tests
},
}

func init() {
rootCmd.AddCommand(execCmd)

Check warning on line 33 in cmd/exec.go

View check run for this annotation

Codecov / codecov/patch

cmd/exec.go#L32-L33

Added lines #L32 - L33 were not covered by tests
}
10 changes: 10 additions & 0 deletions cmd/got/gopy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
Copyright © 2024 NAME HERE <EMAIL ADDRESS>
*/
package main

import cmd "github.com/gotray/got/cmd"

func main() {
cmd.Execute()

Check warning on line 9 in cmd/got/gopy.go

View check run for this annotation

Codecov / codecov/patch

cmd/got/gopy.go#L8-L9

Added lines #L8 - L9 were not covered by tests
}
Loading
Loading