Programming

setuptools 대 distutils : 왜 distutils가 여전히 중요한가?

procodes 2020. 7. 6. 21:47
반응형

setuptools 대 distutils : 왜 distutils가 여전히 중요한가?


파이썬 프로젝트를 패키징하고 설명하는 데 사용할 수있는 도구의 혼란 역사를 가지고 이러한 포함 distutils, 표준 라이브러리에서 distribute, distutils2그리고 setuptools(어쩌면 더). 것으로 보인다 distributedistutils2찬성 중단했다 setuptools있는 잎이 개 경쟁하는 표준.

내가 이해 setuptools하는 것보다 훨씬 더 많은 옵션 (예 : 종속성 선언, 테스트 등)을 제공 distutils하지만 Python 표준 라이브러리에는 포함되어 있지 않습니다 (아직?).

파이썬 포장 사용 설명서 [ 1 ] 지금 권장합니다

setuptools프로젝트를 정의하고 소스 분배를 작성하는 데 사용하십시오 .

그리고 설명 :

distutils많은 프로젝트에 순수 사용할 수 있지만 다른 프로젝트에 대한 종속성 정의를 지원하지 않으며에서 제공하는 패키지 메타 데이터를 올바르게 자동으로 채우기위한 몇 가지 편리한 유틸리티가 없습니다 setuptools. 표준 라이브러리 외부에있는 setuptools는 다른 버전의 Python에서보다 일관된 기능 세트를 제공하며 (와 달리 distutils) setuptools지원되는 모든 버전에서 곧 출시 될 "Metadata 2.0"표준 형식을 생성하도록 업데이트됩니다.

을 사용하기로 선택한 프로젝트의 경우에도 distutilspip는 사전 빌드 된 휠 파일에서 설치하지 않고 소스에서 직접 이러한 프로젝트를 설치할 때 실제로 setuptools대신 프로젝트를 사용하여 빌드합니다 .

그러나 다양한 프로젝트의 setup.py 파일을 살펴보면 이것이 실제 표준이 아닌 것으로 보입니다. 많은 패키지가 여전히 사용 중이며 distutils지원하는 패키지 는 폴백 가져 오기 등 을 통해 setuptools종종 혼합 setuptools됩니다 distutils.

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

모두 설치할 수있는 설치 작성하는 방법을 찾기위한 시도를 다음 setuptoolsdistutils. distutils설정 기능의 종속성을 지원하지 않기 때문에 여기에는 종종 다양한 오류 발생 종속성 검사 방법이 포함됩니다 .

왜 사람들은 여전히 지원하기위한 추가적인 노력을하고 있습니다 distutils- 한 사실 setuptools표준 라이브러리에있는 유일한 이유는 아니다는? 지원 만하는 setup.py 파일을 distutils작성할 때의 장점 과 단점이 있습니다.setuptools


이 SO 질문을 살펴보십시오. 모든 패키징 방법을 잘 설명하고 있으며 질문과 대답에 어느 정도 도움이 될 수 있습니다. 배포, distutils, setuptools 및 distutils2의 차이점?

Distutils 는 여전히 Python으로 패키징하기위한 표준 도구입니다. 표준 라이브러리 (Python 2 및 Python 3.0 ~ 3.3)에 포함되어 있습니다. 간단한 Python 배포에는 유용하지만 기능이 부족합니다. setup.py 스크립트에서 가져올 수있는 distutils Python 패키지를 소개합니다.

Setuptools 는 Distutils의 한계를 극복하기 위해 개발되었으며 표준 라이브러리에는 포함되어 있지 않습니다. easy_install이라는 명령 줄 유틸리티가 도입되었습니다. 또한 setup.py 스크립트로 가져올 수있는 setuptools Python 패키지와 코드로 가져 와서 배포와 함께 설치된 데이터 파일을 찾을 수있는 pkg_resources Python 패키지를 소개했습니다. 단점 중 하나는 distutils Python 패키지를 원숭이 패치한다는 것입니다. pip와 잘 작동합니다. 최신 버전은 2013 년 7 월에 릴리스되었습니다.

따라서 setuptools가 distutils보다 선호되어야하며 질문이 어디에서 나오는지 알지만 distutils는 곧 인기있는 일부 레거시 프로그램과 함께 많은 경우에 사용되므로 곧 지원을 잃지 않습니다. . 레거시 프로그램에서 이러한 종류의 변경은 상당히 고통스럽고 비 호환성과 같은 몇 가지 문제가 발생하여 개발자가 소스 코드를 다시 작성해야합니다. 따라서 distutils는 표준 python 라이브러리의 일부이지만 setuptools는 그렇지 않습니다. 따라서 오늘날과 같이 파이썬 프로그램을 작성하는 경우 setuptools를 사용하지만 distutils가 없으면 setuptools가 존재하지 않았 음을 명심하십시오.


setuptools가 표준 라이브러리에없는 유일한 이유입니다.

한 가지 이유가 있습니다. 다음은 NumPysetup.py 에서 나온 것입니다 .

if len(sys.argv) >= 2 and ('--help' in sys.argv[1:] or
        sys.argv[1] in ('--help-commands', 'egg_info', '--version',
                        'clean')):
    # Use setuptools for these commands (they don't work well or at all
    # with distutils).  For normal builds use distutils.
    try:
        from setuptools import setup
    except ImportError:
        from distutils.core import setup

따라서 NumPy는 setuptools그것을 찾을 수 있으면 선호 합니다. 그러나 SciPy 는 일부 상황에서 선호하도록 패치 될 때 까지이 작업을 수행했습니다 distutils. 커밋 로그 인용 :

Setuptools sets mode +x on the test scripts, so that Nose refuses to run
them. Better not do that.

물론, 합병 사이 setuptools와는 distribute때가되면 모든 것을 해결해야하지만, 많은 패키지는 여전히 파이썬 2.6 설치를 지원해야합니다.


setuptools가 의심 할 여지없이 더 나은 도구 세트 임에도 불구하고 여전히 distutils에 대해 이야기하고 사용하는 몇 가지 이유가 있습니다.

첫째, distutils는 어디에서나 사용할 수 있습니다. 다른 사람과 공유하기위한 모듈을 구축하려는 경우 복잡한 요구 사항이없는 경우 업무용 컴퓨터에서 사용할 수 있습니다. 이전 버전의 파이썬을 지원해야하거나 익숙하지 않은 환경에서 작업하는 경우 특히 중요합니다.

둘째, setuptools는 distutils를 향상시킵니다. 따라서 distutils 도구 세트를 모델로하여 모든 구조를 가져옵니다. setuptools 설명서는 독자가 distutils에 익숙하다고 가정하고 기본 도구 세트를 향상시키는 방법 만 문서화합니다. distutils가 방언을 정의하고 setuptools가 해당 방언을 향상 시킨다고 생각할 수 있습니다.

My personal approach for new projects is start with the assumption I'm going to use distutils. Only as the project grows to require a feature of setuptools do I make the upgrade. The setuptools is a drop-in-replacement for distutils, it's a one-line change to my setup.py.


Basically, it's due to the division of responsibilities.

setuptools is not a part of Python standard library because it's maintained by a 3rd party rather than Python core team. Which means, among other things:

  • it isn't covered by the core test suite and isn't relied upon by core functionality
  • it doesn't itself set core standards for add-on modules (their location, means of import, C extensions' binary interface etc.).
  • it's updated and released independently from Python releases

Effectively, the core team has narrowed down the scope of distutils, reserving the "core standards" and "minimal necessary compilation" parts for themselves while leaving all the stuff beyond that (extended compiler/package format/whatever support) to 3rd parties. The code that was previously covering those "extended parts" was left stale for backwards compatibility.

From Distributing Python Modules — Python 2.7.12 documentation:

While direct use of distutils is being phased out, it still laid the foundation for the current packaging and distribution infrastructure, and it not only remains part of the standard library, but its name lives on in other ways (such as the name of the mailing list used to coordinate Python packaging standards development).

Packages for other OSes are likewise likely to provide setuptools and pip separately - for the aforementioned reasons

  • and because they aren't necessary - or are even detrimental for maintainability - when there's already another package manager on the system.

참고URL : https://stackoverflow.com/questions/25337706/setuptools-vs-distutils-why-is-distutils-still-a-thing

반응형