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. Java集合之Queue

    queue 定义 C++:queue Java:Queue 创建与其基本操作 创建: Queue<Integer> q=new LinkedList<Integer>(); 数 ...

  2. 访问变量的每个字节内容(c语言)

    #include <stdio.h> #define fun(x) for(int fun_i = 0; fun_i < sizeof(x); fun_i++){printf(&qu ...

  3. Tomcat 7.0.3x 启动慢并且遇到StackOverflowError的异常的解决办法

    http://qiuboboy.iteye.com/blog/1853216 使用tomcat 7.0.3x版本的同学可以发现tomcat启动慢了不少,而且还可能遇到如下启动时异常: Unable t ...

  4. Spring使用JdbcTemplate实现对数据库操作

    https://www.cnblogs.com/tuhooo/p/6491913.html https://blog.csdn.net/maodoubi/article/details/4826723 ...

  5. maven+Hibernate+mysql环境搭建

    项目结构图如下 一,首先是添加依赖pom.xml <?xml version="1.0" encoding="UTF-8"?> <projec ...

  6. Laya 分帧加载优化

    Laya 分帧加载优化 @author ixenos Flash中的EnterFrame事件在Laya中等同于Laya.timer.frameLoop(1,...) Laya.timer.frameL ...

  7. 校第十六届大学生程序设计竞赛暨2016省赛集训队选拔赛(Problem E)

    Problem E Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  8. [luoguP2704] 炮兵阵地(状压DP)

    传送门 可以事先把每一行的所有状态处理出来,发现每一行的状态数最多不超过60个 f[i][j][k]表示前i行,第i行为状态j,第i-1行为状态k的最优解 #include <vector> ...

  9. 洛谷P4219 - [BJOI2014]大融合

    Portal Description 初始有\(n(n\leq10^5)\)个孤立的点,进行\(Q(Q\leq10^5)\)次操作: 连接边\((u,v)\),保证\(u,v\)不连通. 询问有多少条 ...

  10. TJOI2014

    匹配 给出一个\(n(n\leq80)\)个点对\(n\)个点的带权二分图,求所有最大权匹配的交集. 先求出一个最大权匹配,然后枚举每一条匹配中的边,检验删除该边后是否还能形成最大权匹配.如果能则说明 ...