msaltnet / smtm

It's a game to get money
https://smtm.msalt.net
MIT License
91 stars 96 forks source link

좋은 파이썬 프로젝트 디렉토리 구조란? #12

Closed msaltnet closed 3 years ago

msaltnet commented 3 years ago

잘 정리되어 있어야 마음이 편함

msaltnet commented 3 years ago

프로젝트 구조에 대해서

https://trowind.tistory.com/105

setup.py

setup.py는 파이썬 프로젝트와 관련된 설정 정보가 들어있다. 두가지 중요한 역할을 하는데, 우선 프로젝트에 필요한 패키지들을 설치할 때 사용할 수 있다.

우선 setup.py에서 사용하고 있는 setuptools 패키지를 설치해 준다.

pip install setuptools
python setup.py install

이런식으로 setup 파일 자체를 실행시켜서 관련된 패키지를 설치할 수 있다. 사실 setup.py 안에는 관련 정보만있지 자동으로 설치하도록 프로그래밍되어 있지는 않다. 그 역할은 setup.py에서 사용하고있는 setuptools 또는 distutils 패키지에서 담당한다. 이를 위해 setup.py를 실행하기 전에는 사용하고 있는 패키지를 설치해야 하는 것이다.

distutils는 파이썬 표준 라이브러리이고, setuptools는 좀 더 다양한 기능을 추가한 외부 라이브러리이다.

setup.py의 또 다른 역할은 패키지를 배포하기 위한 정보를 담고 있는 것이다. wheel이라는 패키지를 설치하여 내가 만든 패키지를 .whl 파일로 만들어서 배포할 수있다.

pip install wheel

패키지를 빌드할 때는 아래 명령어를 사용한다.

python setup.py bdist_wheel

wheel 파일은 파이썬을 위한 빌드 패키지를 뜻한다. 2012년에 Format 1.0에 대한 PEP-427가 생성되었다. zip으로 압축되어있고, 설치는 site-packages에 압축을 풀어서 저장되는 과정이다.

This PEP describes a built-package format for Python called "wheel". A wheel is a ZIP-format archive with a specially formatted file name and the .whl extension. It contains a single distribution nearly as it would be installed according to PEP 376 with a particular installation scheme. Although a specialized installer is recommended, a wheel file may be installed by simply unpacking into site-packages with the standard 'unzip' tool while preserving enough information to spread its contents out onto their final paths at any later time.

https://www.python.org/dev/peps/pep-0427/

이렇게 생성한 패키지는 tween 이라는 패키지를 이용해서 pypi.org의 Python Package Index에 업로드, 등록이 가능하다. 성공적으로 등록된 후로는 여느 패키지와 같이 pip install로 설치할 수 있다.

프로젝트 패키지 https://rampart81.github.io/post/python_package_publish/