テンプレートでパッケージ開発を高速化

Pythonパッケージ開発

James Fulton

Climate informatics researcher

テンプレート

  • Python パッケージには多数の付随ファイルがあります
  • 覚えることが多い
  • テンプレートで多くが自動化されます

パッケージのファイル構成

.
|-- example_package
|   |-- __init__.py
|   `-- example_package.py
|-- tests
|   |-- __init__.py
|   `-- test_example_package.py
|-- README.rst     <-
|-- LICENSE        <-- 追加の
|-- MANIFEST.in    <-- 多数の
|-- tox.ini        <-- ファイル
|-- setup.py       <-- あり
`-- setup.cfg      <--
Pythonパッケージ開発

cookiecutter

  • 空の Python パッケージを作成可能
  • 必要な付随ファイル一式を生成

パッケージのファイル構成

.
|-- example_package
|   |-- __init__.py
|   `-- example_package.py
|-- tests
|   |-- __init__.py
|   `-- test_example_package.py
|-- README.rst
|-- LICENSE
|-- MANIFEST.in
|-- tox.ini
|-- setup.py
`-- setup.cfg
Pythonパッケージ開発

cookiecutter を使う

cookiecutter <template-url>
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
full_name [Audrey Roy Greenfeld]:
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
full_name [Audrey Roy Greenfeld]: James Fulton




  • 氏名を入力し、Enter/Return を押します
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
full_name [Audrey Roy Greenfeld]: James Fulton

email [[email protected]]: [email protected] github_username [audreyr]: MyUsername
project_name [Python Boilerplate]: mysklearn project_slug [mysklearn]: mysklearn
  • Project slug - pip install name で使う name
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
...
project_short_description [Python Boilerplate ...]: A Python package for linear 
    regression.

pypi_username [MyUsername]: version [0.1.0]:
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
...
use_pytest [n]: y
use_pypi_deployment_with_travis [y]: n
add_pyup_badge [n]: n
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
...
Select command_line_interface:
1 - Click
2 - Argparse
3 - No command-line interface
Choose from 1, 2, 3 [1]: 3

create_author_file [y]: y
Pythonパッケージ開発

cookiecutter を使う

cookiecutter https://github.com/audreyr/cookiecutter-pypackage
...
Select open_source_license:
1 - MIT license
2 - BSD license
3 - ISC license
4 - Apache Software License 2.0
5 - GNU General Public License v3
6 - Not open source
Choose from 1, 2, 3, 4, 5, 6 [1]: 6
Pythonパッケージ開発

テンプレートの出力

mysklearn/
|-- mysklearn/
|   |-- __init__.py
|   `-- mysklearn.py
|-- tests/
|   |-- __init__.py
|   `-- test_mysklearn.py
|-- MANIFEST.in
|-- README.rst
|-- requirements_dev.txt
|-- setup.cfg
|-- setup.py
|-- tox.ini

|-- AUTHORS.rst |-- CONTRIBUTING.rst |-- HISTORY.rst `-- Makefile

AUTHORS.rst の中身

=======
Credits
=======

Development Lead
________________

* James Fulton <[email protected]>

Contributors
____________

None yet. Why not be the first?
Pythonパッケージ開発

テンプレートの出力

mysklearn/
|-- mysklearn/
|-- tests/
|-- MANIFEST.in
|-- README.rst
|-- requirements_dev.txt
|-- setup.cfg
|-- setup.py
|-- tox.ini
...
...
|-- docs/
|-- .github/
|-- .editorconfig
|-- .gitignore
`-- .travis.yml
Pythonパッケージ開発

Ayo berlatih!

Pythonパッケージ開発

Preparing Video For Download...