SlideShare a Scribd company logo
1 of 56
Download to read offline
Python Packaging
And Debian Packaging
2018.04.24
Infrastructure Development Team. 심경섭
목차
I. 개요
II. Python 패키지 기반 지식
III. Python 패키징
IV. Debian 에서 Python 패키지
V. 소소한 몇가지
VI. QnA
개요
개요
• Python 패키지에 필요한 기반 지식 습득
• Python 으로 패키지를 만드는 방법 확인
• 만들어진 Python 패키지를 Debian 패키지로 변환 절차 확인
Python 패키징 툴
• distutils, setuptools, scikit-build 가 지원됨
• distribute, distutils2 는 사용되지 않음
distutils
• Python 의 표준 패키징 툴
• 간단한 패키지를 만들기에 적합
• 부족한 기능들이 있음
setuptools
• distutils 의 부족한 기능을 보완하기 위해 나옴 (distutils 기반)
• Python 에서 일반적으로 많이 사용
• 표준 라이브러리는 아님
• CLI 유틸로 “easy_install” 이 있음
scikit-build
• CPython 의 C 확장을 위한 향상된 빌드 시스템
• 내부적으로 CMake 를 사용
• distutils 를 기반으로 하지않음
• 패키지 빌드 속도가 빠름
Python 패키지 기반 지식
디렉토리 구조
• 패키지 디렉토리, 테스트 디렉토리, setup.py, 등으로 구성
• [패키지 디렉토리] : 패키지를 담고 있음
• [tests] : 패키지 디렉토리 안의 코드에 대한 test 를 담고 있음
• [setup.py] : 패키지에 설치에 관한 정보를 담고 있음
디렉토리 구조
패키지, 모듈
• 디렉토리로 구분되어 ”__init__.py” 를 포함하고 있으면 패키지
• Python 3.3 이후에는 디렉토리가 없어도 패키지로 인식 [PEP 420]
• 패키지 디렉토리 안의 각각의 ”.py” 은 모듈
패키지, 모듈
• “from [패키지 이름] import [모듈 이름]” 형태로 import 를 사용
• “from parser import utils” 로 사용
__init__.py
• 외부에서 패키지를 참조할때 가장 먼저 실행됨
• 일반적으로 패키지안에서 공용으로 사용하는 전역 설정을 정의
Python 패키징
Python 패키징 (setuptools)
• setup.py 파일 작성
• setup.py 내부의 import 패키지를 setuptools 로 설정
• 필요에 따라 requirements.txt 파일 작성
setup.py
• 패키지에서 필요한 내용을 명세한 파일
• 필수적으로 작성하는 항목과 선택인 항목이 있음
• https://github.com/pypa/sampleproject/blob/master/setup.py
setup.py
requirements.txt
• 설치할 Python 패키지의 의존성을 명시해 놓은 파일
setup.py(install_requires) vs requirements.txt
setup.py(install_requires) vs requirements.txt
• setup.py(install_requires) 는 Abstract.
• requirements.txt 는 Concrete.
setup.py(install_requires)
• Abstract
• 패키지 명과 버전을 명시할 수 있음
• 명시된 이름과 같은 패키지가 설치되어있기만 하면 됨
requirements.txt
• Concreate
• 패키지 명과 버전을 명시할 수 있음
• 패키지의 출처를 명시해주는 부분이 포함되어있음
• 명시된 출처에서 받아온 패키지가 설치되어야 함
requirements.txt
• 패키지의 출처 명시
• 기본 서버 (https://pypi.python.org/simple/)
의존성 구분
• setup.py 의 내용과 requirements.txt 의 동기화
• -e 옵션을 사용해 동기화를 할 수 있음
• 또, -e 옵션을 사용해 특정 패키지의 저장소를 변경할 수 있음
• 의존성을 구분하면, 저장소를 미러링하거나 사설로 구축이 가능
의존성 구분
Debian 에서 Python 패키지
개요
• Python 2.6 이상부터 지원
• setup.py 파일이 있어야함 (setuptools / distribute 기반)
• virtualenv 에서 특별한 수정 없이 동작해야함
• debhelper (v8 이상부터 Python3 도 지원)
개요
• pybuild 시스템 사용
• Python2, Python3, PyPy 지원
• nose/pytest/tox 지원
• 커스터마이징 가능한 다양한 환경 변수 지원
control 파일 (source)
• Build-Depends 에 아래 내용 추가
• debhelper, dh-python, python2-all, python2-setuptools
• Python3 를 지원한다면, 아래 내용을 추가
• python3-all, python3-setuptools
• Documentation 을 지원한다면, 아래 내용을 추가
• python-docutils, python-sphinx
control 파일 (package)
• Depends 에 아래 내용 추가
• ${python:Depends}
• Python3 를 지원한다면, 아래 내용을 추가
• ${python3:Depends}
• Documentation 패키지에는 아래 내용 추가
• ${sphinxdoc:Depends}
rules 파일
• PYBUILD_NAME 환경 변수 설정
• export PYBUILD_NAME=[패키지 명]
• dh 파라미터로 --with 와 --buildsystem 설정
• dh $@ --with python3 --buildsystem=pybuild
• dh $@ --with python2,python3 --buildsystem=pybuild
• documentation 을 사용시 아래 내용 추가
• --with sphinxdoc
control 파일
rules 파일
[패키지명]
빌드
[패키지명]
[경로]
빌드
[패키지명]
[패키지 경로]
[경로]
[패키지명]
빌드
[패키지명]
[패키지 경로]
[패키지 경로]
빌드
[경로]
[패키지명]
[패키지명]
소소한 몇가지
소소한 몇가지
• pip vs easy_install
• Wheel vs Egg
• Debian Package in Wheel
• stdeb
pip vs easy_install
• easy_install 은 2004 년 setuptools 의 일부로 공개됨
• pip 는 2008 년 easy_install 의 대체제로 나타남
• Wheel 과 Eggs 의 지원 여부가 가장 큼
pip vs easy_install
Wheel vs Egg
• 둘 다 Python 의 패키지 형식임
• Egg 는 2004 년 setuptools 에서 소개됨
• Wheel 은 2012 년 PEP 427 에서 소개됨
• Wheel 은 현재 Python 공식 패키지 형식으로 논의중
Wheel vs Egg
• Wheel 은 배포의 형식, Egg 는 배포와 런타임 설치의 형식
• Wheel 은 배포시 pyc 파일이 포함되지 않음
• Wheel 은 다양한 파일 명명 규칙을 가지고 있음
• PEP 425
• Python 버전, ABI, 시스템 아키텍쳐의 호환성등을 표시
Wheel vs Egg
• Wheel 은 .dist-info 디렉토리를 사용
• PEP 376
• Egg 는 .egg-info 파일을 사용
• PEP 314
Wheel vs Egg
• Wheel 은 다음과 같이 빌드
• python setup.py bdist_wheel
• Egg 는 다음과 같이 빌드
• python setup.py bdist_egg
Egg
[경로]
[패키지명]
[경로]
[경로]
[패키지명]
[패키지명]
[패키지명]
Egg
[패키지명] [패키지명]
[패키지명]
[패키지명]
[패키지명]
Wheel
[패키지명]
[패키지명]
[패키지명]
[패키지명]
[패키지명]
[패키지명]
[패키지명]
Wheel
[패키지명] [패키지명] [패키지명]
[패키지명]
[패키지명]
[패키지명]
Debian Package in Wheel
• Debian 패키지에서 특정 경우를 제외하곤 Wheel 을 제공하면 안됨
• Wheel 은 Debian 사용자가 Python 라이브러리를 쓰기에 복잡함
• 배포판 기반의 패키징 도구에서 이점이 없음
• 사용하기에 편리하지 않음
• Debian 정책을 준수하는 내에서 아래의 경우에만 일부 기능 제공
• pip, virtualenv, pyvenv 를 지원하기 위해 사용되는 경우
Debian Package in Wheel
• Wheel 을 지원해야하는 경우, 의존성으로 dirtbike 를 사용
• Wheel 을 변형한 패키지
• Debian 패키지를 Wheel 로 변형해줌
• ”/usr/share/python-wheels” 에 파일이 설치됨
stdeb
• Python code 를 Debian source package 로 변경해주는 툴
• 자동으로 debian 패키지를 만들어줌
QnA
참고자료
• https://packaging.python.org/
• https://stackoverflow.com/a/14753678/8151723
• https://packaging.python.org/discussions/
• https://caremad.io/posts/2013/07/setup-vs-requirement/
• https://devguide.python.org/
• https://wiki.debian.org/Python/LibraryStyleGuide
• https://wiki.debian.org/Python/Pybuild
KOREA
U.S.A.
JAPAN
Yeouido, Seoul www.pentasecurity.co.kr (HQ)
Houston, Texas www.pentasecurity.com
Shinjuku-Ku, Tokyo www.pentasecurity.co.jp
Copyright 2017 Penta Security Systems Inc. All rights reserved.

More Related Content

Similar to Python Packaging & Debian Packaging

Python 생태계의 이해
Python 생태계의 이해Python 생태계의 이해
Python 생태계의 이해용 최
 
파이썬을 활용한 금융 분석 Ch 9. Input Output Operation
파이썬을 활용한 금융 분석 Ch 9. Input Output Operation파이썬을 활용한 금융 분석 Ch 9. Input Output Operation
파이썬을 활용한 금융 분석 Ch 9. Input Output Operation찬희 이
 
2022.08 멘토링 자료.pptx
2022.08 멘토링 자료.pptx2022.08 멘토링 자료.pptx
2022.08 멘토링 자료.pptxssuserf875e6
 
20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍
20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍
20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍ymtech
 
코드로 인프라 관리하기 - 자동화 툴 소개
코드로 인프라 관리하기 - 자동화 툴 소개코드로 인프라 관리하기 - 자동화 툴 소개
코드로 인프라 관리하기 - 자동화 툴 소개태준 문
 
Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션Dabi Ahn
 
Git basic2 chaos
Git basic2 chaosGit basic2 chaos
Git basic2 chaosYunkyu Choi
 
Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기
Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기
Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기Joongi Kim
 
JBoss EAP on Azure
JBoss EAP on Azure JBoss EAP on Azure
JBoss EAP on Azure rockplace
 
[231]나는서버를썰터이니너는개발만하여라 양지욱
[231]나는서버를썰터이니너는개발만하여라 양지욱[231]나는서버를썰터이니너는개발만하여라 양지욱
[231]나는서버를썰터이니너는개발만하여라 양지욱NAVER D2
 
메이븐파헤치기(김우용)
메이븐파헤치기(김우용)메이븐파헤치기(김우용)
메이븐파헤치기(김우용)우용 김
 
Gradle & IntelliJ & Vert.x
Gradle & IntelliJ & Vert.xGradle & IntelliJ & Vert.x
Gradle & IntelliJ & Vert.xKwnaghwan Cho
 
Android Security Internals (Lesson 3)
Android Security Internals (Lesson 3)Android Security Internals (Lesson 3)
Android Security Internals (Lesson 3)Joon Young Park
 
JBoss EAP on Azure Workshop
JBoss EAP on Azure Workshop JBoss EAP on Azure Workshop
JBoss EAP on Azure Workshop rockplace
 
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축Atlassian cloud 제품을 이용한 DevOps 프로세스 구축
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축SooHyunsuPark
 
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket Cloud
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket CloudAtlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket Cloud
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket CloudOpen Source Consulting
 

Similar to Python Packaging & Debian Packaging (20)

Python 생태계의 이해
Python 생태계의 이해Python 생태계의 이해
Python 생태계의 이해
 
파이썬을 활용한 금융 분석 Ch 9. Input Output Operation
파이썬을 활용한 금융 분석 Ch 9. Input Output Operation파이썬을 활용한 금융 분석 Ch 9. Input Output Operation
파이썬을 활용한 금융 분석 Ch 9. Input Output Operation
 
2022.08 멘토링 자료.pptx
2022.08 멘토링 자료.pptx2022.08 멘토링 자료.pptx
2022.08 멘토링 자료.pptx
 
20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍
20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍
20170310 tech day-1st-maven을 이용한 프로그램 빌드-박준홍
 
코드로 인프라 관리하기 - 자동화 툴 소개
코드로 인프라 관리하기 - 자동화 툴 소개코드로 인프라 관리하기 - 자동화 툴 소개
코드로 인프라 관리하기 - 자동화 툴 소개
 
Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션Git 기본개념과 사용법 그리고 어플리케이션
Git 기본개념과 사용법 그리고 어플리케이션
 
Git basic2 chaos
Git basic2 chaosGit basic2 chaos
Git basic2 chaos
 
JetsonTX2 Python
 JetsonTX2 Python  JetsonTX2 Python
JetsonTX2 Python
 
Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기
Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기
Python Korea 2014년 6월 세미나 - Windows 환경에서 Python 개발환경 세팅하기
 
JBoss EAP on Azure
JBoss EAP on Azure JBoss EAP on Azure
JBoss EAP on Azure
 
[231]나는서버를썰터이니너는개발만하여라 양지욱
[231]나는서버를썰터이니너는개발만하여라 양지욱[231]나는서버를썰터이니너는개발만하여라 양지욱
[231]나는서버를썰터이니너는개발만하여라 양지욱
 
메이븐파헤치기(김우용)
메이븐파헤치기(김우용)메이븐파헤치기(김우용)
메이븐파헤치기(김우용)
 
Git
Git Git
Git
 
Gradle & IntelliJ & Vert.x
Gradle & IntelliJ & Vert.xGradle & IntelliJ & Vert.x
Gradle & IntelliJ & Vert.x
 
Android Security Internals (Lesson 3)
Android Security Internals (Lesson 3)Android Security Internals (Lesson 3)
Android Security Internals (Lesson 3)
 
18 1 파이썬패키지
18 1 파이썬패키지18 1 파이썬패키지
18 1 파이썬패키지
 
JBoss EAP on Azure Workshop
JBoss EAP on Azure Workshop JBoss EAP on Azure Workshop
JBoss EAP on Azure Workshop
 
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축Atlassian cloud 제품을 이용한 DevOps 프로세스 구축
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축
 
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket Cloud
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket CloudAtlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket Cloud
Atlassian cloud 제품을 이용한 DevOps 프로세스 구축: Jira Cloud, Bitbucket Cloud
 
DevOps Study
DevOps StudyDevOps Study
DevOps Study
 

More from 경섭 심

More Effective Python 3st (Multitask)
More Effective Python 3st (Multitask)More Effective Python 3st (Multitask)
More Effective Python 3st (Multitask)경섭 심
 
Main Variable Program
Main Variable ProgramMain Variable Program
Main Variable Program경섭 심
 
Python comparing
Python comparingPython comparing
Python comparing경섭 심
 
Python coroutine
Python coroutinePython coroutine
Python coroutine경섭 심
 
Effective Python 2st (Decorator & Generator)
Effective Python 2st (Decorator & Generator)Effective Python 2st (Decorator & Generator)
Effective Python 2st (Decorator & Generator)경섭 심
 
Effective Python 1st (Test & Style)
Effective Python 1st (Test & Style)Effective Python 1st (Test & Style)
Effective Python 1st (Test & Style)경섭 심
 

More from 경섭 심 (6)

More Effective Python 3st (Multitask)
More Effective Python 3st (Multitask)More Effective Python 3st (Multitask)
More Effective Python 3st (Multitask)
 
Main Variable Program
Main Variable ProgramMain Variable Program
Main Variable Program
 
Python comparing
Python comparingPython comparing
Python comparing
 
Python coroutine
Python coroutinePython coroutine
Python coroutine
 
Effective Python 2st (Decorator & Generator)
Effective Python 2st (Decorator & Generator)Effective Python 2st (Decorator & Generator)
Effective Python 2st (Decorator & Generator)
 
Effective Python 1st (Test & Style)
Effective Python 1st (Test & Style)Effective Python 1st (Test & Style)
Effective Python 1st (Test & Style)
 

Python Packaging & Debian Packaging