Зробіть свій пакет портативним

Принципи Software Engineering у Python

Adam Spannbauer

Machine Learning Engineer at Eastman

Кроки до портативності

файл setup.py

файл requirements.txt

Принципи Software Engineering у Python

Портативна структура пакета

Структура пакета

Принципи Software Engineering у Python

Вміст requirements.txt

працюємо у work_dir/requirements.txt

# Needed packages/versions
matplotlib
numpy==1.15.4
pycodestyle>=2.4.0

працюємо з terminal

datacamp@server:~$ pip install -r requirements.txt
Принципи Software Engineering у Python

Вміст setup.py

from setuptools import setup

setup(name='my_package',
      version='0.0.1',
      description='An example package for DataCamp.',
      author='Adam Spannbauer',
      author_email='[email protected]',
      packages=['my_package'],
      install_requires=['matplotlib',
                        'numpy==1.15.4',
                        'pycodestyle>=2.4.0'])
Принципи Software Engineering у Python

install_requires vs requirements.txt

працюємо уwork_dir/requirements.txt

# Specify where to install requirements from
--index-url https://pypi.python.org/simple/

# Needed packages/versions
matplotlib
numpy==1.15.4
pycodestyle>=2.4.0

Документація: install_requires vs requirements files

Принципи Software Engineering у Python

Встановлення пакета через pip

datacamp@server:~/work_dir $ pip install .
Building wheels for collected packages: my-package
  Running setup.py bdist_wheel for my-package ... done
Successfully built my-package
Installing collected packages: my-package
Successfully installed my-package-0.0.1
Принципи Software Engineering у Python

Давайте потренуємось!

Принципи Software Engineering у Python

Preparing Video For Download...