Eclipse PyDev 项目中的代码行

发布于 2024-09-08 16:26:36 字数 250 浏览 10 评论 0原文

我想知道是否有人在非 Java 项目中使用 Eclipse Metrics 插件(特别是我我正在尝试为几个 PyDev 项目生成代码指标)。我已经阅读了 Metrics 项目的演练,但它表明我应该在访问项目的属性之前进入 Java 透视图,并且我应该找到 Metrics 部分。无论我打开哪个视角,我的 PyDev 项目都没有得到这一点。任何建议或意见都会很棒。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

新人笑 2024-09-15 16:26:36

我不知道是否可以让插件与 pydev 项目一起使用,但如果它只是您所追求的 lines-of-code 指标,您可以在项目的根目录中运行此代码段:

# 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)

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)
原谅过去的我 2024-09-15 16:26:36

如果您使用的是 Linux...

您看过 cloc 吗?

它产生相当完整的输出,并接受几个选项:

borrajax@borrajax-linux:~/Documents/Projects/myProject$ cloc .
    1840 text files.
    1566 unique files.                                          
    9362 files ignored.

http://cloc.sourceforge.net v 1.53  T=3.0 s (454.3 files/s, 81397.0 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Javascript                      709          19190          17283          93862
Python                          333           6278           3399          38398
C                                86           3244           2303          17755
CSS                             122           1786           1592          16856
HTML                             55            784             51           8072
Bourne Shell                     14            651            280           6641
C/C++ Header                      6            301            293           1259
XML                               9              5              0           1153
PHP                               2             88            211            585
SQL                              19            200            127            576
Bourne Again Shell                2             57             15            494
make                              5             41             19            187
DOS Batch                         1             21              1            133
--------------------------------------------------------------------------------
SUM:                           1363          32646          25574         185971
--------------------------------------------------------------------------------

它也可以在 Ubuntu 存储库中找到。

If you are in Linux...

Have you taken a look to cloc?

It produces pretty complete outputs, and accepts several of options:

borrajax@borrajax-linux:~/Documents/Projects/myProject$ cloc .
    1840 text files.
    1566 unique files.                                          
    9362 files ignored.

http://cloc.sourceforge.net v 1.53  T=3.0 s (454.3 files/s, 81397.0 lines/s)
--------------------------------------------------------------------------------
Language                      files          blank        comment           code
--------------------------------------------------------------------------------
Javascript                      709          19190          17283          93862
Python                          333           6278           3399          38398
C                                86           3244           2303          17755
CSS                             122           1786           1592          16856
HTML                             55            784             51           8072
Bourne Shell                     14            651            280           6641
C/C++ Header                      6            301            293           1259
XML                               9              5              0           1153
PHP                               2             88            211            585
SQL                              19            200            127            576
Bourne Again Shell                2             57             15            494
make                              5             41             19            187
DOS Batch                         1             21              1            133
--------------------------------------------------------------------------------
SUM:                           1363          32646          25574         185971
--------------------------------------------------------------------------------

It is available in the Ubuntu repositories, as well.

征﹌骨岁月お 2024-09-15 16:26:36

在 Unix 上,您可以从终端运行以下命令:

find . -name '*.py' | xargs cat | egrep "[a-zA-Z0-9_{}]" | wc -l

如果您不想计算注释,则需要一个更好的正则表达式...

On Unix you can run the following from the terminal:

find . -name '*.py' | xargs cat | egrep "[a-zA-Z0-9_{}]" | wc -l

If you want to not count comments, you need a better regular expression...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文