, 나는 내가 제대로 이해하면 고유의 패키지가 설치되어있는 경우
, 당신은 확인할 수 있습니다 ...는 설치를 중단하거나 원하는 setup.py
에있는 해당 패키지에서 모듈을 가져 오려고하면 ImportError
에서 중단됩니다.
$ python setup.py sdist
: 바퀴 설치에 setup.py
를 호출하지 않기 때문에 당신은 소스 타르와 같은 패키지를 배포해야 지금
from distutils.command.build import build as build_orig
from distutils.errors import DistutilsModuleError
from setuptools import setup
class build(build_orig):
def finalize_options(self):
try:
import numpy
except ImportError:
raise DistutilsModuleError('numpy is not installed. Installation will be aborted.')
super().finalize_options()
setup(
name='spam',
version='0.1',
author='nobody',
author_email='[email protected]',
packages=[],
install_requires=[
# all the other dependencies except numpy go here as usual
],
cmdclass={'build': build,},
)
: 예를 들어,의 설치가 numpy
입니다 중단해야 당신의 의존성을 가정 해 봅시다 내가 할 수있는
$ pip install dist/spam-0.1.tar.gz
Processing ./dist/spam-0.1.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/spam.egg-info
writing pip-egg-info/spam.egg-info/PKG-INFO
writing dependency_links to pip-egg-info/spam.egg-info/dependency_links.txt
writing top-level names to pip-egg-info/spam.egg-info/top_level.txt
writing manifest file 'pip-egg-info/spam.egg-info/SOURCES.txt'
reading manifest file 'pip-egg-info/spam.egg-info/SOURCES.txt'
error: numpy is not installed. Installation will be aborted.
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/_y/2qk6029j4c7bwv0ddk3p96r00000gn/T/pip-s8sqn20t-build/
참고 : numpy
가 발생합니다 누락 된 내장 된 타르를 설치하려고 설치 스크립트의 상단에 대한 수입 검사 :
from setuptools import setup
try:
import numpy
except ImportError:
raise DistutilsModuleError(...)
setup(...)
그러나이 경우
, 포맷되지 않습니다 출력과 전체 스택 추적도 기술과 사용자를 혼란스럽게 할 수있는 표준 출력에 유출 될 것이다. 대신 설치시 호출 될
distutils
명령 중 하나를 서브 클래스화하여 오류 출력의 형식이 올바로 지정되도록하십시오. 이제
, 두 번째 부분 :
... 또는 경고를 인쇄하고 제거 종속성을 계속합니다.
버전 7 pip will swallow any output from your setup script 이후 더 이상 가능하지 않습니다. pip가 상세 모드 (예 : pip install -v mypkg
)로 실행되는 경우에만 사용자는 설정 스크립트의 출력을 볼 수 있습니다. 네가 나 한테 물어 보면 의심스러운 결정이야.
from distutils.log import ERROR
class build(build_orig):
def finalize_options(self):
try:
import numpy
except ImportError:
# issue an error and proceed
self.announce('Houston, we have an error!', level=ERROR)
# for warnings, there is a shortcut method
self.warn('I am warning you!')
super().finalize_options()
'cmdclass'에 대한 모든 문서가 있는가 :
그럼에도 불구하고, 여기에서 설치 스크립트에 경고 및 오류를 발행하는 예입니다? 나는 그것을 발견 할 수 없다. – user2357112
@ user2357112 그것은 파이썬의 stdlib의 일부입니다. [Distutils 확장하기] (https://docs.python.org/3.6/distutils/extending.html)는 좋은 시작점입니다. – hoefling