Python setuptools 사용자 정의 구성
문제
저는 Python 모듈을 패키징하고 있으며 사용자가 일부 사용자 정의 옵션을 사용하여 모듈을 빌드할 수 있기를 바랍니다.특히 패키지에 사용할 수 있는 특정 실행 파일을 제공하면 패키지가 추가 마법을 수행합니다.
이상적으로는 사용자가 다음을 실행합니다. setup.py install
또는 setup.py install --magic-doer=/path/to/executable
.두 번째 옵션을 사용했다면 코드 어딘가에 변수를 설정하고 거기서부터 시작했을 것입니다.
파이썬으로 이것이 가능합니까? setuptools
?그렇다면 어떻게 해야 합니까?
해결책
할 수 있을 것 같습니다...읽다 이것.
기사에서 발췌:
명령은 setuptools.Command에서 파생되는 간단한 클래스이며 다음과 같은 몇 가지 최소 요소를 정의합니다.
description: describe the command
user_options: a list of options
initialize_options(): called at startup
finalize_options(): called at the end
run(): called to run the command
setuptools 문서는 Command 서브클래싱에 대해 여전히 비어 있지만 최소 클래스는 다음과 같습니다.
class MyCommand(Command):
"""setuptools Command"""
description = "run my command"
user_options = tuple()
def initialize_options(self):
"""init options"""
pass
def finalize_options(self):
"""finalize options"""
pass
def run(self):
"""runner"""
XXX DO THE JOB HERE
그런 다음 setup.py 파일의 진입점을 사용하여 클래스를 명령으로 후크할 수 있습니다.
setup(
# ...
entry_points = {
"distutils.commands": [
"my_command = mypackage.some_module:MyCommand"]}
제휴하지 않습니다 StackOverflow