create python project steps
Setting Up Your First Project
You don't have to manually create the structure above, many tools will help you build this environment. For example the Cookiecutter project will help you manage project templates and quickly build them. The spinx-quickstart command will generate your documentation directory. Github will add the README.md and LICENSE.txt stubs. Finally, pip freeze will generate the requirements.txt file.
Starting a Python project is a ritual, however, so I will take you through my process for starting one. Light a candle, roll up your sleeves, and get a coffee. It's time.
Inside of your Projects directory, create a directory for your workspace (project). Let's pretend that we're building a project that will generate a social network from emails, we'll call it "emailgraph."
$ mkdir ~/Projects/emailgraph
$ cd ~/Projects/emailgraphInitialize your repository with Git.
$ git init
Initialize your virtualenv with virtualenv wrapper.
$ mkvirtualenv -a $(pwd) emailgraph
This will create the virtual environment in ~/.virtualenvs/emailgraph and automatically activate it for you. At any time and at any place on the command line, you can issue the
workon emailgraphcommand and you'll be taken to your project directory (the-aflag specifies that this is the project directory for this virtualenv).Create the various directories that you'll require:
(emailgraph)$ mkdir bin tests emailgraph docs fixtures
And then create the various files that are needed:
(emailgraph)$ touch tests/__init__.py
(emailgraph)$ touch emailgraph/__init__.py
(emailgraph)$ touch setup.py README.md LICENSE.txt .gitignore
(emailgraph)$ touch bin/emailgraph-admin.pyGenerate the documentation using
sphinx-quickstart:(emailgraph)$ sphinx-quickstart
You can safely use the defaults, but make sure that you do accept the Makefile at the end to quickly and easily generate the documentation. This should create an index.rst and conf.py file in your
docsdirectory.Install nose and coverage to begin your test harness:
(emailgraph)$ pip install nose coverage
Open up the
tests/__init__.pyfile with your favorite editor, and add the following initialization tests:import unittest class InitializationTests(unittest.TestCase): def test_initialization(self):
"""
Check the test suite runs by affirming 2+2=4
"""
self.assertEqual(2+2, 4) def test_import(self):
"""
Ensure the test suite can import our module
"""
try:
import emailgraph
except ImportError:
self.fail("Was not able to import the emailgraph")From your project directory, you can now run the test suite, with coverage as follows:
(emailgraph)$ nosetests -v --with-coverage --cover-package=emailgraph \
--cover-inclusive --cover-erase testsYou should see two tests passing along with a 100% test coverage report.
Open up the
setup.pyfile and add the following lines:#!/usr/bin/env python
raise NotImplementedError("Setup not implemented yet.")Setting up your app for deployment is the topic of another post, but this will alert other developers to the fact that you haven't gotten around to it yet.
Create the
requirements.txtfile usingpip freeze:(emailgraph)$ pip freeze > requirements.txt
Finally, commit all the work you've done to email graph to the repository.
(emailgraph)$ git add --all
(emailgraph)$ git status
On branch master Initial commit Changes to be committed:
(use "git rm --cached <file>..." to unstage) new file: LICENSE.txt
new file: README.md
new file: bin/emailgraph-admin.py
new file: docs/Makefile
new file: docs/conf.py
new file: docs/index.rst
new file: emailgraph/__init__.py
new file: requirements.txt
new file: setup.py
new file: tests/__init__.py (emailgraph)$ git commit -m "Initial repository setup"
With that you should have your project all setup and ready to go. Get some more coffee, it's time to start work!
create python project steps的更多相关文章
- Use eplipse to develop Python project
Source: This is the example how to use eclipse and python. http://www.360doc.com/content/15/0206/10/ ...
- How to create a project with Oracle Policy Modeling
This blog is about how to create a project with Oracle Policy Modeling. You can do it successfully i ...
- create dll project based on the existing project
Today, I have to create a dll project(called my.sln), the dllmain.cpp/.h/ is already in another proj ...
- Create the Project
https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...
- Eclipse Maven to create Struts2 Project
Follow the guide in this page: http://blog.csdn.net/topwqp/article/details/8882965 problem met : Des ...
- How to create a project with existing folder of files in Visual Studio?
1. Select Visual Studio tool bar-> New -> Project from existing code-> continue with config ...
- Windows编译Nodejs时遇到 File "configure", line 313 SyntaxError: invalid syntax Failed to create vc project files. 时的解决方法
第一次编译的时候电脑上未安装python,遂下载了python最新版本3.3.3,但是报了下面这个错误. 把python降到2.7.*的版本即可. 我这里测试2.7.6和2.7.3版本可以正常编译.
- 迁移python project
1.从python官网下载同版本的安装版的python,在新机器上安装同样版本的python(python底层是用C语言写的,安装python会安装c c++用到的库) 2.拷贝united1整个文 ...
- Step by Step 設定 TFS 2012 Create Team Project 權限 - 避免 TF218017、TF250044
基本上權限的設定和 以往的 TFS 沒有什麼太大的差別 只是這次的權限設定畫面有略作些調整,我還是一併整理一下 當我們用 TFSSetup 的帳號安裝完 TFS 2012 後 想要在自已的電腦上用自已 ...
随机推荐
- Java 常用集合笔记
自增数组 ArrayList<Integer>G[]=new ArrayList[N] 详细笔记 相关题目 栈 Stack<Integer> stack=new Stack&l ...
- Leetcode 304.二维区域和检索-矩阵不可变
二维区域和检索 - 矩阵不可变 给定一个二维矩阵,计算其子矩形范围内元素的总和,该子矩阵的左上角为 (row1, col1) ,右下角为 (row2, col2). 上图子矩阵左上角 (row1, c ...
- irules事件和命令
- POJ 1201 差分方程分析
POJ 1201 给你N个闭区间.每个区间分别为[ai,bi],你必须在这个区间上至少取ci个不同的整数. 现要求所有区间满足各自的条件. 问最少需要选多少个点. 例如[3,7](3) [8,10] ...
- 使用WaveOut API播放WAV音频文件(解决卡顿)
虽然waveout已经过时,但是其api简单,有些时候也还是需要用到. 其实还是自己上msdn查阅相应api最靠谱,waveout也有提供暂停.设置音量等接口的,这里给个链接,需要的可以自己查找: h ...
- 2018-2019 XIX Open Cup, Grand Prix of Korea (Division 2) GYM 102058 F SG函数
http://codeforces.com/gym/102058/problem/F 题意:平面上n个点 两个人轮流在任意两个点之间连一条线但是不能和已有的线相交,先围成一个凸多边形的获胜,先手赢还 ...
- POJ 2484 A Funny Game【博弈】
相比数据结构的题..感觉这种想啊想的题可爱多了~~~代码量还少.... 题目链接: http://poj.org/problem?id=2484 题意: 一圈n个硬币,两人轮流从中取一或两个硬币,(只 ...
- POJ 1780 【手工递归】【欧拉回路】
题意: 1.提供密码的位数. 2.密码的输入可以一直保持,取后n位作为密码.如果密码正确则开锁. 3.设计一种方法使得在输入最少的情况下破译.(即保证每个密码只输入一次) 4.输出输入的数字的序列. ...
- webpack体积优化篇一
定位 webpack 大的原因 这里推荐使用 webpack-bundle-analyzer —— Webpack 插件和 CLI 实用程序,她可以将内容束展示为方便交互的直观树状图,让你明白你所 ...
- Spring中使用byType实现Beans自动装配
以下内容引用自http://wiki.jikexueyuan.com/project/spring/beans-auto-wiring/spring-autowiring-byType.html: 此 ...