Skip to content

Commit 7d76eab

Browse files
Added linting script (#192)
* Added linting and flaking script Added a script that will provide automatic flaking and linting of the files. Fixes : #181 Signed-off-by: aujjwal-redhat <[email protected]> * Changed flaking to flake;Added a readme in scripts; Added the reference in the contributions Signed-off-by: aujjwal-redhat <[email protected]> * Added flags in the script Signed-off-by: aujjwal-redhat <[email protected]> * Changed the link in contributing.md file Signed-off-by: aujjwal-redhat <[email protected]> * Added the command to run the script in CONTRIBUTING.md file Signed-off-by: aujjwal-redhat <[email protected]> * removed r flag; no more needed Signed-off-by: aujjwal-redhat <[email protected]> * condition changes Signed-off-by: aujjwal-redhat <[email protected]> * Modified the help message Signed-off-by: aujjwal-redhat <[email protected]>
1 parent 19cc12a commit 7d76eab

File tree

11 files changed

+110
-2
lines changed

11 files changed

+110
-2
lines changed

CONTRIBUTING.md

+10-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,17 @@ autopep8 -i <PATH_TO_THE_FILE>/<filename>.py
2626
---
2727
**NOTE**
2828

29-
Along with this run pylint and flake8 manually as well and remove the errors. <br>
30-
To run the same:
29+
Run pylint and flake8 to check and remove the errors. <br>
30+
To execute the same:
3131

32+
### Using script:
33+
You can run the following command
34+
```js
35+
tools/linting.sh -p PATH/TO/FILE -l -f
36+
```
37+
To know more about the script, go [here](https://github.com/srijan-sivakumar/redant/blob/main/tools/README.md).
38+
39+
### Manually
3240
```js
3341
flake8 <PATH_TO_THE_FILE>/<filename>.py
3442
pylint -j 4 --rcfile=.pylintrc <PATH_TO_THE_FILE>/<filename>.py

__init__.py

Whitespace-only changes.

support/ops/__init__.py

Whitespace-only changes.

support/ops/gluster_ops/__init__.py

Whitespace-only changes.

support/ops/support_ops/__init__.py

Whitespace-only changes.

tests/example/__init__.py

Whitespace-only changes.

tests/example/sample_component/__init__.py

Whitespace-only changes.

tests/functional/__init__.py

Whitespace-only changes.

tests/functional/glusterd/__init__.py

Whitespace-only changes.

tools/README.md

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ where the test cases will reside will be tests/ . Once can provide a flag
1313
-nc if they want the TC suite to run faster as it won't clear the cache files.
1414
This scenario might come handy wherein a user might want to test out some code
1515
changes and see if it passes the sanity checks.
16+
17+
3. `linting.sh` : A BASH script helps in automating the linting process. Multiple flags for flake and lint are provided that gives the user the choice to perform any one or both. The path flag leverages the operation as the user can run the script to test the lint for one file or the whole repo. Run `tools/linting.sh -h` to know more.

tools/linting.sh

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/bash
2+
3+
FILEPATH='.'
4+
perform_linting () {
5+
if [[ $FILEPATH == '.' ]]
6+
then
7+
pylint -j 4 --rcfile=.pylintrc ./core
8+
pylint -j 4 --rcfile=.pylintrc ./core/parsing
9+
pylint -j 4 --rcfile=.pylintrc ./tests/example
10+
pylint -j 4 --rcfile=.pylintrc ./tests/example/sample_component
11+
pylint -j 4 --rcfile=.pylintrc ./tests/functional
12+
pylint -j 4 --rcfile=.pylintrc ./tests/functional/glusterd
13+
pylint -j 4 --rcfile=.pylintrc ./support
14+
pylint -j 4 --rcfile=.pylintrc ./support/ops/gluster_ops
15+
pylint -j 4 --rcfile=.pylintrc ./support/ops/support_ops
16+
else
17+
pylint -j 4 --rcfile=.pylintrc $FILEPATH
18+
fi
19+
}
20+
21+
help_info () {
22+
# Provides the help information
23+
# Describes the flags and their usage
24+
echo
25+
echo "Linting help"
26+
echo "============="
27+
echo "Flags:"
28+
echo "-p : Specifies the path of the file"
29+
echo " Ex: tools/linting.sh -p /home/redant/core"
30+
echo
31+
echo "-f : Specifies flake operation to be performed only"
32+
echo " Ex: If you want to test flake for core"
33+
echo " tools/linting.sh -p /home/redant/core -f"
34+
echo
35+
echo "-l : Specifies lint operation to be performed only"
36+
echo " Ex: If you want to test lint for core"
37+
echo " tools/linting.sh -p /home/redant/core -l"
38+
echo
39+
echo "-h : Provides the information about the flags"
40+
echo
41+
echo "Note:"
42+
echo "====="
43+
echo "If you don't specify the path, the operation will occur on the whole repo"
44+
echo
45+
echo "Ex: tools/linting.sh -f -l"
46+
echo "This will perform the linting on the whole repo"
47+
echo
48+
echo "Examples:"
49+
echo "========="
50+
echo "tools/linting.sh -f"
51+
echo "This will perform only flake on the folder"
52+
echo
53+
echo "tools/linting.sh -l"
54+
echo "This will perform only lint on the folder"
55+
echo
56+
echo "tools/linting.sh -p /home/redant/core -f -l"
57+
echo "This will perform linting on the folder"
58+
echo
59+
echo "tools/linting.sh -p /home/redant/core -f"
60+
echo "This will perform only flake operation on the folder"
61+
echo
62+
echo "tools/linting.sh -p /home/redant/core -l"
63+
echo "This will perform only lint operation on the folder"
64+
echo
65+
echo "tools/linting.sh -[wrong flag]"
66+
echo "This will show illegal action"
67+
}
68+
69+
while getopts "p:flh" opt; do
70+
case $opt in
71+
p)
72+
if [[ $OPTARG == '' ]]
73+
then
74+
echo "No path specified."
75+
echo "Linting the whole repo"
76+
else
77+
echo "Path File:"$OPTARG
78+
FILEPATH=$OPTARG
79+
fi
80+
;;
81+
f)
82+
echo "Flake operation starts"
83+
flake8 $FILEPATH
84+
;;
85+
l)
86+
echo "Lint operation starts"
87+
perform_linting
88+
;;
89+
h)
90+
help_info
91+
92+
;;
93+
\?)
94+
help_info
95+
96+
;;
97+
esac
98+
done

0 commit comments

Comments
 (0)