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 後 想要在自已的電腦上用自已 ...
随机推荐
- Vijos 1308 埃及分数(迭代加深搜索)
题意: 输入a.b, 求a/b 可以由多少个埃及分数组成. 埃及分数是形如1/a , a是自然数的分数. 如2/3 = 1/2 + 1/6, 但埃及分数中不允许有相同的 ,如不可以2/3 = 1/3 ...
- hdu3376 Matrix Again
最大费用最大流 咋写?取个相反数就可以了-- #include <iostream> #include <cstring> #include <cstdio> #i ...
- $config['base_url'] BASE_URL
/*|------------------------------------------------| Base Site URL|--------------------------------- ...
- 大数据学习——linux常用命令(三)
三 文件操作 1创建文件 touch somefile.txt 创建一个空文件somefile.txt > 重定向操作符 echo "woshiwoa"> some.t ...
- squid重定向(python 代码)
#!/usr/bin/python2.7 # coding: utf-8 import sys,os,stat import transport def redirect_url(line,concu ...
- 【贪心+二分】codeforces C. Sagheer and Nubian Market
http://codeforces.com/contest/812/problem/C [题意] 如何花最少的钱买最多的纪念品?首要满足纪念品尽可能多,纪念品数量一样花钱要最少,输出纪念品数量以及最少 ...
- 制作U盘Puppy-Live启动盘
制作U盘Puppy-Live启动盘 准备工具和材料:Puppy的ISO镜像文件.UltraISO工具.100M以上的U盘 开始: 1.用Ultraiso打开下载的镜像文件,然后选择菜单栏里面的&quo ...
- winrar5.0破解
RAR registration data Federal Agency for Education 1000000 PC usage license UID=b621cca9a84bc5deffbf ...
- unbuntu下安装多个JAVA JDK版本及如何切换
当前环境已经安装过jdk1.6.0_45安装JDK 1.7.x时,若安装错误,可执行以下步骤:sudo add-apt-repository ppa:openjdk-r/ppa sudo apt-ge ...
- Android资源目录结构
资源目录结构 res为资源目录,主要以xml语法编写静态的资源. 资源的命名标准:小写字母和数字,且以小写字母开头. 资源的生成,为了和java语法沟通,资源文件会自动的生成在[gen]目录的R.ja ...