How to do Code Analysis for Python Inheritance? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am searching for days to get the class hierarchy such as super and subclasses of any class (along with file path and line number, method over-rides references) something like code analysis of the project. The same functionality as PyCharm editor does. It will be a great help if someone can guide me on how to achieve this

If you want to run a sort of code-analysis on Python, firstly you should remember Python is a dynamically-typed language, which means types are inferred.
In Python, everything is an object. Which means all your class definitions are also objects. You can use the ast module to parse any source file (.py) into an Abstract Syntax Tree. In this AST, you'll be able to see relationships between names. However, bear in mind that the ast module is intraprocedural , which means that if you want to build a complex interprocedural code analysis, you'll need some heavy working to do, specially when it comes to solving aliases problems, among countless other things. Then again, you'll never know the types of each name in the ast.
If you delve into this quest, you should extend the ast module to implement your own NodeVisitor, a class that will execute some routine in every node of your AST. Check more info here

Related

How to convert python script to pascal script? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I have app that need Inno Setup to pack it. And aslo i need to write some Pascal code in [Code] section.The problem is that i am very familiar with python but not familiar with Pascal,So i want to know it's there have any tool covert python code to pascal code, or some other methods, thanks.
Unfortunately you won't be able to directly convert python code to pascal
Python is a dynamically typed interpreted language, whereas Pascal is a statically typed compiled language. This means that any converter would need to know the type of every variable used in your python script, which can change throughout a script.
Providing you know the typings of your python code your easiest solution if the Pascal is 100% required would be to go through your python line by line and re-write in Pascal using online resources to find the equivalant syntaxes.
Some things won't convert cleanly due to changing of types mid script, these will need to be corrected.

Python tool to check all function usages within project [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I have a vague memory of this question being asked before somewhere in cyberspace but I can't find it again.
Say I have a file with a bunch of functions (and or classes) defined, but I know that some of them are not used anywhere in my project. Is there a tool to scan through my project to see which functions aren't being used?
I know I can do this individually for each function, using Pycharm for example, but I don't know of a way to do this for all functions in a file. It feels like there must be a tool for this, but I don't know of one.
EDIT
I know there are edge cases of code, as pointed out by #deceze, that make this sort of usage checking impossible in general. But I'd be happy with a tool that works 99% of the time. The rest can be caught by unit tests for example, and manually handled.
I don't know about any tool that explores your whole project but you could easily make one in few lines of code by using the jedi library.
There is jedi.Script.usages which is exactly what you want here, the tool would do something like:
Create a jedi environment using your python interpreter of choice (this way will have information about sys.path
Walk over the project files you want to analize and extract the functions you want to check usages from (glob, os.walk, custom cli, ...)
On each file, you just need to extract the functions you want to analize (in your parser you store the locations as line/columns pairs)
Create a jedi script with the previous location and call usages and then store the results in a dictionary
Profit
PS: the most "tricky" step would be the one that extract functions from your python files but I guess this could also be done with jedi instead using another builtin python parsers, here's an untested piece of code:
for definition in jedi.names(source, all_scopes=True, definitions=True, references=True):
if definition.parent().type == "function": # The name is located in a function ...
ass = definition.goto_assignments()
if len(ass) > 0 and ass[0].parent().type == "function": # ... and is assigned to in a function
print("Found a local variable:", definition.name)
Extracted from this github issue
Coverage.py - used it recently to show my test coverage. But it can be used in other contexts as well

Looking for example or documentation for wikidump python lib [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
I stumbled upon the wikidump python library, which I think suits me just fine.
I could get by by looking at the source code, but I'm new at python and I don't want to write BS code as the project I need it for is kind of important to me.
I got the 'wiki-SPECIFICDATE-pages-articles.xml.bz2' file and I would need to use that as my source for single article fetching. Can anyone give me some pointers as to properly achieve this or, even better, point at some documentation? I couldn't find any!
(p.s. if you got any better and properly doc'd lib, please tell me)
Not sure if I understand the question, but if you have the Wikipedia dump and you need to parse the wikicode, I would suggest mwparserfromhell lib.
Another powerful framework is Pywikibot, that is the historic framework for bot users on Wikipedia (thus, it has many scripts dedicated to writing pages, instead of reading and parsing articles). It has a lot of documentation (though, sometimes obsolete) and it uses MediaWiki API.
You can use them both, of course: PWB for fetching articles and mwparserfromhell for parsing.

What is a good configuration file library for c thats not xml (preferably has python bindings)? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I am looking for a good config file library for c that is not xml. Optimally I would really like one that also has python bindings. The best option I have come up with is to use a JSON library in both c and python. What would you recommend, or what method of reading/writing configuration settings do you prefer?
YaML :)
If you're not married to Python, try Lua. It was originally designed for configuration.
You could use a pure python solution like ConfigObj and then simply use the CPython API to query for settings. This assumes that your application embeds Python. If it doesn't, and if you are shipping Python anyway, it might make sense to just embed it. Your C .exe won't get that much bigger if it's a dynamic link, and you will have all the flexibility of Python at your disposal.
Despite being hated by techies and disowned by Microsoft, INI files are actually quite popular with users, as they are easy to understand and edit. They are also very simple to write parsers for, should your libraries not already support them.

Python tool that builds a dependency diagram for methods of a class [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 3 years ago.
Improve this question
I'm digging into a huge legacy Python class that has a lot of methods. I eventually break complex ones into smaller pieces so the amount of methods increases even more. I wonder if there is a tool that can scan the Python code and build some kind of dependency diagram for its methods.
I define method x() to be a dependency of method y() if x() is called at least once in y().
I could use such a tool to isolate (if possible) subsets of class methods that have no external dependencies (all their dependencies are methods from the same subset).
I'm planning to move some functionality into other classes and I think that such an approach would help me to decide which parts to extract from the initial huge class.
Edit: I would really like a command-line tool.
Have you looked at Snakefood yet? It looks like it's exactly what you're looking for.
Have you tried pydev? It's a python extension for eclipse. I believe it allows you to use the "call hierarchy" feature of Eclipse to view a call graph for a given method. It's not quite what you want but maybe it's enough to get started.
Pycallgraph should do what you are looking for.
Just started using pydeps and so far it works well.
i was confuse in this question too,i have found a search helper help me to find the call hierarchy in another way. not very good but better than donot have. sorry about my english.
ps.IDE eclipse+pydev

Categories