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. 一个关于vue+mysql+express的全栈项目(五)------ 实时聊天部分socket.io

    一.基于web端的实时通讯,我们都知道有websocket,为了快速开发,本项目我们采用socket.io(客户端使用socket.io-client) Socket.io是一个WebSocket库, ...

  2. springMVC model传对象数组 jq 获取

    这个问题网上没有什么解答,有两种可能性: 一.我使用的这种方法实在太蠢了正常人都不会去这个搞: 二.我太蠢了.... 以下解决方案 //后台代码如下 public String plant(Model ...

  3. Java学习之集合框架的迭代器--Iteratorjk及ListItertor接口

    通常情况下,你会希望遍历一个集合中的元素.例如,显示集合中的每个元素.一般遍历数组都是采用for循环或者增强for,这两个方法也可以用在集合框架,但是还有一种方法是采用迭代器遍历集合框架,它是一个对象 ...

  4. spring boot学习02【如何在spring boot项目中访问jsp】

    1.配置application.properties文件 打开application.properties追加 spring.mvc.view.prefix=/WEB-ROOT/ spring.mvc ...

  5. hdu 2167 状态压缩

    /*与1565的解法差不多*/ #include<stdio.h> #include<string.h> int map[16][16]; int dp[2][1<< ...

  6. free delete malloc new(——高品质量程序设计指南第16章)

    free和delete只是把指针所指向的内存给释放掉了,但是指针本身并没有被删掉. 所以在释放掉内存后一定要记得将指针指向NULL ,动态内存分配不会自动的释放,一定要记得free掉

  7. [Bzoj4817] [Sdoi2017]树点涂色 (LCT神题)

    4817: [Sdoi2017]树点涂色 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 629  Solved: 371[Submit][Status ...

  8. linux修改PS1,自定义命令提示符样式

    目录 参数说明 修改颜色 linux默认的命令提示符是这样的: 白色的,如果当前执行的命令很多的话,一整块屏幕上全是一堆输出信息,上一条命令在哪?我刚输入的命令在哪?找的头晕.有没有办法可以修改命令提 ...

  9. Spring中基于AOP的@AspectJ

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/aop-with-spring-framenwork/aspectj-based-aop-with- ...

  10. C# Queue与RabbitMQ的爱恨情仇(文末附源码):Q与MQ消息队列简单应用(二)

    上一章我们讲了队列( Queue),这一章我们讲Message Queue消息队列,简称MQ. 定义: MQ是MessageQueue,消息队列的简称(是流行的开源消息队列系统,利用erlang语言开 ...