You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1# framework imports2fromwsgiref.simple_serverimportmake_server3frompyramid.configimportConfigurator4frompyramid.responseimportResponse56# hello view on route 'hello_world'7defhello(request):
8returnResponse('Hello world!')
910# Base call on file11if__name__=='__main__':
12# Base Configuration13config=Configurator()
14config.add_route('hello_world', '/')
15config.add_view(hello, route_name='hello_world')
1617# Building and starting the app18app=config.make_wsgi_app()
19server=make_server('0.0.0.0', 8080, app)
20server.serve_forever()
id:
excurses
class:
slide level-1
data-x:
r+1500
data-y:
1000
Excurses
Philosophy
Be lazy - Don't repeat yourself - Don't reinvent the wheel
Standing on the shoulders of giants
Test Driven Development & Documentation
Tools
git
Python Eggs
id:
phil
class:
slide level-1
data-x:
r-500
data-y:
r+1000
Philosophy three great virtues of a programmer
Laziness: The quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don't have to answer so many questions about it.
Impatience: The anger you feel when the computer is being lazy. This makes you write programs that don't just react to your needs, but actually anticipate them. Or at least pretend to.
Hubris: The quality that makes you write (and maintain) programs that other people won't want to say bad things about.
—"Programming Perl", Larry Wall, 2nd Edition, O'Reilly, 1996
id:
dry
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Philosophy DRY - Don't repeat yourself
Don't repeat yourself
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
—Andy Hunt, Dave Thomas; The Pragmatic Programmer
DRY vs WET
DRY: Don't repeat yourself
WET: write everything twice / we enjoy typing
It applies for one program and also to best practice of frameworks
id:
reinvent
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Philosophy Don't reinvent the wheel
To reinvent the wheel is to duplicate a basic method that has already previously been created or optimized by others.
Why should I write and maintain code that others alrady have developed
Using Best practices
Standing on the shoulders of giants - we don't have to reinvent the wheel, we use it
id:
tests
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Test Driven Development & Documentation
Specification
Testing of Specification
Documentation
id:
git
class:
slide level-1
data-x:
r+1000
data-y:
2000
Tool: GIT
git: a distributed version control system
git init
git clone url
git status
git add
git rm
git commit
git checkout
git branch
git push
id:
eggs
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Python Eggs/Wheels
Eggs/Wheels are the Python Packaging Container
id:
scaffolds
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Scaffolds / Templates / Skeletons
Concept of Code Generation to bootstrap software components
id:
normal-pyramid-app
class:
slide level-1
data-x:
r+1000
data-y:
1000
Starting a Pyramid App
Steps:
Virtual Environment (pyvenv)
install pyramid
use scaffold to create base app / egg structure
check into VCS
start app in development mode and start developing
id:
venv
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Virtual Environment
$ pyvenv base_app
$ cd base_app
$ source bin/activate
Install Pyramid
$ pip install pyramid
id:
bootstrap
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Bootstrap App with scaffold
# generate app from scaffold# (for all avaliable scaffolds see: `pcreate --list`)
$ pcreate -s starter base_app
...
$ cd base_app
# Check generated Code into VCS
$ git init .
$ git add setup.py README.txt base_app/
$ git commit -m "initial version from scaffold"# build app
$ python setup.py develop
id:
start
class:
slide level-1
data-x:
r+0
data-y:
r+1000
Start App
$ pserve --reload development.ini
Starting subprocess with file monitor
Starting server in PID xxxx.
serving on http://0.0.0.0:6543