Skip to content
This repository has been archived by the owner on Jul 24, 2023. It is now read-only.

Compiling kw-args in tests #47

Open
joeyism opened this issue Dec 2, 2016 · 2 comments
Open

Compiling kw-args in tests #47

joeyism opened this issue Dec 2, 2016 · 2 comments

Comments

@joeyism
Copy link

joeyism commented Dec 2, 2016

Hi,

I am trying to run the kw-args code in the tests folder. I ran
go build
which created the kw-args file. When I run
./kw-args
I get the error
could not import 'kwargs'
Is there anything else I need to do for PyImport_ImportModule to import kwargs properly?

EDIT: I also tried #39 solution but that didn't work for me either

@joeyism
Copy link
Author

joeyism commented Dec 2, 2016

I don't know if this is the proper way, especially because it seems like the code will be very dependent on work environment, but I was able to get it working with

sys_path := python.PySys_GetObject("path")

python.PyList_Append(sys_path, python.PyString_FromString("/home/test/Documents/Programming/go/src/github.com/sbinet/go-python/tests/kw-args"))

which is just $GOPATH/src/github.com/sbinet/go-python/tests/kw-args

This seems hacky though, is there a better way to do it?

@sbinet
Copy link
Owner

sbinet commented Dec 3, 2016

hi @joeyism

as you can see here: https://github.com/sbinet/go-python/blob/master/python_test.go#L26, the way these examples are run as tests is basically to add "." to $PYTHONPATH.
Not sure that's something I would recommand for production, though :)

That said, I could add something to the various main.go package with instructions on how to run.
Something like:

// Run like so:
//   $> PYTHONPATH=`pwd`:$PYTHONPATH \
//      go run ./main.go
package main
[...]

what do you think?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants