Analyze Python source code using Python and Inspector - python

I'm developing a static analyzer tool in Python that analyzes Python code for a given .py file and extract the body of classes, methods, etc in order to analyze code metrics (methods size, inheritance, and so on).
I identified the library "Inspect" that seems to suit me. However, I noticed that all the examples provided in the official documentation and external website only use this library by passing concrete instances of objects or functions that they want to analyze; however, I would like to analyze the source code without creating concrete instances of them, to avoid possible compiler errors due to missing library or other factors.
There is possible alternative methods or libraries that I can try to do it?

Related

Analyzing 10k solidworks parts through python

I have been looking around on and off for the last week to see if anybody has performed this type of work. Unfortunately I have found very little that is python specific.
I have a repository with ~10k solidworks parts. I would like to analyse these files in batch and collect information like volume, material, etc, so to get some general statistical information. Ideally this would be in python but solutions in other languages are more than welcome.
Most answers I found are about creating addons in VB,C#, C++ to interact with Solidworks API but nothing about doing general statistical analysis of just the parts. I don't want to interact with the application or build features, I just want to look at what's inside the files without having Solidworks. I am also working on Linux which is not supported by Solidworks.
Нi, 6F4E37
I see two ways to get what you want from solidworks files, unfortunately they both involve Windows and C#/VB code.
Without SolidWorks application. Use SW Document manager - a
library that allows you to access meta information of your parts.
You will be able to get some information about your part including
volume.
I'm unaware of any attempts to run Document Manager on Wine, please
share your results if you'll try.
Note that Document manager library license is free, provided that
you have active SolidWorks subscription.
Using SolidWorks API. You don't have to create an add-in, you can
connect to solidworks from a standalone application :
SldWorks swApp = (SldWorks)Activator.CreateInstance(System.Type.GetTypeFromProgID("SldWorks.Application"));
Obviously for that approach you'll need to have solidowrks installed on your machine.
Also note that SolidWorks is not the most stable application, and it'll crash every 200-400 files that you process, so you you'll choose this approach you'll need to keep an eye on SolidWorks instance and restart it if needed.

Can I build and host custom HTML pages at Read the Docs?

My program’s documentation is mainly written in Sphinx, but it also includes two custom HTML pages:
an example report produced by the program;
an extended reference on certain features of the program.
These two HTML files are produced by the program itself, not by Sphinx.
I want to host my docs on Read the Docs, and it would be very convenient for me to build and host the two custom pages, versioned, together with the Sphinx docs.
My program is already installed in the RtD build environment as I have the Install Project option enabled. And since the RtD docs mention writing your own builder, I gather it might be possible to invoke my program from there and have it dump the HTML content in a specific place.
So I really have two questions:
Is this an appropriate use of Read the Docs? I guess it’s not designed to host arbitrary Web pages — but then again, those files are not arbitrary, they are an important part of the docs.
How would I implement it? I’m having a hard time making sense of the RtD API: is this “builder” related in any way to Sphinx builders? how do I hook it up to RtD? perhaps there is an example somewhere?
I achieved the desired result using Sphinx’s html_extra_path feature:
A list of paths that contain extra files [...] They are copied to the output directory.
To generate these files, I haven’t found a better place than right in my conf.py, which seems a bit precarious, but works so far. Of course, Install your project inside a virtualenv needs to be enabled in Read the Docs advanced settings.
Now my custom notices.html and showcase.html are treated just like the .html pages produced by Sphinx itself, with versioning and redirects: http://httpolice.readthedocs.io/page/notices.html

Python and JavaScript/AngularJS documentation on the one server?

The advantages of this approach include:
Consistent docstring syntax everywhere
Centralsied documentation server; find all your docs in one place
Search and jump-to-source from any documented function or class; in either language
Are there any modules integrating with Sphinx or similar; which generate+put your JavaScript and Python documentation in one place?
I am not sure if your question is about public documentation or in-house documentation of some of your projects.
For the former you want to see this: http://devdocs.io/
Also devdocs document scrapers are open source, so you should be able to use them for your own projects to build custom devdocs.io.

Produce documentation for Python functions

I was wondering if it's possible with Doxygen to generate documentation for Python methods as well. For example, I have a Flask web app that runs solely on functions, all these functions contain docstrings that I want to be generated into a nice format (with Doxygen), however currently I can only get it to do so for classes.
Is this possible?

How do I deal with conflicting names when building python docs with doxygen

I'm having a problem with Doxygen for Windows with Python where input files with the same failename cause a conflict wth the output files. This seems to be a bug in doxygen - is there a way to work-around this problem?
Background
We build docs for our API using Doxygen. Our project is overwhelmingly written in python and the only components that our clients care about are python. Due to accidents of history our classes often have unfortunate naming conventions.
For example we have a classes whose fully-qualified name are:
tools.b.foo.Foo
tools.b.bar.Bar
Later this class was re-implemented and put into a new module:
tools.c.foo.Foo_improved
tools.c.bar.Bar_improved
When we want to build our tools API documentation we have a process which checks out tools.* into a directory on the build-server and then we call doxygen with a fairly standard configuration file.
We'd expect that there should be four HTML files in the output, two for foo and two for bar. However what we get is only two files. Both sets of sripts are parsed, however since the module names are the same the documentation for the old version ends up over-writing the documentation which was generated for the new versions. As a result in every case where a python module name is duplicated (but in a different sub-package) we are only getting a single doc file for every file name.
FYI, we are using doxygen 1.7.1 on Windows XP 32bit with Python 2.4.4
Config file is here:
http://pastebin.me/002f3ec3145f4e1896a9cf79e7179493
UPDATE 1: In the generated doc index I can see entries for all four files, however if I follow the links to both Foo and Foo_improved both point to the same file.
You could try explicitly declaring a class w/ full namespace
http://www.doxygen.nl/manual/commands.html#cmdclass

Categories

Resources