Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
227 views
in Technique[技术] by (71.8m points)

python - Changing console_script entry point interpreter for packaging

I'm packaging some python packages using a well known third party packaging system, and I'm encountering an issue with the way entry points are created.

When I install an entry point on my machine, the entry point will contain a shebang pointed at whatever python interpreter, like so:

in /home/me/development/test/setup.py

from setuptools import setup
setup(
    entry_points={
        "console_scripts": [
            'some-entry-point = test:main',
        ]
    }
)        

in /home/me/.virtualenvs/test/bin/some-entry-point:

#!/home/me/.virtualenvs/test/bin/python
# EASY-INSTALL-ENTRY-SCRIPT: 'test==1.0.0','console_scripts','some-entry-point'
__requires__ = 'test==1.0.0'
import sys
from pkg_resources import load_entry_point

sys.exit(
   load_entry_point('test==1.0.0', 'console_scripts', 'some-entry-point')()
)

As you can see, the entry point boilerplate contains a hard-coded path to the python interpreter that's in the virtual environment that I'm using to create my third party package.

Installing this entry point using my third-party packaging system results in the entry point being installed on the machine. However, with this hard-coded reference to a python interpreter which doesn't exist on the target machine, the user must run python /path/to/some-entry-point.

The shebang makes this pretty unportable. (which isn't a design goal of virtualenv for sure; but I just need to MAKE it a little more portable here.)

I'd rather not resort to crazed find/xargs/sed commands. (Although that's my fallback.)

Is there some way that I can change the interpreter path after the shebang using setuptools flags or configs?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can customize the console_scripts' shebang line by setting 'sys.executable' (learned this from a debian bug report). That is to say...

sys.executable = '/bin/custom_python'

setup(
  entry_points={
    'console_scripts': [
       ... etc...
    ]
  }
)

Better though would be to include the 'execute' argument when building...

setup(
  entry_points={
    'console_scripts': [
       ... etc...
    ]
  },
  options={
      'build_scripts': {
          'executable': '/bin/custom_python',
      },
  }
)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...