[SciPy-dev] version numbers.

Pearu Peterson pearu at cens.ioc.ee
Tue Feb 19 15:37:33 CST 2002


Hi Eric,

On Tue, 19 Feb 2002, Pearu Peterson wrote:

> I have studied a possibility to let CVS server to calculate these
> cvs-numbers. Indeed, it is possible but the corresponding script needs
> some adjustements. So, I hope that the frustation with updating version
> numbers in CVS should be temporary.

I have implemented required hooks and also tested in my CVS tree. It seems
to work very nicely.

So, in attachement you find a python script that calculates cvs version
numbers. Installation instructions for scipy are the following:

1) Copy the file calc_cvs_version.py to /home/cvsroot/CVSROOT:
  cp calc_cvs_version.py /home/cvsroot/CVSROOT/calc_cvs_version.py
2) Add the following (single) line to /home/cvsroot/CVSROOT/loginfo file:

world/scipy (/usr/bin/python $CVSROOT/CVSROOT/calc_cvs_version.py $CVSROOT/world/scipy)

3) Try to commit something and then do update. This should create file
__cvs_version__.py into the scipy tree. 

Few notes:
If someone tries to change __cvs_version__.py and commit it, it will have
no effect. So it is safe.
If files are commited to CVS then __cvs_version__.py will be updated in
each commit automatically.

You may also want to check the algorithm in calc_cvs_version.py in case I
missed something. I have tested it to work also with Python 1.5.2.
Let me know if you have any doubts about it.

Regards,
	Pearu
-------------- next part --------------
#!/usr/bin/env python
# Direct usage (only for testing):
#  calc_cvs_version.py <full_path_to_cvs_tree>
# Usage from CVS tree:
#  1) Copy this file to $CVSROOT/CVSROOT
#  2) Add the following line to $CVSROOT/CVSROOT/loginfo file:
#    dir/modulename (/full/path/to/python $CVSROOT/CVSROOT/calc_cvs_version.py $CVSROOT/dir/modulename)
#    Make sure that `python' is a full path to system python executable.
# Result:
#  Creates CVS formatted python file
#     <full_path_to_cvs_tree>/__cvs_version__.py,v
#  that contains the assignment of 3-tuple:
#     cvs_version = (<cvs_minor>,<cvs_micro>,<cvs_serial>)
# Author:
#  Pearu Peterson <pearu at cens.ioc.ee>
# Permission to use, modify, and distribute this software is given under the
# terms of the LGPL.  See http://www.fsf.org
# NO WARRANTY IS EXPRESSED OR IMPLIED.  USE AT YOUR OWN RISK.

import sys
import os
import string

if len(sys.argv)!=2: sys.exit()

cvs_path = os.path.abspath(sys.argv[1])

def visit_cvs_tree(cvs_version,dirname,names):
    try: names.remove('Attic')
    except ValueError: pass

    for name in filter(lambda n:n[-2:]==',v',names):
        if name=='__cvs_version__.py,v': continue
        f = open(os.path.join(dirname,name),'r')
        rev_numbers_str = string.split(f.readline())[1][:-1]
        f.close()
        rev_numbers = map(eval,string.split(rev_numbers_str,'.'))
        if len(rev_numbers)>1:
            cvs_version[-1] = cvs_version[-1] + rev_numbers[-1]
            cvs_version[-2] = cvs_version[-2] + rev_numbers[-2]

cvs_version_py_tmpl = """\
head    #revision#;
access;
symbols;
locks; strict;
comment @# @;


#revision#
date    2002.02.19.18.41.34;    author pearu;   state Exp;
branches;
next    ;


desc
@@


#revision#
log
@__cvs_version__.py
@
text
@### DO NOT EDIT THIS FILE!!!
### DO NOT TRY TO COMMIT THIS FILE TO CVS REPOSITORY!!!
cvs_version = (#version#)
@
"""

cvs_version_fname = os.path.join(cvs_path,'__cvs_version__.py,v')

###### Get previous version ######
if os.path.isfile(cvs_version_fname):
    f = open(cvs_version_fname,'r')
    rev_numbers_str = string.split(f.readline())[1][:-1]
    f.close()
    prev_rev_numbers = map(eval,string.split(rev_numbers_str,'.'))
    while len(prev_rev_numbers)<4:
        prev_rev_numbers = [1] + rev_numbers
else:
    prev_rev_numbers = [1,1,0,0]

##### Calculate new version ######
rev_numbers = prev_rev_numbers[:2]+[0,0]
os.path.walk(cvs_path,visit_cvs_tree,rev_numbers)

##### Update version ######
if rev_numbers[-2] != prev_rev_numbers[-2]:
    # E.g. a file have been added or removed.
    rev_numbers[-3] = rev_numbers[-3] + 1
revision = string.join(map(str,rev_numbers),'.')
version = string.join(map(str,rev_numbers),',')

##### Create new file __cvs_version__.py,v ####
cvs_version_py = string.replace(cvs_version_py_tmpl,'#version#',version)
cvs_version_py = string.replace(cvs_version_py,'#revision#',revision)

if os.path.exists(cvs_version_fname):
    os.remove(cvs_version_fname)
f = open(cvs_version_fname,'w')
f.write(cvs_version_py)
f.close()
os.chmod(cvs_version_fname, 0444)

#### EOF #####


More information about the Scipy-dev mailing list