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 後 想要在自已的電腦上用自已 ...
随机推荐
- MindManager 设置默认Note字体大小
工具栏 Design > Notes Theme > Default Font
- [Poi2011]Meteors 题解
题目大意: 给定一个环,每个节点有一个所属国家,k次事件,每次对[l,r]区间上的每个点点权加上一个值,求每个国家最早多少次操作之后所有点的点权和能达到一个值. 思路: 整体二分(二分答案),对于每个 ...
- bzoj 2802 [Poi2012]Warehouse Store STL
[Poi2012]Warehouse Store Time Limit: 10 Sec Memory Limit: 64 MBSec Special JudgeSubmit: 621 Solve ...
- SQL Server 创建唯一约束sql语句
SQL Server 创建唯一约束sql语句 语句示例: 在创建表是时同时创建, 创建id,name,sex三个字段的唯一索引 create table t1( id int primary ...
- 数字游戏(codevs 1085)
题目描述 Description 丁丁最近沉迷于一个数字游戏之中.这个游戏看似简单,但丁丁在研究了许多天之后却发觉原来在简单的规则下想要赢得这个游戏并不那么容易.游戏是这样的,在你面前有一圈整数(一共 ...
- windows 配置 apache的多个站点
windows 配置apache的多个站点 第一步打开apache的conf/extra/httpd-vhosts.conf,复制<VirtualHost></VirtualHost ...
- 123. Best Time to Buy and Sell Stock III ~~
Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...
- express 写接口
实例下载:百度云盘免密码 (): 指注释 一.准备工作 1.安装express npm install express -g npm install express-generator -g 2.初始 ...
- winServer-常用winrm命令
学习WinServer必须学习powershell,学习powershell必须掌握远程管理服务器的方法,所以必须学会winrm来远程管理服务器 记录一些常用的winrm命令和错误 常用命令 //在P ...
- Google C++ style guide——C++类
1.构造函数的职责 构造函数中仅仅进行那些没有实际意义的初始化.由于成员变量的"有意义"的值大多不在构造函数中确定. 能够的话,使用Init()方法集中初始化为有意义的数据. 长处 ...