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 emailgraph
command and you'll be taken to your project directory (the-a
flag 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
docs
directory.Install nose and coverage to begin your test harness:
(emailgraph)$ pip install nose coverage
Open up the
tests/__init__.py
file 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.py
file 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.txt
file 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 後 想要在自已的電腦上用自已 ...
随机推荐
- springMVC中处理静态资源的几种方案
处理静态资源方案一:在web.xml文件中配置如下: <!-- <!–解决静态资源方案–> <servlet-mapping> <servlet-name>d ...
- 使用PL/SQL将sql脚本数据导入数据库
一. PL/SQL登录到数据库,使用tools工具进行导入.使用plsql登录到需要导入数据的数据库.点击工具栏上[tools]--[Import tables] 二.commit;
- 零、常用的Mysql数据库操作语句大全
零.用户管理: 1.新建用户: >CREATE USER name IDENTIFIED BY 'ssapdrow'; 2.更改密码: >SET PASSWORD FOR name=PAS ...
- POJ2926-Requirements,曼哈顿距离。去掉绝对值符号暴力枚举所有情况,神薙!
Requirements 好吧,这题我实在想不到什么优化的方法,看了看讨论区,顺便膜拜了一下大 ...
- HDU1280前m大的数creat at 9:51,3.13,2016
前m大的数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- 什么是Service Mesh?
转至大佬宋净明的博客:https://jimmysong.io/posts/what-is-a-service-mesh/ Service mesh 又译作 “服务网格”,作为服务间通信的基础设施层. ...
- [NOIP2003] 普及组
乒乓球 模拟 /*By SilverN*/ #include<iostream> #include<algorithm> #include<cstring> #in ...
- PatentTips - Reducing Write Amplification in a Flash Memory
BACKGROUND OF THE INVENTION Conventional NAND Flash memories move data in the background to write ov ...
- linux日志服务器审计客户端history记录
https://blog.csdn.net/yanggd1987/article/details/70255179
- ztr loves lucky numbers--hdu5676(DFS)
http://acm.hdu.edu.cn/showproblem.php?pid=5676 题目大意: 给你一个数 让你找比这数大并且只含4和7 并且4和7的个数一样 枚举从0到10的18次方之 ...