A quick start for python pyramid

February 10, 2012 by · Comments Off on A quick start for python pyramid
Filed under: python 

Installation of pyramid

1.Install python 2.7/3.x

2.Install setuptools

For windows, please add C:\Python27\Scripts to PATH variable.

For ubuntu: apt-get install python-setuptools

3.Install virtualenv

$easy_install virtualenv

On windows, download virtualenv-1.7.tar.gz, decompress, and run : python setup.py install

create a virtual working directory mysite:
virtualenv mysite
cd mysite
source bin/activate  (Scripts\activate.bat)

Then variable $VIRTUAL_ENV will be set;  and virtualenv modified $PATH, appended bin/python,
also virtualenv installed pip at ENV/bin; so new python packages would be installed here, such as: pip install html5lib.

clear virtual env:
virtualenv –clear mysite

4. Install Pyramid and Preparation

Preparation, on unix/linux:

After you’ve got your env virtualenv installed, you may install Pyramid itself using the following commands from within the virtualenv (env) directory:

$ bin/easy_install pyramid

$bin/easy_install docutils nose coverage zope.sqlalchemy SQLAlchemy pyramid_tm waitress

Preparation, on Windows
Use your Python’s virtualenv to make a workspace:

c:\> c:\Python26\Scripts\virtualenv mysite
Switch to the pyramidtut directory:

c:\> cd mysite
Use easy_install to get Pyramid and its direct dependencies installed:

c:\mysite> Scripts\easy_install pyramid
Use easy_install to install various packages from PyPI.

c:\mysite> Scripts\easy_install docutils nose coverage zope.sqlalchemy SQLAlchemy pyramid_tm waitress
5. How to create project aimed at deployment
————————————
5.1. Making a Project
Your next step is to create a project. Pyramid supplies a variety of scaffolds to generate sample projects. We will use the pyramid_routesalchemy scaffold, which generates an application that uses SQLAlchemy and URL dispatch.

The below instructions assume your current working directory is the “virtualenv” named “pyramidtut”.

On UNIX, for pyramid 1.2:
$ bin/paster create -t pyramid_routesalchemy tutorial

On Windows, for pyramid 1.2:
c:\pyramidtut> Scripts\paster create -t pyramid_routesalchemy tutorial

On unix, for pyramid 1.3:
$ bin/pcreate –list-templates
$ bin/pcreate -s starter tutorial

On Windows, for pyramid 1.3:
scripts\pcreate –list-templates
scripts\pcreate -s starter tutorial

Note

If you are using Windows, the pyramid_routesalchemy scaffold may not deal gracefully with installation into a location that contains spaces in the path. If you experience startup problems, try putting both the virtualenv and the project into directories that do not contain spaces in their paths.

————————————–
5.2. Installing the Project in “Development Mode”
In order to do development on the project easily, you must “register” the project as a development egg in your workspace using the setup.py develop command. In order to do so, cd to the “tutorial” directory you created in Making a Project, and run the “setup.py develop” command using virtualenv Python interpreter.

On UNIX:

$ cd tutorial
$ ../bin/python setup.py develop

———————————
On Windows:

c:\pyramidtut> cd tutorial
c:\pyramidtut\tutorial> ..\Scripts\python setup.py develop

———————————
5.3 Running the Tests
After you’ve installed the project in development mode, you may run the tests for the project.

On UNIX:

$ ../bin/python setup.py test -q
On Windows:

c:\pyramidtut\tutorial> ..\Scripts\python setup.py test -q

————————–
5.4. install new project:

$ cd MyProject
$ ..\Scripts\python.exe setup.py develop

This will install adistributionrepresenting your project into the interpreter’s library set so it can be found by import statements and by other console scripts such aspserve, pshell, proutes and pviews

———————————-
5.5. Starting the Application
Start the application.

On UNIX:

$ ../bin/pserve development.ini
or
$ ../bin/pserve development.ini –reload

When –reload is passed topserve, changes to any Python module your project uses will cause the server to restart. This
typically makes development easier, as changes to Python code made within a Pyramid application is not
put into effect until the server restarts.

On Windows:

c:\pyramidtut\tutorial> ..\Scripts\pserve development.ini
———————–
5.6. Visit the Application in a Browser
In a browser, visit http://localhost:6543/. You will see the generated application’s default page.

One thing you’ll notice is the “debug toolbar” icon on right hand side of the page. You can read more about the purpose of the icon at The Debug Toolbar. It allows you to get information about your application while you develop.
———————–
5.7.Exposing Test Coverage Information

You can run the nosetests command to see test coverage information. This runs the tests in the same way that setup.py test does but provides additional “coverage” information, exposing which lines of your project are “covered” (or not covered) by the tests.

To get this functionality working, we’ll need to install a couple of other packages into our virtualenv: nose and coverage:

On UNIX:

$ ../bin/easy_install nose coverage
On Windows:

c:\pyramidtut\tutorial> ..\Scripts\easy_install nose coverage
Once nose and coverage are installed, we can actually run the coverage tests.

On UNIX:

$ ../bin/nosetests –cover-package=tutorial –cover-erase –with-coverage
On Windows:

c:\pyramidtut\tutorial> ..\Scripts\nosetests –cover-package=tutorial ^
–cover-erase –with-coverage
Looks like our package’s models module doesn’t quite have 100% test coverage.

 

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)

Noticeable Hacker News I Read(2011/07)

August 1, 2011 by · Comments Off on Noticeable Hacker News I Read(2011/07)
Filed under: tech watch 

Post for Startup:
How to use A/B testing for better product design

Hackers to follow on Google+

Which domain registrar is best?

Why you should’nt keep your startup idea secret

How has your profession affected your non-professional thinking?

Post for Tech:

Google Running About 900,000 Servers (datacenterknowledge.com)

Stop A/B Testing and Make Out like a Bandit (untyped.com)

Why We Prefer Founding CEOs (bhorowitz.com)

Early Unix history and evolution (mit.edu)

LevelDB: A Fast Persistent Key-Value Store

Better Understanding Link-based Spam Analysis Techniques (seomoz.org)

Understanding the Git Workflow (sandofsky.com)

So you want to write a fast Python? (alexgaynor.net)

Awesome Python and django related projects (elweb.co)

Twitter Shifting More Code to JVM, Citing Performance and Encapsulation As Primary Drivers

Setting Up SSL on Tomcat in 5 minutes

Introduction to Algorithms

All About Time

JavaScript language advanced Tips & Tricks

Finagle is a library for building asynchronous RPC servers and clients in Java, Scala, or any JVM language.

Protocol buffer socket rpc in python/java

Akka and the java memory model

Things Everyone Should Do: Code Review (scientopia.org)

Why I read Hacker News even though I understand very little of it (alexrosen.com)

Realtime image processing in Python

http://prizes.org/
Why Every Maker Should Learn Chinese

Learn core python in one week (my way)

Find is a beautiful tool

 

On Education and Life: 

Harvard and Class

How to raise a global kid?

11 Unusual Methods for Being a Great Public Speaker (jamesaltucher.com)

 

 

 

 

Digg This
Reddit This
Stumble Now!
Vote on DZone
Share on Facebook
Bookmark this on Delicious
Share on LinkedIn
Bookmark this on Technorati
Post on Twitter
Google Buzz (aka. Google Reader)