복붙노트

[PYTHON] 패키징을 위해 console_script 진입 점 인터프리터 변경

PYTHON

패키징을 위해 console_script 진입 점 인터프리터 변경

필자는 잘 알려진 써드 파티 패키징 시스템을 사용하여 파이썬 패키지를 패키징하고 있으며, 엔트리 포인트가 생성되는 방식에 문제가있다.

내 컴퓨터에 엔트리 포인트를 설치할 때 엔트리 포인트는 파이썬 인터프리터가 가리키는 세방을 포함 할 것이다.

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')()
)

보시다시피 진입 점 보일러 플레이트에는 타사 패키지를 만드는 데 사용하는 가상 환경에있는 Python 인터프리터에 대한 하드 코딩 된 경로가 포함되어 있습니다.

제 3 자 패키지 시스템을 사용하여이 진입 점을 설치하면 진입 점이 시스템에 설치됩니다. 그러나 대상 컴퓨터에 존재하지 않는 파이썬 인터프리터에 대한 하드 코딩 된 참조를 사용하면 python / path / to / some-entry-point를 실행해야합니다.

shebang은 이것을 꽤 귀찮게 만듭니다. (virtualenv의 디자인 목표는 분명하지 않지만 여기서는 조금 더 이식성있게 만들 필요가 있습니다.)

차라리 find / xargs / sed 명령어를 사용하지 않을 것입니다. (그것이 나의 후퇴이지만.)

거기에 setuptools 플래그 또는 configs를 사용하여 shebang 후 통역사 경로를 변경할 수있는 몇 가지 방법이 있습니까?

해결법

  1. ==============================

    1.'sys.executable'(데비안 버그 리포트에서 이것을 배웠습니다)을 설정하여 console_scripts의 shebang 행을 사용자 정의 할 수 있습니다. 즉 말하자면...

    'sys.executable'(데비안 버그 리포트에서 이것을 배웠습니다)을 설정하여 console_scripts의 shebang 행을 사용자 정의 할 수 있습니다. 즉 말하자면...

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

    건물을 만들 때 '실행'인수를 포함하는 것이 더 좋지만 ...

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

    2.진입 점에서 사용할 파이썬과 일치하도록 setup.py의 내용을 변경하기 만하면됩니다.

    진입 점에서 사용할 파이썬과 일치하도록 setup.py의 내용을 변경하기 만하면됩니다.

    #!/bin/custom_python
    

    (나는 @damian 대답을 시도했지만 나를 위해 일하지 않았다. 아마도 데비안 Jessie의 setuptools 버전은 너무 오래되었다.)

  3. ==============================

    3.setup.py를 수정하지 않고 런타임에이 작업을 수행하고자하는 사람을 위해 나중에 pip를 사용하여 pip.py 빌드에 interpreter 경로를 전달할 수 있습니다.

    setup.py를 수정하지 않고 런타임에이 작업을 수행하고자하는 사람을 위해 나중에 pip를 사용하여 pip.py 빌드에 interpreter 경로를 전달할 수 있습니다.

    $ ./venv/bin/pip install --global-option=build \
    --global-option='--executable=/bin/custom_python' .
    ...
    $ head -1 ./venv/bin/some-entry-point
    #!/bin/custom_python
    
  4. from https://stackoverflow.com/questions/17237878/changing-console-script-entry-point-interpreter-for-packaging by cc-by-sa and MIT license