Voltar ao ranking

yinwang0/pysonar2

Java

PySonar2: a semantic indexer for Python with interprocedual type inference

pythonindexcode-searchcode-intelligencecode-analysisstatic-analysistype-inference
Crescimento de estrelas
Estrelas
1.4k
Forks
499
Crescimento semanal
Issues
0
5001k
out. de 2013jan. de 2018abr. de 2022jul. de 2026
ArtefatosMavengit clone https://github.com/yinwang0/pysonar2.git
README

PySonar2 - a type inferencer and indexer library for Python

PySonar2 is a type inferencer and indexer library for Python, designed for analysing large code bases. The resulting index can be used to build code browsers and code search engines.

PySonar2 has a sophisticated type system and whole-project interprocedural analysis to infer types and locate definitions. It handles first-class functions (closures) and control flow correctly. As a result, the accuracy of the index often outperforms Python IDEs such as PyCharm.

PySonar2 uses advanced analysis techniques similar to control-flow analysis (k-CFA, CFA2, etc), but with a much simpler theory and without their drawbacks. It is both highly accurate and highly performant, thus it became the choice of several large scale code index infrastructures,

Major users include:

  • Google
  • Sourcegraph
  • Insight.io (now part of Elastic)

How to build

mvn package -DskipTests

Demo

To have a feel of what PySonar2 produce, you can build a simple code browser of the Python 2.7 standard 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 files inside the html directory after this process. You can move your mouse on the variables and click on 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 an end-user tool. It is mainly designed as a library for Python IDEs, developer tools and code search engines, 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 have python or python3 installed and pointed to by the PATH environment variable. If you have them in different names, please make symbol links.

PYTHONPATH environment variable is used for locating the Python standard libraries. It is important 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 easily with even an innocent-looking change. If you hope to contribute to PySonar2, please discuss with me first 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 run the 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 -DskipTests
java -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 them into a directory named tests/testname.test(test directory name must end with ".test"). Please look at 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.

Repositórios relacionados
donnemartin/system-design-primer

Learn how to design large-scale systems. Prep for the system design interview. Includes Anki flashcards.

PythonPyPIOtherprogrammingdevelopment
358.7k57.3k
vinta/awesome-python

An opinionated list of Python frameworks, libraries, tools, and resources

PythonPyPIOtherawesomepython
awesome-python.com
309.6k28.4k
practical-tutorials/project-based-learning

Curated list of project-based tutorials

PythonPyPIMIT Licensetutorialproject
274.6k35.4k
TheAlgorithms/Python

All Algorithms implemented in Python

PythonPyPIMIT Licensepythonalgorithm
thealgorithms.github.io/Python/
223k50.9k
tensorflow/tensorflow

An Open Source Machine Learning Framework for Everyone

C++Apache License 2.0tensorflowmachine-learning
tensorflow.org
196.5k75.7k
Significant-Gravitas/AutoGPT

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

PythonPyPIOtheraiopenai
agpt.co
185.6k46.1k
CyC2018/CS-Notes

:books: 技术面试必备基础知识、Leetcode、计算机操作系统、计算机网络、系统设计

algorithmleetcode
cyc2018.xyz
184.8k50.8k
yt-dlp/yt-dlp

A feature-rich command-line audio/video downloader

PythonPyPIThe Unlicenseyoutube-dlpython
discord.gg/H5MNcFW63r
179.4k15.3k
521xueweihan/HelloGitHub

:octocat: 分享 GitHub 上有趣、入门级的开源项目。Share interesting, entry-level open source projects on GitHub.

PythonPyPIgithubhellogithub
hellogithub.com
166.5k12.4k
huggingface/transformers

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

PythonPyPIApache License 2.0nlpnatural-language-processing
huggingface.co/transformers
162.8k34k
langgenius/dify

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

TypeScriptnpmOtheraigpt
dify.ai
149.7k23.6k
langchain-ai/langchain

The agent engineering platform.

PythonPyPIMIT Licenseaianthropic
docs.langchain.com/langchain/
142.3k23.7k