Personal tools
You are here: Home Weblog general

general

2007-04-28

Write nicer Python code

Filed Under:

Starting from the basic facts:

  • you can't always code in pair
  • you don't want to compile & tests to check that is fine in the last few line you have just written
  • you want to write nice python code
  • you want to improve the way you write python

It exists a few very interesting softwares that can help you.

Here is a list of the one I am using really often:

PyFlakes - http://www.divmod.org/projects/pyflakes

PyLint - http://www.logilab.org/view?rql=Any%20X%20WHERE%20X%20eid%20857

These two are nice also but not as good as the previous one:

PyMetrics - http://sourceforge.net/projects/pymetrics

PyChecker - http://pychecker.sourceforge.net/
 
These tool are directly linked to my favourite editor VI:

command Pyflakes :call Pyflakes()
function! Pyflakes()
    let tmpfile = tempname()
    execute "w" tmpfile
    execute "set makeprg=(pyflakes\\ " . tmpfile . "\\\\\\|sed\\ s@" . tmpfile ."@%@)"
    make
    cw
endfunction


command Pylint :call Pylint()
function! Pylint()
setlocal makeprg=(echo\ '[%]';\ pylint\ %)
setlocal efm=%+P[%f],%t:\ %#%l:%m
silent make
cwindow
endfunction


And better each time you save your python file in vim , I check for wrong imports with Pyflakes with:

autocmd BufWrite *.{py} :call Pyflakes()


2006-10-24

Watch my new commit...

Filed Under:

Get notification as soon as somebody commit is really important! A quick note to set it up with emails...

We will make this in 4 steps.

Step 1: Installing pysvn

Check that you don't have it yet:
$ python2.4
Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svn
>>>
If you get something else (e.g ImportError: No module named svn) you will need to do this step:

You will need the python library to access subversion: pysvn. Note that header of the libsvn are required [should come with your subversion install]!
Go to  http://pysvn.tigris.org/project_downloads.html and fetch last tarball (MacOSX version also available). Note that
pysvn is noted there as "Extension". I fetched last stable version: http://pysvn.tigris.org/files/documents/1233/34994/pysvn-1.5.0.tar.gz

$ tar xvzf pysvn-1.5.0.tar.gz 
 ...
$ cd pysvn-1.5.0/Source
$ python2.4 setup.py configure
...
$ make
...[pray]...
$ mkdir /usr/lib/python2.4/site-packages/pysvn
$ cp pysvn/__init__.py /usr/lib/python2.4/site-packages/pysvn
$ cp pysvn/_pysvn.so /usr/lib/python2.4/site-packages/pysvn
Now try again and you should get something like:
$ python2.4
Python 2.4.3 (#2, Oct  6 2006, 07:52:30)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import svn
>>>


Step 2: Installing SVNMailer


Go to http://storage.perlig.de/svnmailer/ and fetch last tarball (stable actual one is: http://storage.perlig.de/svnmailer/svnmailer-1.0.8.tar.gz)

Fallow these steps:
$ tar xvzf svnmailer-1.0.8.tar.gz
...

$ cd svnmailer-1.0.8
$ /usr/bin/python2.4 setup.py install
...

 You have now a brand new svnmailer installed. Check it with:

$ ls -l /usr/bin/svnmailer
-rwxr-xr-x 1 root root 2192 2006-10-24 17:00 /usr/bin/svn-mailer

3) Configure your repository to use svnmailer


We created a svn repository:

$ svnadmin create /var/svn/repos1
So we have a repository on our local filesystem in /var/svn/repos1

Go into the hooks directory:
$ cd /var/svn/repos1/hooks
Add/edit post-commit file.
And add the fallowing lines:
#!/bin/sh
REPOS="$1"
REV="$2"
/usr/bin/svn-mailer commit "$REPOS" "$REV" /etc/svn-mailer.conf
Change execute permission on post-commit
chmod 755 post-commit
It's time to configure SVNMailer

4) Configure SVNMailer


Edit/Add the file /etc/svn-mailer.conf
And add the fallowing lines [you might edit few things...]. Imagine that I have mymodule in my repository (so that i can do svn co file:///var/svn/repos1/mymodule)

[general]
# see http://opensource.perlig.de/svnmailer/doc-1.0/#general for details.

# the diff command to be used ... just copy it...
diff = /usr/bin/diff -u -L %(label_from)s -L %(label_to)s %(from)s %(to)s
# the sendmail location
mail_command = /usr/sbin/sendmail

[mymodule]
# see http://opensource.perlig.de/svnmailer/doc-1.0/#groups for details
# this part of the config apply only for commits under mymodule
for_paths = mymodule/.*

# the subject of the email
commit_subject_prefix = [MYMODULE]

# From address in the mail
from_addr = jfroche@jfroche.be

# To address ...
to_addr = peopleinterestinginmymodule@foo.bar

[defaults]
# see http://opensource.perlig.de/svnmailer/doc-1.0/#groups for details
# this part of the config apply for all the other module

# Default From address template
from_addr = %(author)s@localhost.localdomain

# the subject of the email
commit_subject_prefix = [SVN]
to_addr = jeff@jfroche.be foo@skynet.be bar@gmail.com
generate_diffs = add copy modify
suppress_deletes = yes
Here it is... Try to commit and you should get email...

If you want to traceback error, go to edit /var/svn/repos1/hooks/post-commit and for example log to a file by changing the line
/usr/bin/svn-mailer commit "$REPOS" "$REV" /etc/svn-mailer.conf
In
/usr/bin/svn-mailer commit "$REPOS" "$REV" /etc/svn-mailer.conf 2> 1> /tmp/svnmailer.log
Hope this helps ...

2006-04-05

Blogging...

Filed Under:

What about me blogging?

Having a blog seems to be a really new fashion among differents communities (young people, developpeurs, scientists, artists ...).

Blog is a short form for weblog in fact, principe is simple: display at the top the newest written article.
There is different kind of weblog:

  • Personal : express the life's thoughts
  • Professional : express professional experiences
  • Cultural : express all your culural (music, movie, paintings...) thoughts

Most of my stuffs will be about personal and professional expericences, General will be my personnal thoughts and the others will be topic oriented.

As Zope and Plone are part of my professional fun for the moment these are the actual topics. Don't know if I will be enough talkative to express what I see, feel but it's a good exercice for me. Taking also my place into this so big world...

My previous thoughts about blogging were very negative, thinking that most are unuseful and never read. They were like books inside a cellar that nobody read. Things are changing as you see. While working on a zope 3 stuff, I was yesterday thinking  "hey I should put that somewhere on a page..." and the weblog idea came up again. Don't want to tell myself "you should go there every night and at least write something", something that I will do during few days and stop, I know me. So let's say I will write here when i feel so without any dates constraints.

Spelling, grammar... I am a native french speaker that should take more english lessons. I don't want to write here in french as english is thecommon language in the zope/plone community. I hope people don't mind too much about that ?




Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: