go-python / gopy

gopy generates a CPython extension module from a go package.
BSD 3-Clause "New" or "Revised" License
2.05k stars 113 forks source link

Spectacular failure when project contains a go package named "token" #229

Open HT154 opened 4 years ago

HT154 commented 4 years ago

Repro:

docker run -it -v `pwd`:/go/src/github.com/me/my_project docker.apple.com/golang:1.15-alpine
# in container
cd /go/src/github.com/me/my_project
apk add build-base git python3 python3-dev # Python 3.8.5
python3 -m ensurepip
go mod download
make gopy goimports
pip3 install pybindgen==0.21.0 setuptools==49.3.2 wheel==0.34.2

gopy pkg -vm=python3 -output=python -name=my_project github.com/me/my_project

Log excerpt:

--- building package ---
gopy pkg -vm=python3 -output=python -name=my_project github.com/me/my_project
goimports -w my_project.go
go build -buildmode=c-shared -o my_project_go.so .
python3 build.py
cmd had error: exit status 1  output:
oTraceback (most recent call last):
  File "build.py", line 5, in <module>
    from pybindgen import retval, param, Module
  File "/usr/lib/python3.8/site-packages/pybindgen/__init__.py", line 1, in <module>
    from pybindgen.typehandlers.base import ReturnValue, Parameter
  File "/usr/lib/python3.8/site-packages/pybindgen/typehandlers/__init__.py", line 2, in <module>
    from pybindgen.typehandlers import base
  File "/usr/lib/python3.8/site-packages/pybindgen/typehandlers/base.py", line 21, in <module>
    import logging
  File "/usr/lib/python3.8/logging/__init__.py", line 26, in <module>
    import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
  File "/usr/lib/python3.8/traceback.py", line 5, in <module>
    import linecacheb
  File "/usr/lib/python3.8/linecache.py", line 11, in <module>
    import tokenize
  File "/usr/lib/python3.8/tokenize.py", line 34, in <module>
    from token import *
  File "/go/src/github.com/me/my_project/python/my_project/token.py", line 12, in <module>
    import _my_project
ModuleNotFoundError: No module named '_my_project'

It looks like it's failing due to a bare relative import inside the python stdlib tokenize library, so I'm not sure if there's anything gopy can do about.

But I did want to at least get this up in an issue so some other poor soul like me can stumble across it and save some hair-pulling by renaming one of their modules.