Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Lines of Code in Eclipse PyDev Projects

I'm wondering if anyone has had any luck using the Eclipse Metrics Plugin with Projects that are not in Java (specifically I'm trying to generate code metrics for a couple of PyDev Projects). I've read through the walk-through for the Metrics project but it indicates that I should be in the Java Perspective before accessing the Properties for my Project and that I should find a Metrics section. I don't get that for my PyDev Projects regardless of which Perspective I have open. Any suggestions or advice would be great.

like image 818
g.d.d.c Avatar asked Jul 09 '10 15:07

g.d.d.c


People also ask

How do I run code in PyDev?

Go to the menu: Alt + R + S + The number of the Run you wish (It can be Python, Jython, unit-test, etc). Note: if you were using unit-tests, you could use: Ctrl+F9 to run the unit-tests from the module (and even selecting which tests should be run -- and if Shift is pressed it's launched in debug mode).

Can we write Python code in Eclipse?

Eclipse requires the PyDev extension to properly develop Python code. This tutorial covers installing both Eclipse and Pydev, then walks through the basics of the Eclipse interface. Other editors provide similar functionality, but we like Eclipse the best.

What is PyDev Eclipse?

PyDev is a third-party plug-in for Eclipse. It is an Integrated Development Environment (IDE) used for programming in Python supporting code refactoring, graphical debugging, code analysis among other features.


1 Answers

I don't know if it's doable to get the plugin to work with pydev projects, but if it's just the lines-of-code metric you are after, you could run this snippet in your project's root directory:

# prints recursive count of lines of python source code from current directory
# includes an ignore_list. also prints total sloc

import os
cur_path = os.getcwd()
ignore_set = set(["__init__.py", "count_sourcelines.py"])

loclist = []

for pydir, _, pyfiles in os.walk(cur_path):
    for pyfile in pyfiles:
        if pyfile.endswith(".py") and pyfile not in ignore_set:
            totalpath = os.path.join(pydir, pyfile)
            loclist.append( ( len(open(totalpath, "r").read().splitlines()),
                               totalpath.split(cur_path)[1]) )

for linenumbercount, filename in loclist: 
    print "%05d lines in %s" % (linenumbercount, filename)

print "\nTotal: %s lines (%s)" %(sum([x[0] for x in loclist]), cur_path)
like image 134
ChristopheD Avatar answered Oct 14 '22 06:10

ChristopheD