• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

pysonar2: PySonar2: an advanced semantic indexer for Python

原作者: [db:作者] 来自: 网络 收藏 邀请

PySonar2 - an advanced semantic indexer for Python

PySonar2 is a semantic indexer library for Python, designed for batch processing of large codebases.

To create high accuracy and quality index of Python, which is very dynamic language, PySonar2performs (costly) whole-project interprocedural analysis to infer types of variables, parameters andfunctions. Because of this, PySonar2 generally produces better index than Python IDEs (such asPyCharm etc.), while at the same time sacraficing real-time indexing abilities of IDEs.

PySonar2 has been the underlying indexing engine for several large-scale code navigation services,such as Google's internal Code Search service, Sourcegraph.com and Insight.io (now part ofElasticsearch). It has been used to index millions of lines of Python code.

How to build

mvn package

Demo

To have a feel of what PySonar2 produce, you can build a simple code browser of the Python 2.7standard library with the following command line:

java -jar target/pysonar-<version>.jar /usr/lib/python2.7 ./html

This may take a few minutes depending on your machine. You should find some interactive HTML filesinside the html directory after this process. You can move your mouse on the variables and clickon them to jump to definitions etc.

Note that this is just a simple demo program based on the library. PySonar2 is not meant to be anend-user tool. It is mainly designed as a library for Python IDEs, developer tools and code searchengines, so its interface may not be as appealing as an end-user tool.

If you have problems with it, please feel free to contact me.

System requirements

  • Python 2.7.x
  • Python 3.x
  • Java 8+
  • maven

Environment variables

PySonar2 uses CPython's built-in ast package to parse Python code, so please make sure you havepython or python3 installed and pointed to by the PATH environment variable. If you have themin different names, please make symbol links.

PYTHONPATH environment variable is used for locating the Python standard libraries. It isimportant to point it to the correct Python library, for example

export PYTHONPATH=/usr/lib/python2.7

If this is not set up correctly, references to library code will not be found.

Contribute

You are welcome to make code contributions.

Because of the highly complex and unpublished theory behind PySonar2, things may go wrong easilywith even an innocent-looking change. If you hope to contribute to PySonar2, please discuss with mefirst before making significant changes, otherwise I may not be able to review your changes.

For basic verification, you can run the unit tests. PySonar2 has a basic test framework. You can runthe tests using this command:

mvn test

If you modify the code or tests, you need to generate new expected results. Run these command lines:

mvn package -DskipTestsjava -classpath target/pysonar-<version>.jar org.yinwang.pysonar.TestInference -generate tests

To write new tests, you just need to write relevant Python code demonstrating your change, put theminto a directory named tests/testname.test(test directory name must end with ".test"). Please lookat the tests directory for examples.

Please don't expect the tests to catch all bugs. Be very careful :)

License

Apache 2.0 License. See LICENSE file.


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
sonar-l10n-zh: Chinese Pack for SonarQube发布时间:2022-02-13
下一篇:
sonar-pmd: sonar的pmd插件结合p3c(阿里规约)发布时间:2022-02-13
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap