Create Python project steps

Source: Internet
Author: User
Tags virtual environment virtualenv

Setting up Your First Project

You don ' t has to manually create the structure above, many tools would help you build this environment. For example the Cookiecutter project would help you manage project templates and quickly build them. The Spinx-quickstart command would generate your documentation directory. Github would add the README.md and LICENSE.txt stubs. Finally, would pip freeze generate the requirements.txt file.

Starting a Python project is a ritual, however, so I'll take your 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 would generate a social network from emails, we'll call it "emailgraph."

    $ mkdir ~/projects/emailgraphcd ~/projects/emailgraph
  2. Initialize your repository with Git.

    $ git init
  3. Initialize your virtualenv with virtualenv wrapper.

     $ mkvirtualenv-a $ (pwd    

    This would create the virtual environment in ~/.virtualenvs/emailgraph and automatically Activate it for you. At no time and at no place on the command line, you can issue the workon emailgraph command and you'll be t Aken to your project directory (the -a flag specifies that's 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 is 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 with the defaults, but make sure so do accept the Makefile on the end to quickly and easily generate T He documentation. This should create a 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 tests/__init__.py up the file with your favorite editor, and add the following initialization tests:

    ImportUnitTestClassInitializationtests(UnitTest.TestCase):DefTest_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 ( "is 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              --cover-inclusive--cover-erase tests 

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

  8. Open up the setup.py file and add the following lines:

    #!/usr/bin/env pythonnotimplementederror("Setup not implemented yet." )

    Setting up your apps for deployment are the topic of another post, but this would alert other developers to the fact it 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 of the work you've done to email graph to the repository.

      (emailgraph) $ git add--all (Emailgraph) $ git Statuson branch masterinitial commitchanges to being committed:  (use span class= "s2" > "git rm--cached <file> ..." to Unstage) new file:LICENSE.txt new file:README.md NE W file:bin/emailgraph-admin.py New File:docs/makefile new file:docs/conf.py new File:docs/index.rst new File:emailgra ph/__init__.py New File:requirements.txt New file:setup.py new File:tests/__init__.py (emailgraph< Span class= "O" >) $ git commit-m  "Initial Repository Setup"    

With this you should has your project all setup and ready to go. Get Some more coffee, it's time to start work!

Create Python project steps

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.