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.

  1. 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/emailgraph
  2. Initialize your repository with Git.

    $ git init
    
  3. 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).

  4. 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.py
  5. Generate 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.

  6. Install nose and coverage to begin your test harness:

    (emailgraph)$ pip install nose coverage
    
  7. 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 tests

    You should see two tests passing along with a 100% test coverage report.

  8. 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.

  9. Create the requirements.txt file using pip freeze:

    (emailgraph)$ pip freeze > requirements.txt
    
  10. 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的更多相关文章

  1. 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/ ...

  2. 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 ...

  3. 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 ...

  4. Create the Project

    https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspn ...

  5. Eclipse Maven to create Struts2 Project

    Follow the guide in this page: http://blog.csdn.net/topwqp/article/details/8882965 problem met : Des ...

  6. 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 ...

  7. 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版本可以正常编译.

  8. 迁移python project

    1.从python官网下载同版本的安装版的python,在新机器上安装同样版本的python(python底层是用C语言写的,安装python会安装c  c++用到的库) 2.拷贝united1整个文 ...

  9. Step by Step 設定 TFS 2012 Create Team Project 權限 - 避免 TF218017、TF250044

    基本上權限的設定和 以往的 TFS 沒有什麼太大的差別 只是這次的權限設定畫面有略作些調整,我還是一併整理一下 當我們用 TFSSetup 的帳號安裝完 TFS 2012 後 想要在自已的電腦上用自已 ...

随机推荐

  1. CentOS 6.5 x64 安装Tomcat8 并配置两个Tomcat8

    1.首先,安装tomcat的前提是已经配置好jdk环境变量,若没配好可以参考我的上一篇博文:CentOS 6.5 x64安装jdk8,当然也可以通过网络搜索安装步骤~~ 2.下载: 可以通过官网下载: ...

  2. OI中的小智慧

    反正不会咕咕的. sort之类没+1的问题不说 双向边n*2的问题不说 变量n+5的问题不说 1.先生成后判断 (见NOIP 2016 pj t2回文日期) 这个思想在这道题体现的不明显,记得洛谷上面 ...

  3. Go切片基础

    package main import "fmt" //切片(Slice)本身没有数据,是对底层Array的一个view //不使用指针就可以改数组内容 //slice可以向后扩展 ...

  4. php5.5编译安装

    系统环境:centos6.5PHP包:5.5.15https://wiki.swoole.com/wiki/page/177.html下载 PHP 源码包wget http://cn2.php.net ...

  5. Leetcode39.Combination Sum组合总和

    给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合. candidates 中的数字可以无限制重复被选 ...

  6. Hibernate 批处理(batch inserts, updates and deletes)

    总结:hibernate在进行批量处理不给力的主要原因就是Session中存在缓存,而hibernate的机制就是通过session中的一级缓存去同步数据库,所以当进行批量处理时,缓存中保存的数据量很 ...

  7. CodeForces - 462B Appleman and Card Game

    是一道简单题 将字母从个数多到小排序 然后 再按题目算法得到最多 但是注意 数据类型声明 money要为long long #include <iostream> #include < ...

  8. [NOIP2002] 提高组 洛谷P1034 矩形覆盖

    题目描述 在平面上有 n 个点(n <= 50),每个点用一对整数坐标表示.例如:当 n=4 时,4个点的坐标分另为:p1(1,1),p2(2,2),p3(3,6),P4(0,7),见图一. 这 ...

  9. POJ 1724 【存在附加约束的最短路问题】【优先队列】

    题意:给K个权值.给含有N个点,R条单向边的图. 每条边都有两个权值,其中一个路长,另外一个是附加权值. 要求路的附加权值之和不超过K的情况下求最短路. 思路: 自己的思路太狭隘,这题还是看了大牛的思 ...

  10. 使用fastjson将list、map转换成json,出现$ref

    这是转换时出现的问题情况( map >> json ) 引用是通过"$ref"来表示的 引用 描述 "$ref":".." 上一 ...