github.phpd.cn/thought-machine/please@v12.2.0+incompatible/tools/please_pex/pex_main.go (about) 1 // Package main implements please_pex, which builds runnable Python zip files for us. 2 package main 3 4 import ( 5 "gopkg.in/op/go-logging.v1" 6 7 "cli" 8 "tools/please_pex/pex" 9 ) 10 11 var log = logging.MustGetLogger("please_pex") 12 13 var opts = struct { 14 Usage string 15 Verbosity int `short:"v" long:"verbose" default:"1" description:"Verbosity of output (higher number = more output, default 1 -> warnings and errors only)"` 16 Out string `short:"o" long:"out" env:"OUT" description:"Output file"` 17 EntryPoint string `short:"e" long:"entry_point" env:"SRC" description:"Entry point to pex file"` 18 ModuleDir string `short:"m" long:"module_dir" description:"Python module dir to implicitly load modules from"` 19 TestSrcs []string `long:"test_srcs" env:"SRCS" env-delim:" " description:"Test source files"` 20 Test bool `short:"t" long:"test" description:"True if we're to build a test"` 21 Interpreter string `short:"i" long:"interpreter" env:"TOOLS_INTERPRETER" description:"Python interpreter to use"` 22 TestRunner string `short:"r" long:"test_runner" choice:"unittest" choice:"pytest" default:"unittest" description:"Test runner to use"` 23 Shebang string `short:"s" long:"shebang" description:"Explicitly set shebang to this"` 24 ZipSafe bool `long:"zip_safe" description:"Marks this pex as zip-safe"` 25 NoZipSafe bool `long:"nozip_safe" description:"Marks this pex as zip-unsafe"` 26 }{ 27 Usage: ` 28 please_pex is a tool to create .pex files for Python. 29 30 These are not really pex files any more, they are just zip files (which Python supports 31 out of the box). They still have essentially the same approach of containing all the 32 dependent code as a self-contained self-executable environment. 33 `, 34 } 35 36 func main() { 37 cli.ParseFlagsOrDie("please_pex", "9.6.0", &opts) 38 cli.InitLogging(opts.Verbosity) 39 w := pex.NewWriter(opts.EntryPoint, opts.Interpreter, !opts.NoZipSafe) 40 if opts.Shebang != "" { 41 w.SetShebang(opts.Shebang) 42 } 43 if opts.Test { 44 w.SetTest(opts.TestSrcs, opts.TestRunner == "pytest") 45 } 46 if err := w.Write(opts.Out, opts.ModuleDir); err != nil { 47 log.Fatalf("%s", err) 48 } 49 }