Skip to content

Commit dc7df90

Browse files
authored
Merge pull request #332 from SoftwareUnderstanding/dev
Preparing for 0.0.1 release
2 parents c09fe7f + cfd46fc commit dc7df90

7 files changed

Lines changed: 165 additions & 119 deletions

File tree

Dockerfile

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,10 @@
11
FROM python:3.7
22

3-
43
RUN apt update &&\
54
apt install -y git &&\
65
apt install -y graphviz
76

87
RUN pip install --upgrade pip
9-
RUN pip install graphviz
10-
RUN pip install cdmcfparser==2.3.2
11-
RUN pip install docstring_parser==0.7
12-
RUN pip install astor
13-
RUN pip install click
14-
15-
RUN useradd -ms /bin/bash code_user
16-
17-
ENV USER code_user
18-
ENV HOME /home/code_user
19-
20-
WORKDIR ${HOME}
218

22-
COPY ./inspect4py.py ${HOME}/.
23-
COPY ./code_visualization.py ${HOME}/.
24-
RUN mkdir ${HOME}/staticfg
25-
ADD ./staticfg ${HOME}/staticfg/.
9+
RUN git clone https://github.com/SoftwareUnderstanding/inspect4py
10+
RUN cd inspect4py && pip install -e .

Dockerfile_old

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
FROM python:3.7
2+
3+
4+
RUN apt update &&\
5+
apt install -y git &&\
6+
apt install -y graphviz
7+
8+
RUN pip install --upgrade pip
9+
RUN pip install graphviz
10+
RUN pip install cdmcfparser==2.3.2
11+
RUN pip install docstring_parser==0.7
12+
RUN pip install astor
13+
RUN pip install click
14+
15+
RUN useradd -ms /bin/bash code_user
16+
17+
ENV USER code_user
18+
ENV HOME /home/code_user
19+
20+
WORKDIR ${HOME}
21+
22+
COPY ./inspect4py.py ${HOME}/.
23+
COPY ./code_visualization.py ${HOME}/.
24+
RUN mkdir ${HOME}/staticfg
25+
ADD ./staticfg ${HOME}/staticfg/.

README.md

Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -15,35 +15,38 @@ 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, `inspect4py` 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 return `Library` as its main type)
1919
- Return a ranking of the different ways in which a a software component can be run, ordered by relevance.
2020

2121

2222
All metadata is extracted as a JSON file.
2323

2424

25-
Inspect4py currently works **only for Python projects**.
25+
Inspect4py currently works **only for Python 3 projects**.
2626

27-
## Dependencies:
27+
## Background:
2828

29-
It uses [AST](https://en.wikipedia.org/wiki/Abstract_syntax_tree), more specifically
29+
`inspect4py` uses [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree), more specifically
3030
the [ast](https://docs.python.org/3/library/ast.html) module in Python, generating
3131
a tree of objects (per file) whose classes all inherit from [ast.AST](https://docs.python.org/3/library/ast.html#ast.AST).
3232

33-
inspect4py parsers each of the input file(s) as an ast tree, and walks across them, extracting
34-
the relevant information, storing it as a JSON file. Furthermore, it also captures the control
35-
flow of each input file(s), by using another two libraries:
33+
`inspect4py` parses each of the input file(s) as an AST tree, extracting the relevant information and storing it as a JSON file. Furthermore, it also captures the control flow of each input file(s), by using another two libraries:
3634

37-
-[cdmcfparser](https://pypi.org/project/cdmcfparser/): The module provided functions can takes a file with a python code or a character buffer, parse it and provide back a hierarchical representation of the code in terms of fragments. Each fragment describes a portion of the input: a start point (line, column and absolute position) plus an end point (line, column and absolute position).
35+
- [cdmcfparser](https://pypi.org/project/cdmcfparser/): The module provided functions can takes a file with a python code or a character buffer, parse it and provide back a hierarchical representation of the code in terms of fragments. Each fragment describes a portion of the input: a start point (line, column and absolute position) plus an end point (line, column and absolute position).
3836

39-
-[staticfg](inspect4py/staticfg): StatiCFG is a package that can be used to produce control flow graphs (CFGs) for Python 3 programs. The CFGs it generates can be easily visualised with graphviz and used for static analysis. We have a flag in the code (FLAG_PNG) to indicate if we want to generate this type of control flow graphs or not. **Note**: The original code of this package can be found [here](https://github.com/coetaur0/staticfg), but given a bug in the package's source code, we forked it, and fixed it in our [repository](inspect4py/staticfg)
37+
- [staticfg](inspect4py/staticfg): StatiCFG is a package that can be used to produce control flow graphs (CFGs) for Python 3 programs. The CFGs it generates can be easily visualised with graphviz and used for static analysis. We have a flag in the code (FLAG_PNG) to indicate if we want to generate this type of control flow graphs or not. **Note**: The original code of this package can be found [here](https://github.com/coetaur0/staticfg), which has been fixed it in our [repository](inspect4py/staticfg)
4038

41-
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/).
39+
We also 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/).
4240

43-
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 inspect4py.
41+
Finally, we reuse [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 running inspect4py.
4442

4543
## Install
4644

45+
### Python version
46+
We have tested `inspect4py` in Python 3.7+. **Our recommended version is Python 3.7**.
47+
48+
**Support in Python 3.9**: We have detected that `cdmcfparser` has issues in Python 3.9+. Therefore **the `-cf` command is not guaranteed in Python 3.9**. All other commands have been tested successfully in Python 3.9+.
49+
4750
### Installation from code
4851

4952
First, make sure you have graphviz installed:
@@ -56,64 +59,97 @@ Then, prepare a virtual Python3 enviroment, `cd` into the `inspect4py` folder an
5659

5760
`pip install -e .`
5861

59-
### Dependencies:
60-
- cdmcfparser==2.3.2
61-
- docstring_parser==0.7
62-
- astor
63-
- graphviz
64-
- Click
65-
- setuptools == 54.2.0
66-
- json2html
62+
You are done!
63+
64+
### Package dependencies:
65+
```
66+
cdmcfparser
67+
docstring_parser==0.7
68+
astor
69+
graphviz
70+
click
71+
pigar
72+
setuptools==54.2.0
73+
json2html
74+
configparser
75+
```
76+
77+
If you want to run the evaluations, do not forget to add `pandas` to the previous set.
6778

6879
### Installation through Docker
6980

70-
First, you will need to have [Docker](https://docs.docker.com/get-started/) installed.
81+
You need to have [Docker](https://docs.docker.com/get-started/) installed.
7182

72-
Next, clone this repository:
83+
Next, clone the `inspect4py` repository:
7384

7485
```
7586
git clone https://github.com/SoftwareUnderstanding/inspect4py/
7687
```
7788

78-
Generate a Docker image for inspect4py:
89+
Generate a Docker image for `inspect4py`:
7990

8091
```
8192
docker build --tag inspect4py:1.0 .
8293
```
8394

84-
Run inspect4py (you will have to copy the target data inside the image for analysis):
95+
Run the `inspect4py` image:
96+
97+
```
98+
docker run -it --rm inspect4py:1.0 /bin/bash
99+
```
85100

101+
Now you can run `inspect4py`:
86102
```
87-
docker run -it --rm --entrypoint "/bin/bash" inspect4py:1.0
103+
root@e04792563e6a:/# inspect4py --help
88104
```
89105

90-
And then run `inspect4py` following the commands outlined in the sections below
106+
For more information about `inspect4py` execution options, please see the section below (Execution).
107+
108+
Note that when running `inspect4py` with Docker, you will need to need to provide a path to the target repository to analyze. You can do this by:
109+
110+
1. Cloning the target repository. For example:
91111

112+
```
113+
docker run -it --rm inspect4py:1.0 /bin/bash
114+
# Docker image starts
115+
root@e04792563e6a:/# git clone https://github.com/repo/id
116+
root@e04792563e6a:/# inspect4py -i id
117+
```
118+
2. Creating a [volume](https://docs.docker.com/storage/volumes/). For example, for mounting the $PWD folder:
92119

120+
```
121+
docker run -it -v -v $PWD:/out --rm inspect4py:1.0 /bin/bash
122+
# Docker image starts
123+
root@e04792563e6a:/# inspect4py -i /out/path/to/repo
124+
```
125+
126+
<!--
93127
Other useful commands when using Docker:
94128
```
95129
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
96-
docker run -it --entrypoint "/bin/bash" inspect4py:1.0
97130
docker image rm -f inspect4py:1.0
98131
```
132+
-->
99133

100134
## Execution
101135

102136
The tool can be executed to inspect a file, or all the files of a given directory (and its subdirectories).
103137
For example, it can be used to inspect all the python files of a given GitHub repository (that has been previously cloned locally).
104138

105-
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.
139+
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.
106140

107-
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.
141+
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`.
108142

143+
<!--
109144
```
110145
inspect4py --input_path <FILE.py | DIRECTORY> [--fig , --output_dir "OutputDir", --ignore_dir_pattern "__", ignore_file_pattern "__" --requirements --html_output]
111146
```
147+
-->
112148

149+
For clarity, we have added a `help` command to explain each input parameter:
113150

114-
For clarity, we have added the help option to explain each input parameters
115-
116-
```inspect4py --help
151+
```
152+
inspect4py --help
117153
118154
Usage: inspect4py [OPTIONS]
119155
@@ -148,19 +184,8 @@ Options:
148184
invocation commands to run and test the
149185
target repository.
150186
--help Show this message and exit.
151-
152187
```
153188

154-
## Evaluation
155-
156-
Simply cd into the right directory and run it. You can do so with the following commands
157-
158-
```
159-
cd src/main_command_evaluation
160-
python3 run_directory_type_evaluation.py
161-
```
162-
163-
164189
## Documentation
165190

166191
For additional documentation and examples, please have a look at our [online documentation](https://inspect4py.readthedocs.io/en/latest/)

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Given a folder with code, `inspect4py` will:
1313
- Extract the hierarchy of directories and files.
1414
- Extract the requirements used in the software project.
1515
- 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
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 return `Library` as its main type)
1717
- Return a ranking of the different ways in which a a software component can be run, ordered by relevance.
1818

1919
All metadata is extracted as a JSON file. See the [documentation](https://inspect4py.readthedocs.io/en/latest/output.html) for more details.

docs/install.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
1-
## Dependencies:
1+
## Background:
22

3-
inspect4py uses [abstract syntax trees (ASTs)](https://en.wikipedia.org/wiki/Abstract_syntax_tree), more specifically
4-
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).
3+
`inspect4py` uses [ASTs](https://en.wikipedia.org/wiki/Abstract_syntax_tree), more specifically
4+
the [ast](https://docs.python.org/3/library/ast.html) module in Python, generating
5+
a tree of objects (per file) whose classes all inherit from [ast.AST](https://docs.python.org/3/library/ast.html#ast.AST).
56

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

10-
-[cdmcfparser](https://pypi.org/project/cdmcfparser/): The module provided functions can takes a file with a python code or a character buffer, parse it and provide back a hierarchical representation of the code in terms of fragments. Each fragment describes a portion of the input: a start point (line, column and absolute position) plus an end point (line, column and absolute position).
9+
- [cdmcfparser](https://pypi.org/project/cdmcfparser/): The module provided functions can takes a file with a python code or a character buffer, parse it and provide back a hierarchical representation of the code in terms of fragments. Each fragment describes a portion of the input: a start point (line, column and absolute position) plus an end point (line, column and absolute position).
1110

12-
-[staticfg](./staticfg): StatiCFG is a package that can be used to produce control flow graphs (CFGs) for Python 3 programs. The CFGs it generates can be easily visualised with graphviz and used for static analysis. We have a flag in the code (FLAG_PNG) to indicate if we want to generate this type of control flow graphs or not.
11+
- [staticfg](inspect4py/staticfg): StatiCFG is a package that can be used to produce control flow graphs (CFGs) for Python 3 programs. The CFGs it generates can be easily visualised with graphviz and used for static analysis. We have a flag in the code (FLAG_PNG) to indicate if we want to generate this type of control flow graphs or not. **Note**: The original code of this package can be found [here](https://github.com/coetaur0/staticfg), which has been fixed it in our [repository](inspect4py/staticfg)
1312

14-
!!! info
15-
The original code of this package can be found [here](https://github.com/coetaur0/staticfg), but given a bug in the package's source code, we forked it, and fixed it in our [repository](./staticfg)
13+
We also 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/).
1614

17-
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/).
18-
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.
15+
Finally, we reuse [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 running inspect4py.
2016

2117
## Install
2218

@@ -28,11 +24,13 @@ First, make sure you have graphviz installed:
2824
sudo apt-get install graphviz
2925
```
3026

31-
Then, prepare a virtual Python3 enviroment and install the required packages.
27+
Then, prepare a virtual Python3 enviroment, `cd` into the `inspect4py` folder and install the package as follows:
28+
29+
`pip install -e .`
3230

33-
`pip install -r requirements.txt`
31+
You are done!
3432

35-
Dependencies:
33+
### Package dependencies:
3634
```
3735
cdmcfparser
3836
docstring_parser==0.7
@@ -49,33 +47,46 @@ If you want to run the evaluations, do not forget to add `pandas` to the previou
4947

5048
### Installation through Docker
5149

52-
First, you will need to have [Docker](https://docs.docker.com/get-started/) installed.
50+
You need to have [Docker](https://docs.docker.com/get-started/) installed.
5351

54-
Next, clone this repository:
52+
Next, clone the `inspect4py` repository:
5553

5654
```
5755
git clone https://github.com/SoftwareUnderstanding/inspect4py/
5856
```
5957

60-
Generate a Docker image for inspect4py:
58+
Generate a Docker image for `inspect4py`:
6159

6260
```
6361
docker build --tag inspect4py:1.0 .
6462
```
6563

66-
Run inspect4py (you will have to copy the target data inside the image for analysis):
64+
Run the `inspect4py` image:
65+
66+
```
67+
docker run -it --rm inspect4py:1.0 /bin/bash
68+
```
6769

70+
Now you can run `inspect4py`:
6871
```
69-
docker run -it --rm --entrypoint "/bin/bash" inspect4py:1.0
72+
root@e04792563e6a:/# inspect4py --help
7073
```
7174

72-
And then run `inspect4py` following the commands outlined in the sections below
75+
For more information about `inspect4py` execution options, please see the [usage section](https://inspect4py.readthedocs.io/en/latest/usage/).
76+
77+
Note that when running `inspect4py` with Docker, you will need to need to provide a path to the target repository to analyze. You can do this by:
7378

79+
1. Cloning the target repository. For example:
7480

75-
Other useful commands when using Docker:
81+
```
82+
docker run -it --rm inspect4py:1.0 /bin/bash
83+
# Docker image starts
84+
root@e04792563e6a:/# git clone https://github.com/repo/id
85+
root@e04792563e6a:/# inspect4py -i id
86+
```
87+
2. Creating a [volume](https://docs.docker.com/storage/volumes/). For example, for mounting the $PWD folder:
7688

7789
```
78-
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
79-
docker run -it --entrypoint "/bin/bash" inspect4py:1.0
80-
docker image rm -f inspect4py:1.0
81-
```
90+
docker run -it -v -v $PWD:/out --rm inspect4py:1.0 /bin/bash
91+
# Docker image starts
92+
root@e04792563e6a:/# inspect4py -i /out/path/to/repo

0 commit comments

Comments
 (0)