Publikowanie pakietu

Tworzenie pakietów w Pythonie

James Fulton

Climate informatics researcher

PyPI

Python Package Index

  • pip instaluje stąd pakiety
  • Każdy może przesyłać pakiety
  • Warto opublikować pakiet, gdy tylko może być użyteczny
1 https://pypi.org/
Tworzenie pakietów w Pythonie

Dystrybucje

  • Pakiet dystrybucyjny – spakowana wersja pakietu gotowa do instalacji.
  • Dystrybucja źródłowa – pakiet dystrybucyjny zawierający głównie kod źródłowy.
  • Dystrybucja wheel – pakiet dystrybucyjny przetworzony w celu przyspieszenia instalacji.
Tworzenie pakietów w Pythonie

Jak budować dystrybucje

python setup.py sdist bdist_wheel

  • sdist = dystrybucja źródłowa
  • bdist_wheel = dystrybucja wheel
mysklearn/
|-- mysklearn
|-- setup.py
|-- requirements.txt
|-- LICENSE
|-- README.md

|-- dist <---
| |-- mysklearn-0.1.0-py3-none-any.whl
| |-- mysklearn-0.1.0.tar.gz
|-- build |-- mysklearn.egg-info
Tworzenie pakietów w Pythonie

Jak udostępnić swój pakiet

Prześlij dystrybucje do PyPI

twine upload dist/*

Prześlij dystrybucje do TestPyPI

twine upload -r testpypi dist/*
mysklearn/
|-- mysklearn
|-- setup.py
|-- requirements.txt
|-- LICENSE
|-- README.md
|-- dist
|   |-- mysklearn-0.1.0-py3-none-any.whl
|   |-- mysklearn-0.1.0.tar.gz
|-- build
|-- mysklearn.egg-info
Tworzenie pakietów w Pythonie

Jak inni mogą zainstalować Twój pakiet

Instalacja pakietu z PyPI

pip install mysklearn

Instalacja pakietu z TestPyPI

pip install --index-url         https://test.pypi.org/simple 
            --extra-index-url   https://pypi.org/simple
            mysklearn
Tworzenie pakietów w Pythonie

Czas na ćwiczenia!

Tworzenie pakietów w Pythonie

Preparing Video For Download...