Skip to content

Commit c09fe7f

Browse files
authored
Merge pull request #330 from SoftwareUnderstanding/dev
Fix #21 Fix #113 Fix #319
2 parents b9d171b + 778246c commit c09fe7f

6 files changed

Lines changed: 117 additions & 66 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Given a folder with code, `inspect4py` will:
1515
- Extract the hierarchy of directories and files.
1616
- Extract the requirements used in the software project.
1717
- Classify which files are tests
18-
- Classify the main type of software project (script, package, library or service). Only one type is returned as main type (e.g., if a library has the option to be deployed as a service, code_inspector will
18+
- Classify the main type of software project (script, package, library or service). Only one type is returned as main type (e.g., if a library has the option to be deployed as a service, `inspect4py` will
1919
- Return a ranking of the different ways in which a a software component can be run, ordered by relevance.
2020

2121

docs/index.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
1-
# code_inspector
1+
# inspect4py
22

33
Library to allow users inspect a software project folder (i.e., a directory and its subdirectories) and extract all the most relevant information, such as class, method and parameter documentation, classes (and their methods), functions, etc.
44

55
## Features
66

7-
Given a folder with code, `code_inspector` will:
7+
Given a folder with code, `inspect4py` will:
88

9-
- Extract all classes in the code
10-
- For each class, extract all its methods.
11-
- For each class, extract all its imported modules and how each module is imported as.
12-
- For each class and method, extract its documentation, including parameters, and accepted values.
13-
- Record the control flow of each file.
14-
- Requirement extraction from imported modules.
15-
- Extraction of the main method to invoke the software (ongoing work).
16-
- Extraction of the type of script or library that the code project is (e.g., a package, a service, a library, or a script).
9+
- Extract all imported modules and how each module is imported as (i.e., whether they are internal or external).
10+
- Extract all functions in the code, including their documentation, parameters, accepted values, and call list.
11+
- Extract all classes in the code, with all their methods and respective documentation
12+
- Extract the control flow of each file.
13+
- Extract the hierarchy of directories and files.
14+
- Extract the requirements used in the software project.
15+
- Classify which files are tests
16+
- Classify the main type of software project (script, package, library or service). Only one type is returned as main type (e.g., if a library has the option to be deployed as a service, `inspect4py` will
17+
- Return a ranking of the different ways in which a a software component can be run, ordered by relevance.
1718

18-
All metadata is extracted as a JSON file. See the [documentation](https://code-inspector.readthedocs.io/en/latest/output.html) for more details.
19+
All metadata is extracted as a JSON file. See the [documentation](https://inspect4py.readthedocs.io/en/latest/output.html) for more details.
1920

2021

2122
!!! warning
22-
`code_inspector` currently works **for Python projects only**. Some of its features (e.g., AST extraction) are only supported for Python 3.x projects.
23+
`inspect4py` currently works **for Python projects only**. Some of its features (e.g., AST extraction) are only supported for Python 3.x projects.
2324

2425
!!! info
25-
If you experience any issues when using code_inspector, please open an issue on our [GitHub repository](https://github.com/SoftwareUnderstanding/code_inspector/issues).
26+
If you experience any issues when using inspect4py, please open an issue on our [GitHub repository](https://github.com/SoftwareUnderstanding/inspect4py/issues).

docs/install.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
## Dependencies:
22

3-
code_inpsector uses [abstract syntax trees (ASTs)](https://en.wikipedia.org/wiki/Abstract_syntax_tree), more specifically
3+
inspect4py uses [abstract syntax trees (ASTs)](https://en.wikipedia.org/wiki/Abstract_syntax_tree), more specifically
44
the [ast](https://docs.python.org/3/library/ast.html) module in Python, generating a tree of objects (per file) whose classes all inherit from [ast.AST](https://docs.python.org/3/library/ast.html#ast.AST).
55

6-
code_inspector parses each of the input file(s) as an ast tree, and walks across them, extracting
6+
inspect4py parses each of the input file(s) as an ast tree, and walks across them, extracting
77
the relevant information, storing it as a JSON file. Furthermore, it also captures the control
88
flow of each input file(s), by using another two libraries:
99

@@ -16,7 +16,7 @@ flow of each input file(s), by using another two libraries:
1616

1717
For parsing the docstrings, we use [docstring_parser](https://pypi.org/project/docstring-parser/), which has support for ReST, Google, and Numpydoc-style docstrings. Some (basic) tests done using this library can be found at [here](./test_docstring_parser/).
1818

19-
It also usese [Pigar](https://github.com/damnever/pigar) for generating automatically the requirements of a given repository. This is an optional funcionality. In order to activate the argument (-r) has to be indicated when we run the code_inspector.
19+
It also usese [Pigar](https://github.com/damnever/pigar) for generating automatically the requirements of a given repository. This is an optional funcionality. In order to activate the argument (-r) has to be indicated when we run inspect4py.
2020

2121
## Install
2222

@@ -32,14 +32,20 @@ Then, prepare a virtual Python3 enviroment and install the required packages.
3232

3333
`pip install -r requirements.txt`
3434

35-
- Dependencies:
36-
- cdmcfparser==2.3.2
37-
- docstring_parser==0.7
38-
- astor
39-
- graphviz
40-
- Click
41-
- setuptools == 54.2.0
42-
- json2html
35+
Dependencies:
36+
```
37+
cdmcfparser
38+
docstring_parser==0.7
39+
astor
40+
graphviz
41+
click
42+
pigar
43+
setuptools==54.2.0
44+
json2html
45+
configparser
46+
```
47+
48+
If you want to run the evaluations, do not forget to add `pandas` to the previous set
4349

4450
### Installation through Docker
4551

@@ -48,28 +54,28 @@ First, you will need to have [Docker](https://docs.docker.com/get-started/) inst
4854
Next, clone this repository:
4955

5056
```
51-
git clone https://github.com/rosafilgueira/code_inspector/
57+
git clone https://github.com/SoftwareUnderstanding/inspect4py/
5258
```
5359

54-
Generate a Docker image for code_inspector:
60+
Generate a Docker image for inspect4py:
5561

5662
```
57-
docker build --tag inspector:1.0 .
63+
docker build --tag inspect4py:1.0 .
5864
```
5965

60-
Run code_inspector (you will have to copy the target data inside the image for analysis):
66+
Run inspect4py (you will have to copy the target data inside the image for analysis):
6167

6268
```
63-
docker run -it --rm --entrypoint "/bin/bash" inspector:1.0
69+
docker run -it --rm --entrypoint "/bin/bash" inspect4py:1.0
6470
```
6571

66-
And then run `code_inspector` following the commands outlined in the sections below
72+
And then run `inspect4py` following the commands outlined in the sections below
6773

6874

6975
Other useful commands when using Docker:
7076

7177
```
7278
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
73-
docker run -it --entrypoint "/bin/bash" inspector:1.0
74-
docker image rm -f inspector:1.0
79+
docker run -it --entrypoint "/bin/bash" inspect4py:1.0
80+
docker image rm -f inspect4py:1.0
7581
```

docs/output.md

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
* Results are stored by default inside the **OutputDir** directory, which is created automatically, if it is does not exits. Users have also the possibility to indicate their own directory name.
1+
`inspect4py` results are stored by default inside an `OutputDir` directory, which is created automatically if it is does not exits. Users have also the possibility to indicate their own directory name.
22

3-
* If the input is a **file**, the tool will create automatically two subdirectories inside **OuptuDir**:
4-
- **JsonFiles** directory: with a json file (with the name of the file + ".json") of the information extracted
5-
- **ControlFlow** directory: with one or two (depending on the FLAG_PNG) Control Flow files will be created
3+
If the input is a **file**, the tool will automatically create two subdirectories inside `OuptuDir`:
64

7-
* If the input is a **directory**, the tool will create the previous directories (**JsonFiles** and **ControlFlow**) but per **directory** and its **subdirectories** instead, under **OutputDir**, storing all the information extracted per file found in each directory and/or subdirectory. The **OutputDir** directory will have the same subdirectory structure as the input directory given by the user. Furthermore, in order to facilitate the inspection of all the features extracted for a given directory (and its subdirectories), we have aggreagated all the previous json information in a **single json file** stored at **OutputDir/DirectoryInfo.json**.In other words, **OutputDir/DirectoryInfo.json**, represents all the features extracted of all files found in a given directory (and its subdirectories).
5+
- **JsonFiles** directory: with a JSON file (with the name of the file + ".json") of the information extracted
6+
- **ControlFlow** directory: containing one or two control flow files depending on the execution options.
87

9-
### JSON FILE
8+
If the input is a **directory**, inspect4py will create the **JsonFiles** and **ControlFlow** directories for each **directory** in the original repository, under `OutputDir`. These folders store all the information extracted per file. The `OutputDir` directory will have the same subdirectory structure as the input directory given by the user. In order to ease the inspection of all the features extracted for a given directory (and its subdirectories) we have aggregated all generated json information in a **single JSON file** stored at `OutputDir/DirectoryInfo.json`.In other words, `OutputDir/DirectoryInfo.json`, represents all the features extracted of all files found in a given directory (and its subdirectories).
109

11-
* File features:
10+
## JSON file format
11+
12+
### File features:
1213
```
1314
- file:
1415
- path: <file_name>.py
@@ -20,7 +21,7 @@
2021
- full
2122
2223
```
23-
* Dependencies features:
24+
### Dependency features:
2425
```
2526
- dependencies: (list of dependencies)
2627
-dep_<0>:
@@ -34,7 +35,7 @@
3435
-dep_<1>:
3536
- ...
3637
```
37-
* Classes features:
38+
### Class features:
3839
```
3940
- classes: (list of classes)
4041
-<class_name>:
@@ -84,8 +85,7 @@
8485
- ...
8586
```
8687

87-
88-
* Function features:
88+
### Function features:
8989

9090
```
9191
- functions: (list of functions found within the class):
@@ -123,24 +123,62 @@
123123
-<function_name>:
124124
- ...
125125
```
126-
* ControlFlow features:
126+
### ControlFlow features:
127127
```
128128
- controlflow:
129129
- cfg: Path of the cfg as a txt
130130
- png: Path of the cfg as a PNG
131-
131+
```
132+
### Test information:
133+
```
134+
"tests": [
135+
{
136+
"type": "test",
137+
"run": "python path_to_test/test.py",
138+
"has_structure": "main", # (if the test has a main function)
139+
"mentioned_in_readme": false # (if the test is not mentioned
140+
the main README file)
141+
},
142+
143+
],
144+
```
145+
### Software invocation:
146+
```
147+
"software_invocation": [
148+
{
149+
"run": [
150+
"somef"
151+
],
152+
"type": "package", # Types include package, library, service,
153+
and script
154+
"installation": "pip install somef",
155+
"ranking": 1 # Relevance sorted in ascending order
156+
},
157+
{
158+
"type": "script",
159+
"run": "python path_to_script/script.py",
160+
"has_structure": "main",
161+
"mentioned_in_readme": false,
162+
"ranking": 2
163+
},
164+
],
165+
```
166+
### Software type:
167+
```
168+
"software_type": "package"
132169
```
133170
## Example
134171

135-
The easiest example is to run `code_inspector` against itself:
172+
The easiest example is to run `inspect4py` against itself:
136173

137-
`python code_inspector.py -i code_inspector.py -f`
174+
`inspect4py -i path_to_github_repo/inspect4py -f`
138175

139176

140177
Results of this run include a JSON file and a control flow file
141178

142-
If no output directory is specified, `code_inspector` will place the documentation in **OuptuDir**, including a JSON File and a control flow file for each code file found in the analyzed directory.
179+
If no output directory is specified, `inspect4py` will place the documentation in **OuptuDir**, including a JSON File and a control flow file for each code file found in the analyzed directory.
143180

181+
<!--
144182
## Visualizing results
145183
146184
We include visualization tools to explore the results in an easy manner. Below we show some visualizations of the results for `code_inspector` code:
@@ -156,4 +194,6 @@ python code_visualization.py OutputDir/JsonFiles/<FILE>.json
156194
157195
### Example 2: visualizing code_inspector.py
158196
159-
![visualization_code_inspector](images/visual_code_inspector.png)
197+
![visualization_code_inspector](images/visual_code_inspector.png)
198+
199+
-->

docs/usage.md

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,23 @@
1-
The tool can be executed to inspect a file, or all the files of a given directory (and its subdirectories).
1+
Inspect4py can be executed to inspect a file, or all the files of a given directory (and its subdirectories).
22
For example, it can be used to inspect all the python files of a given GitHub repository (that has been previously cloned locally).
33

4-
The tool by default stores the results in the "OutputDir" directory, but users can specify their own directory name by using -o or --output flags.
5-
6-
And the tools allows users to specify if control flow figures will be generated or not. By default they wont be generated. To indicate the generation of control flow figures, users should use -f or --fig.
4+
The tool by default stores the results in the "OutputDir" directory, but users can specify their own directory name by using `-o` or `--output` flags.
75

6+
And the tools allows users to specify if control flow figures will be generated or not. By default they wont be generated. To indicate the generation of control flow figures, users should use `-f` or `--fig`.
87

98
```
10-
python code_inspector.py --input_path <FILE.py | DIRECTORY>
11-
[--fig ,
12-
--output_dir "OutputDir",
13-
--ignore_dir_pattern "__",
14-
--ignore_file_pattern "__"
15-
--requirements
16-
--html_output]
9+
inspect4py --input_path <FILE.py | DIRECTORY> [--fig , --output_dir "OutputDir", --ignore_dir_pattern "__", ignore_file_pattern "__" --requirements --html_output]
1710
```
1811

12+
1913
For clarity, we have added the help option to explain each input parameters
2014

21-
```
22-
python code_inspector.py --help
23-
Usage: code_inspector.py [OPTIONS]
15+
```inspect4py --help
16+
17+
Usage: inspect4py [OPTIONS]
2418
2519
Options:
20+
--version Show the version and exit.
2621
-i, --input_path TEXT input path of the file or directory to
2722
inspect. [required]
2823
-f, --fig activate the control_flow figure generator.
@@ -42,6 +37,15 @@ Options:
4237
-r, --requirements find the requirements of the repository.
4338
-html, --html_output generates an html file of the DirJson in the
4439
output directory.
40+
-cl, --call_list generates the call list in a separate html
41+
file.
42+
-cf, --control_flow generates the call graph for each file in a
43+
different directory.
44+
-dt, --directory_tree captures the file directory tree from the
45+
root path of the target repository.
46+
-si, --software_invocation generates which are the software
47+
invocation commands to run and test the
48+
target repository.
4549
--help Show this message and exit.
4650
4751
```

inspect4py/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ def extract_requirements(input_path):
9191
# Answering yes (echo y), we allow searching for PyPI
9292
# for the missing modules and filter some unnecessary modules.
9393

94-
# cmd = 'echo y | pigar -P ' + input_path + ' --without-referenced-comments -p ' + file_name
95-
cmd = 'echo n | pigar -P ' + input_path + ' --without-referenced-comments -p ' + file_name
94+
cmd = 'echo y | pigar -P ' + input_path + ' --without-referenced-comments -p ' + file_name
95+
# cmd = 'echo n | pigar -P ' + input_path + ' --without-referenced-comments -p ' + file_name
9696
# print("cmd: %s" %cmd)
9797
proc = subprocess.Popen(cmd.encode('utf-8'), shell=True, stdin=subprocess.PIPE,
9898
stdout=subprocess.PIPE, stderr=subprocess.PIPE)

0 commit comments

Comments
 (0)