Modularization - minnie0531/fastapi-template GitHub Wiki

Python modulation ํ•˜๋Š” ๋ฐฉ๋ฒ•

wheel ํŒŒ์ผ ๋งŒ๋“ค๊ธฐ

  1. ์‚ฌ์šฉํ•˜๋Š” packages

    pip install wheel
    pip install setuptools (๋Œ€์ฒด๋กœ ๊ธฐ๋ณธ์ ์œผ๋กœ ๊น”๋ ค ์žˆ๋Š” ๊ฒƒ ๊ฐ™์Œ)
    pip install twine
    
  2. ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ  ๊ทธ ์•ˆ์— ํ•„์š”๋กœ ํ•˜๋Š” ๋กœ์ง์„ ๊ตฌํ˜„ํ•จ.

  3. ํด๋”์˜ ์ƒ์œ„ ๋ ˆ๋ฒจ์—์„œ setup.py ์ž‘์„ฑ

from setuptools import setup, find_packages

setup(name='aaa_custom', # ํŒจํ‚ค์ง€ ๋ช…
version='1.0.0.0', #version
description='Test aaa module',
author='minnie',
author_email='[email protected]',
url='test.url.com',
license='MIT', # MIT์—์„œ ์ •ํ•œ ํ‘œ์ค€ ๋ผ์ด์„ผ์Šค ๋”ฐ๋ฅธ๋‹ค
py_modules=['aaa_helper'], # ํŒจํ‚ค์ง€์— ํฌํ•จ๋˜๋Š” ๋ชจ๋“ˆ
python_requires='>=3',
install_requires=['redis','pickle','os'], # ํŒจํ‚ค์ง€ ์‚ฌ์šฉ์„ ์œ„ํ•ด ํ•„์š”ํ•œ ์ถ”๊ฐ€ ์„ค์น˜ ํŒจํ‚ค์ง€
packages=['aaa_custom'] # ํŒจํ‚ค์ง€๊ฐ€ ๋“ค์–ด์žˆ๋Š” ํด๋”
)

  1. ๋‹ค์Œ command๋กœ build (pip install wheel ํ™•์ธ) python setup.py bdist_wheel
  2. whlํŒŒ์ผ ์ƒ์„ฑ ํ™•์ธ dist/testPackage-1.0.0.0-py3-none-any.whl

whlํŒŒ์ผ ์—…๋กœ๋“œ

  1. configuration ์„ค์ •
# Private pypi ์‚ฌ์šฉ์‹œ ~/.pypirc์— internal url์„ ์„ค์ •ํ•ด ์ค˜์•ผ ํ•จ. 
# ํ˜น์€ ๋ช…๋ น์–ด์— ์˜ต์…˜์œผ๋กœ internal url์„ค์ •

[distutils]
index-servers =internal
[internal]
repository: [http://localhost:8080](http://localhost:8080/)
username:yourusername
password:yourpassword
  1. Upload wheel ํŒŒ์ผ
  • Upload with twine twineย uploadย dist/testPackage-1.0.0.0-py3-none-any.whl
  • Upload with setuptools python setup.py sdist upload -r internal