LoginSignup
39
49

More than 5 years have passed since last update.

私が考えるPythonのプロジェクトテンプレート。

Last updated at Posted at 2016-08-22

 ここでは私が考えるPythonのプロジェクトテンプレートを紹介します。実際にチームを組んでプロジェクト開発を行ったことがないので、現場を知りません。ご指摘があれば是非ともお教えください。

ディレクトリ構成

まずはディレクトリの構成です。Pythonでimportする際の名前がmodulenameになります。buildやvenvは用意する必要がありませんが、buildはsetup.pyの利用を、venvはvirtualenvの利用を促す意味で作成しています。これらはREADME.mdに書いてもいいかもしれません。

Direcotry
Project\
    modulename\
        hoge.py
    build\
    test\
        test_hoge.py
    docs\
    venv\
    requirements.txt
    setup.py
    LICENCSE
    README.md
    MANIFEST.in

requirements.txt

開発環境をrequirements.txtに書き出しましょう。

pip3 freeze > requirements.txt
# install : pip3 install -r requirements.txt

setup.py

setup.py
#!/usr/bin/env python3
# coding:utf-8

from setuptools import setup

setup(name='Hoge_Project',
      version='0.0.1',
      description='Python Hoge_Project.',
      author='spam',
      author_email='hoge@spam.com',
      url='http://hoge.com',
      packages=['modulename'],
      #install_requires=['hoge','spam','hoge_spam'],
    )

追記:2016/08/23

MANIFEST.in

hatchineeさんにご指摘をいただいたので、追加させていただきます。パッケージ化する際にsetup.pyを使うと、デフォルトではpythonのソースファイル以外が追加されません。そのためパッケージ化する際に、python以外のファイルは明示的指定する必要があります。

#パッケージ化
python setup.py sdist   
#or 
python setup.py bdist_wheel
MANIFEST.in
include MANIFEST.in                                                                                                                
include *.txt                                                                                                                      
# Top-level                                                                                                                        
include setup.py README.md LICENCSE                                                                                                                 
# All-source file                                                                                                                  
recursive-include modulename *                                                                                                     
# All documentation                                                                                                                
recursive-include docs *
# Exclude what we don't want to include
global-exclude *.pyc *~ *.bak *.swp *.pyo

簡単ですが、これでおしまいです。

39
49
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
39
49