Note: python Skeleton Nya

Approximately original material

Project skeleton in my case

Forget it, so how to build your own python project

Prerequisites

The following are prerequisites for installation

1. Project environment construction

Build a python environment if needed

# Install python if needed
$ pythonz install py_version

# virtualenv environment construction
$ cd path_to_virtualenv_dir
$ virtualenv -p `pythonz locate py_version` virtualenv_dir_name

# pythonz installation contents confirmation
$ pythonz list
 virtualenv activate
$ . path_to_virtualenv_dir/virtualenv_dir_name/bin/activate
 virtualenv deactivate
$ deactivate

2. Create directory


# python project storage directory
$ mkdir projects
# Create project directory
$ mkdir prj_name ; cd prj_name
# Initialization
$ mkdir bin pkg_name test docs
touch pkg_name/__init__.py tests/__init__.py
  1. setup.py

Create the following files in prj_name / setup.py

try:
    from setuptools import setup
except ImportError:
    from distutils.core import setup

config = {
    'description': 'My Project',
    'author': 'My Name',
    'url': 'URL to get it at.',
    'download_url': 'Where to download it.',
    'author_email': 'My email.',
    'version': '0.1',
    'install_requires': ['nose'],
    'packages': ['NAME'],
    'scripts': [],
    'name': 'projectname'
}

setup(**config)

Set up dependent libraries under install_requires

$ python setup.py develop
# Verification
$ pip list

4. Prepare a test environment

Add tests to prj_name / tests / pkg_name_tests.py

from nose.tools import *
import pkg_name

def setup():
    print "SETUP!"

def teardown():
    print "TEAR DOWN!"

def test_basic():
    print "I RAN!"

Operation check

$ nosetest

5. Directory structure

The directory structure is as follows

prj_name/
     pkg_name/
         __init__.py
     bin/
     docs/
     setup.py
     tests/
         pkg_name_tests.py
         __init__.py

Recommended Posts

Note: python Skeleton Nya
Note: Python
Python note
Python study note_002
Note: Python Decorator
[Python] Learning Note 1
python script skeleton
Python study note_004
Python study note_003
[Note] openCV + python
Python beginner's note
[Note] future sentence ~ Python ~
[Note] File reading ~ Python ~
Note to daemonize python
Python basic grammar note (4)
Python basic grammar note (3)
Python Tkinter Primer Note
Python Input Note in AtCoder
[Note] Operate MongoDB with Python
Planar skeleton analysis with Python
[WIP] Fluent Python Study Note
3 months note for starting Python
[AtCoder] ABC165C Personal Note [Python]
Note that it supports Python 3
A note about [python] __debug__
Note
Python Note: About comparison using is
[Note] Project Euler in Python (Problem 1-22)
Python: A Note About Classes 1 "Abstract"
(Note) Be careful with python argparse
Note
[Note] Hello world output with python
Note
boto3 (AWS SDK for Python) Note
Foreign Key in Python SQLite [Note]
Planar skeleton analysis in Python (2) Hotfix
Python Note: Get the current month
A note about mock (Python mock library)
A note where a Python beginner got stuck
python note: when easy_install is not available
[Note] Get data from PostgreSQL with Python
Note when creating an environment with python
Note for Pyjulia calling Julia from Python
"Python Machine Learning Programming" Summary Note (Jupyter)
Example of 3D skeleton analysis by Python
[Personal note] Web page scraping with python3
Trying to handle SQLite3 with Python [Note]
Note that Python decorators should have wraps
(Note) Bulk upgrade of python installed packages
Python Note: The secret role of commas
[Note] Execute Python code from Excel (xlwings)