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.

  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!

时间: 2024-11-02 00:17:39

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/20107535_446635492.shtml The open source tool about se http://www.ltesting.net/ceshi/open/kygncsgj/ Steps: Install pyDev in eclipse.    This is the de

Visual Studio Create Setup project to deploy web application in IIS

Introduction: In this article I will explain how to create setup file in visual studio 2008/2010 to deploy web application file directly in IIS or in client machine or how to place web application folder in c:\\inetpub\wwwroot folder by running setup

Mac Error Create Android Project - “Errors running builder &#39;Android Resource Manager&#39; on project”

http://stackoverflow.com/questions/18096315/mac-error-create-android-project-errors-running-builder-android-resource-man 在mac笔记本上运行android eclipse报标题的错误,然后在stackoverflow上找到了答案 18down votefavorite 5 I spent the whole day just trying to create a simple

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 if you do what I teach you, en, Now, we will start! Step 1: Open Oracle Policy Modeling, File --> New Project... Type the "hongten-pom" for the

创建一个Eclipse项目【Create a Project with Eclipse】

最近一个问题很困扰我,今天则得到了答案,也意味着我该选择了. 不知道大家有没有遇到过这样的情况,我是上年刚毕业,大四时进行过java培训,12年9月-13年4月,在这之前已经自学过java.7月份时进入一家公司工作,今年3月份辞职,4月份找到工作,来上班了.一开始就不太喜欢公司氛围,前台,hr,态度什么的都不太好,工作环境也极像客服部,整天电话不断,讨论声不断,第一个星期真是煎熬,去了两三天之后有辞职的想法,但是后面想想还是算了,公司待遇还可以. 但是进入到公司后leader让学PHP,学PHP

创建Z-Stack项目的工具(Create Z-Stack Project For IAR)

         Create Z-Stack Project For IAR 做Zigbee开发用CC2530肯定会用到Z-Stack,而开发环境一般选IAR Embedded Workbench,但是麻烦的是每次新建一个Z-Stack项目工程就是噩梦,各种复制和修改烦人不得以,因此这个工具就是简化基于Z-Stack库创建项目的过程.有问题请与我联系!QQ441673604. ***********************************************************

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 project(called A.sln), I only have to update the included lib file in my dll project. So I create a new win32 project, which is an empty dll project. Here

Create the Project

https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/create-the-project Download Wingtip Toys Sample Project (C#) or Download E-book (PDF) This tutorial series will teach you the basics o

Eclipse Maven to create Struts2 Project

Follow the guide in this page: http://blog.csdn.net/topwqp/article/details/8882965 problem met : Description Resource Path Location TypeThe superclass "javax.servlet.http.HttpServlet" was not found on the Java Build Path index.jsp /Sample_Struts