ã¯ããã«
æããã¾ãã ãnikkieã§ãã
ããªã·ã¿ã§ã¯ã¨ããªã¼ã¡ãããã¤ããªã·ã®nikkieã§ããï¼ç§æSHSã¨ããªã¼ãå¯æãï¼ï¼ã
Pythonã§ã¯æè¿pyproject.tomlãç±ãã§ãã
ç§ããã®ãã¡ã¤ã«ã®ä¾¿å©ãã«æ°ã¥ããã®ã¯ããããæè¿ãªã®ã§ãããsetup.pyã使ã£ã¦ããæ¹ï¼ï¼éå»ã®èªåï¼åãã«ãããããªä¾¿å©ãªãã¡ã¤ã«ããããã ãï¼ãã¨ãªã¹ã¹ã¡ãã¦ããã¾ãã
ç®æ¬¡
- ã¯ããã«
- ç®æ¬¡
- pyproject.tomlããªã¹ã¹ã¡ãããèæ¯
- ããããããã®ãPythonã§èªåã ãã®ã¯ã½ã©ã¤ãã©ãªãä½ãæ¹æ³ããpyproject.tomlã§å®è£ ãã
- ããããã ããpyproject.tomlï¼
- çµããã«
pyproject.tomlããªã¹ã¹ã¡ãããèæ¯
ä¸ã¯ã¾ãã«å¤§LLMæ代ã
ChatGPTã®APIã使ã£ã¦Pythonã§ã©ã¤ãã©ãªãèªä½ããä¾ãé »ç¹ã«ç®ã«ãã¾ãã
- Pythonで作ったCLIツールをGitHubから直接pipでinstallできるようにする方法 - $shibayu36->blog; ðð
- GitHubのEventAPIとChatGPTを使って「この人最近何しているの?」が分かるコマンドを作った - notebook ðð
ãããã¯ã©ãã課é¡ã解決ãã¦ãã¦ãããã«ããããä»ã®äººãå©ç¨ã§ãã¦ãç´ æ´ãããã¨æãã¾ãï¼
ä¸æ¹ãé常ã«ç´°ããç¹ã§ãããç§ã«ã¯æ°ã«ãªããã¨ãããã¾ããã
ãããsetup.pyã®å©ç¨ã§ãã
èªä½ã©ã¤ãã©ãªãGitHubããã¤ã³ã¹ãã¼ã«ã§ããããã«ããããã«setup.pyãæ¸ããã¦ãã¾ãã
Pythonã®ããã±ã¼ã¸ã³ã°ã«é¢ããã©ã¤ãã©ãªsetuptoolsã®ããã¥ã¡ã³ãã«ã¯ä»¥ä¸ã®æãããã¾ã1
New projects are advised to avoid setup.py configurations (beyond the minimal stub) when custom scripting during the build is not necessary.
æ訳 ãã«ãã®éã«å®è¡ãããã«ã¹ã¿ã ã¹ã¯ãªãããå¿ è¦ã§ãªãã¨ããæ°ããããã¸ã§ã¯ãã«ã¯ï¼æå°ã®ã¹ã¿ããè¶ããï¼setup.pyã使ã£ãè¨å®ãé¿ãããã¨ãå¼·ãå§ãã¾ã
nikkieã®èªèï¼2023å¹´æç¹ï¼
- æ£ç´æåã¯ãpyproject.tomlãä½ã便å©ãªã®ï¼ãã¨æã£ã¦ããï¼ãã¾ããã£ã...ï¼
- Poetryã¨ãPipenvã¨ãã¨ä¸ç·ã«ä½¿ãï¼ å¦ç¿ã³ã¹ãé«ãã...
- ä¸è¨ã®ä¸æããã£ããã§ãããããã¦Pythonã³ãã¥ããã£çã«ã¯setup.pyããpyproject.tomlã¸ä¹ãæããé²ãã§ããï¼ï¼ã
- ãçéã®æ¨æºããåãæ®ããã¦ãããããã¨ããå±æ§ãæ±ã
- å®é使ã£ã¦ã¿ã2ã¨ããããã¯ãããã®ãããããªããã¨æãå§ãã
- dependencies, optional-dependenciesãªã©ãããã¤ãã®è¨å®é ç®ã¯setup.pyããã¯ããã«åããããã
- setup.pyã使ã£ã¦ããæ¹ã ããã²ãã²pyproject.tomlã使ã£ã¦ã¿ã¦ãã ãããã¨ããæ°æã¡
setuptoolsã®ããã¥ã¡ã³ãã«ã¯setup.pyã¨pyproject.tomlã®è¨å®ä¾ãä½µè¨ããã¦ãã3ãé常ã«åèã«ãªãã¾ããã
ããããããã®ãPythonã§èªåã ãã®ã¯ã½ã©ã¤ãã©ãªãä½ãæ¹æ³ããpyproject.tomlã§å®è£ ãã
ã°ã¼ãï¼
pip install git+https://github.com/ftnext/unko
>>> import unko
>>> unko.deru()
puripuri
pyproject.tomlä¸æ©ç®
å·®åã¯pyproject.tomlã ããããã¦ãã®å 容ã¯ä»¥ä¸ã ãã§ãã
[project] name = "unko" version = "0.1"
projectãã¼ãã«ã«nameã¨versionã ãå®ç¾©ããã°ãsetup.pyã¨åãå½¹å²ãæãããæå°éã®pyproject.tomlã¨ãªãã¾ãã
ãã®2ã¤ã®è¨å®ã¯ãsetup.pyã®nameå¼æ°ã¨versionå¼æ°ã«ç¸å½ãã¾ãã
# ref: https://github.com/karaage0703/unko/blob/248a7246c383df32119b1cb70976c3a641595553/setup.py from setuptools import setup, find_packages setup( name='unko', version='0.1', packages=find_packages() )
setup.pyã«ãã£ãpackages
å¼æ°ç¸å½ã®ãã®ã¯ã©ãã«ãã£ãã®ã ããã¨æãããããããã¾ãããã
ãããï¼ãã®ã¯ã½ã©ã¤ãã©ãªã»ã©åç´ãªæ§æãªãï¼ãããªãã¿ãããªãã§ããã
https://setuptools.pypa.io/en/latest/userguide/quickstart.html#package-discovery
Starting with version 61.0.0, setuptoolsâ automatic discovery capabilities have been improved to detect popular project layouts (such as the flat-layout and src-layout) without requiring any special configuration.
ããç¨ããããããã¸ã§ã¯ãã®ã¬ã¤ã¢ã¦ãã¯ï¼setuptoolsãï¼æ¤åºãã¦ããããããªã®ã§ãã
ãã®ãããã¯ä»¥ä¸ãªã©ãèªãã§ç解ãæ·±ãã¦ããããï¼
ããããã ããpyproject.tomlï¼
è¨å®ä¾
projectãã¼ãã«ã«ã©ããªè¨å®é ç®ããããã¯æ¥æ¬èªã§èªãã以ä¸ããªã¹ã¹ã¡ï¼ï¼ç¿»è¨³ã«æè¬ï¼
ç§ã¯ããã®ããã¥ã¡ã³ãã®ãä¾ããåèã«ãã¦ãã¾ãã
ï¼ä»ã«ã¯ç¥ãããã©ã¤ãã©ãªã®ãªãã¸ããªã®è¨å®å¤ããã¯ãã¨ãã§ããï¼
ããã¸ã§ã¯ãã®è¨å®ã ãã§ãªããéçºã«ä½¿ããã¼ã«ã®è¨å®ãæ¸ããï¼
ãããæ¬å½ã«ãããã¨æãã¦ãã¾ãã
éçºã§ä½¿ãblackãpytestãmypyãªã©ãªã©ããããã®ãã¼ã«ã¯pyproject.tomlã§ï¼ãï¼configureã§ããã®ã§ãï¼
æè¿ã®ç§ã¯taskipyã使ã£ã¦ãã¾ãï¼[tool.taskipy.tasks]
ï¼ã
taskipyã§ã³ãã³ããã¾ã¨ããããããåãã¼ã«ã®è¨å®ãè¨è¼ã§ãããããçãã¨ããã«æãå±ã1ãã¡ã¤ã«ã ãªããã¨æãã¦ãã¾ã
çµããã«
setup.pyã使ã£ã¦ããéå»ã®èªååãã«ãpyproject.tomlã®ã¹ã¹ã¡ã綴ãã¾ããã
- Pythonã§èªä½ã©ã¤ãã©ãªãä½ãã¨ãã«setup.pyã¨ããä¾ãè¦ããã
- æ¦é£ãããã ãã®è©±ãå®ã¯pyproject.tomlã¨ãã便å©ãªãã¡ã¤ã«ããããã§ããï¼
- å¦ç¿ã³ã¹ããé«ãã¨æããããããã¾ãããããã setup.pyããè¨å®é
ç®åãåãããããã¨ããç¹ã¯å¤§ããã¨æãã¾ãð¤
- åèï¼æ¥æ¬èªï¼ https://packaging.python.org/ja/latest/specifications/declaring-project-metadata/#example
- åèï¼è±èªï¼ https://setuptools.pypa.io/en/latest/userguide/quickstart.html
- projectãè¨å®ããªãã§ãéçºã§ä½¿ããã¼ã«ã®è¨å®ãæ¸ãã ãã§å°å ¥ãããã¨ãã§ãã¾ãï¼4ï¼ã¨ã«ãã仲è¯ããªããï¼ï¼
èªä½ã©ã¤ãã©ãªãä½ãã¨ãã«ãã¡ãã£ã¨ã ãè伸ã³ãã¦pyproject.tomlã使ã£ã¦ã¿ãã£ããªãã¨ããæ¹ãããã£ããã£ããã¨ã¦ãå¬ããã§ãã
ã©ãã©ã使ãããpyproject.tomlï¼
pyproject.tomlã®PEPãããã¤ãããããã§ãèªãã§ãã£ã¦åãã£ããã¨ããã£ãããå¥è¨äºã«ã¢ã¦ãããããã¦ããã¾ãã
- https://setuptools.pypa.io/en/latest/userguide/quickstart.html#setup-py↩
-
ãç¥
pyproject.toml
ããã¥ã¼ ã ↩ - setup.pyã®è¨å®ãéãããsetup.cfgã®ä¾ãä½µè¨ããã¦ãã¾ãï¼3éãè¦ãããï¼ï¼↩
- ↩