Re: Metrics 0.1a3

7 views
Skip to first unread message

Fink Mark

unread,
May 31, 2010, 4:58:15 AM5/31/10
to Sebastien Douche, testing-so...@googlegroups.com
Hi Sebastian,

many thanks for your interest in the metrics package.

On Sun, May 23, 2010 at 7:06 PM, Sebastien Douche <sdo...@gmail.com> wrote:
Hi Mark,
I'm very interested by your project. Why do not activate a bugtracker
on bitbucket ?
We have a forum at testing-so...@googlegroups.com to discuss problems and improvements. But also other testing related topics.
 

Here a small bug when you launch metrics on a directory :
sdouche@fou-hi:~$ metrics
~/src/sact/unstable/sact.nova/nova/sact.net/src/sact/net/
[Errno 21] Is a directory:
'/home/sdouche/src/sact/unstable/sact.nova/nova/sact.net/src/sact/net/'
-- Skipping input file.

Metrics Summary:
Files                       Language        SLOC Comment McCabe
----- ------------------------------ ----------- ------- ------
----- ------------------------------ ----------- ------- ------
Traceback (most recent call last):
 File "/usr/local/bin/metrics", line 5, in <module>
   pkg_resources.run_script('metrics==0.1a3', 'metrics')
 File "/usr/local/lib/python2.6/dist-packages/distribute-0.6.10-py2.6.egg/pkg_resources.py",
line 461, in run_script
   self.require(requires)[0].run_script(script_name, ns)
 File "/usr/local/lib/python2.6/dist-packages/distribute-0.6.10-py2.6.egg/pkg_resources.py",
line 1194, in run_script
   execfile(script_filename, namespace, namespace)
 File "/usr/local/lib/python2.6/dist-packages/metrics-0.1a3-py2.6.egg/EGG-INFO/scripts/metrics",
line 9, in <module>
   sys.exit(main())
 File "/usr/local/lib/python2.6/dist-packages/metrics-0.1a3-py2.6.egg/metrics/metrics.py",
line 124, in main
   process(context)
 File "/usr/local/lib/python2.6/dist-packages/metrics-0.1a3-py2.6.egg/metrics/metrics.py",
line 205, in process
   display_metrics(context, metric_instance, '%5d' % total['file_count'],
KeyError: 'file_count'

I hope you will agree with me that this is not a bug. The original PyMetrics package did not have this feature. I thought about adding something like that but I think it is impossible cover all the use cases and maintain an easy to use interface at the same time. There are many cases like hidden files and certain kind of file types you have want to ignore etc. That is the reason why I follow the unix type of interface. Consequently you provide files and not directories.

I hope you do not see this as a limitation since you can easily create a repository walker yourselves that suits your environment.
    def create_metrics(in_file_names):
# create the metrics from the current revision
context = {}
context['base'] = base
context['in_file_names'] = in_file_names
context['include_metrics'] = [
('sloc', 'SLOCMetric'), ('mccabe', 'McCabeMetric')]
context['quiet'] = True
context['verbose'] = False
res = metrics.process(context)
return res

def process_revision(revision):
# change to revision and create metrics
print 'Processing revision : %s' % revision
# change repository to revision
hg.clean(repo, revision)

# collect files to process
epre = re.compile('|'.join([fnmatch.translate(ep)
for ep in exclude_pattern]))
files = [os.path.relpath(os.path.join(dp, name), base) for
(dp, dn, fn) in os.walk(base)
for name in fn
if not epre.match(os.path.relpath(os.path.join(dp, name), base))]
#files = [os.path.join(os.path.relpath(dp, base), name) for
# (dp, dn, fn) in os.walk(base) for name in fn]
#print 're pattern %s' % '|'.join([fnmatch.translate(ep)
# for ep in exclude_pattern])
print 'Number of files to process : %d' % len(files)
#print files
#in_file_names = [files[500], files[-1]]
in_file_names = files
revision_metrics = create_metrics(in_file_names)
post_metrics(revision_metrics, revision, url)

For a more complete walker sample visit:
http://bitbucket.org/markfink/testing-software/src/tip/visualizer/
 
Why do not include McCabe in the dict?
Yes, it is there.
 
 
A very interesting option is to add cobertura (xml format) output to
add metrics in Hudson.
Same thing as with the input. People would like all sorts of formats. PyMetrics had CSV, and SQL. I myself needed JSON, You want XML... I think that again it is very difficult to cover all the use cases in a satisfying way.
Nevertheless what you are asking for is a very common usecase. I am currently not working with Hudson, or Cobertura. What I can offer you is that if you provide some kind of specification of what you want, or a patch, I will cover this feature.
 
Btw, great to see this project

Many thanks for your feedback!


--
Sebastien Douche <sdo...@gmail.com>
Twitter: http://bit.ly/afkrK (agile, lean, python, open source)


Reply all
Reply to author
Forward
0 new messages