go-python / go-python/gopy

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

未关闭
#229 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Go
星标
2.3k
派生
136
平均合并
14 分钟
30 天内合并 PR
2

描述

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
from pybindgen import retval, param, Module
File "/usr/lib/python3.8/site-packages/pybindgen/__init__.py", line 1, in
from pybindgen.typehandlers.base import ReturnValue, Parameter
File "/usr/lib/python3.8/site-packages/pybindgen/typehandlers/__init__.py", line 2, in
from pybindgen.typehandlers import base
File "/usr/lib/python3.8/site-packages/pybindgen/typehandlers/base.py", line 21, in
import logging
File "/usr/lib/python3.8/logging/__init__.py", line 26, in
import sys, os, time, io, re, traceback, warnings, weakref, collections.abc
File "/usr/lib/python3.8/traceback.py", line 5, in
import linecacheb
File "/usr/lib/python3.8/linecache.py", line 11, in
import tokenize
File "/usr/lib/python3.8/tokenize.py", line 34, in
from token import *
File "/go/src/github.com/me/my_project/python/my_project/token.py", line 12, in
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.

贡献指南

这个仓库没有索引到贡献指南

调研方向

Start by reproducing the gopy pkg command in the Docker environment described, then inspect the generated python/my_project/token.py and build.py files alongside the import traceback. Determine how a Go package named token collides with Python's tokenize import, and define whether successful generation or an explicit documented limitation is the intended outcome.

由索引模型根据 Issue 内容生成。

评估

技术栈
go, python
领域
tooling
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
需要澄清
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。