Skip to contentSkip to conversation

devtools: set DTS directory to format check

PATCH Superseded Thomas Monjalon 3 participants 10 messages Nov 9, 2022 – Nov 23, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 devtools: set DTS directory to format check

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check. In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

---
 devtools/dts-check-format.sh | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
devtools/dts-check-format.sh +10 -4
index dc07150775..eb1bdd2a01 100755
@@ -3,11 +3,10 @@
 # Copyright(c) 2022 University of New Hampshire
 
 usage() {
-	echo "Run formatting and linting programs for DTS. Usage:"
-
+	echo 'Usage: $(basename $0) [options] [directory]'
+	echo 'Options:'
 	# Get source code comments after getopts arguments and print them both
 	grep -E '[a-zA-Z]+\) +#' "$0" | tr -d '#'
-	exit 0
 }
 
 format=true
@@ -17,7 +16,9 @@ lint=true
 while getopts "hfl" arg; do
 	case $arg in
 	h) # Display this message
+		echo 'Run formatting and linting programs for DTS.'
 		usage
+		exit 0
 		;;
 	f) # Don't run formatters
 		format=false
@@ -25,10 +26,15 @@ while getopts "hfl" arg; do
 	l) # Don't run linter
 		lint=false
 		;;
-	*)
+	?)
+		usage
+		exit 1
 	esac
 done
+shift $(($OPTIND - 1))
 
+directory=${1:-$(dirname $0)/../dts}
+cd $directory || exit 1
 
 errors=0
 
Signature · 1 line
2.36.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 61 lines · Thomas Monjalon

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check. In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

---
 devtools/dts-check-format.sh | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
devtools/dts-check-format.sh +2 -2
index dc07150775..eb1bdd2a01 100755
@@ -3,11 +3,10 @@
 # Copyright(c) 2022 University of New Hampshire
 
 usage() {
-       echo "Run formatting and linting programs for DTS. Usage:"
-
+       echo 'Usage: $(basename $0) [options] [directory]'
+       echo 'Options:'
        # Get source code comments after getopts arguments and print them

both

        grep -E '[a-zA-Z]+\) +#' "$0" | tr -d '#'
devtools/dts-check-format.sh +8 -3
-       exit 0
 }
 
 format=true
@@ -17,7 +16,9 @@ lint=true
 while getopts "hfl" arg; do
        case $arg in
        h) # Display this message
+               echo 'Run formatting and linting programs for DTS.'
                usage
+               exit 0
                ;;
        f) # Don't run formatters
                format=false
@@ -25,10 +26,15 @@ while getopts "hfl" arg; do
        l) # Don't run linter
                lint=false
                ;;
-       *)
+       ?)
+               usage
+               exit 1
        esac
 done
+shift $(($OPTIND - 1))
 
+directory=${1:-$(dirname $0)/../dts}
+cd $directory || exit 1
 
 errors=0
 
--
Quoted 3 lines

2.36.1

Looks good to me.

Reviewed-by Tested-by on v1 1/1
#2 lore raw
In reply to Thomas Monjalon
Quoted 29 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, November 9, 2022 6:09 PM
To: [email protected]
Cc: Juraj Linkeš <[email protected]>; Lijuan Tu <[email protected]>; Owen Hilyard <[email protected]>
Subject: [PATCH] devtools: set DTS directory to format check

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check. In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

---
 devtools/dts-check-format.sh | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
devtools/dts-check-format.sh +0 -0
index dc07150775..eb1bdd2a01 100755

devtools/dts-check-format.sh line 6

Quoted 6 lines
devtools/dts-check-format.sh +1 -2
@@ -3,11 +3,10 @@
 # Copyright(c) 2022 University of New Hampshire
 
 usage() {
-	echo "Run formatting and linting programs for DTS. Usage:"
-
+	echo 'Usage: $(basename $0) [options] [directory]'

Double quotes here, otherwise $0 won't be expanded.

Quoted 23 lines
devtools/dts-check-format.sh +1 -0
+	echo 'Options:'
 	# Get source code comments after getopts arguments and print

them both

devtools/dts-check-format.sh +2 -2
 	grep -E '[a-zA-Z]+\) +#' "$0" | tr -d '#'
-	exit 0
 }
 
 format=true
@@ -17,7 +16,9 @@ lint=true
 while getopts "hfl" arg; do
 	case $arg in
 	h) # Display this message
+		echo 'Run formatting and linting programs for DTS.'
 		usage
+		exit 0
 		;;
 	f) # Don't run formatters
 		format=false
@@ -25,10 +26,15 @@ while getopts "hfl" arg; do
 	l) # Don't run linter
 		lint=false
 		;;
-	*)

devtools/dts-check-format.sh while getopts "hfl" arg; do · line 38

Quoted 10 lines
devtools/dts-check-format.sh +6 -0
+	?)
+		usage
+		exit 1
 	esac
 done
+shift $(($OPTIND - 1))
 
+directory=${1:-$(dirname $0)/../dts}
+cd $directory || exit 1
 

I'd like to include the information of where we're doing the fomatting in the console output, e.g.:
echo "Formatting in $(pwd):"

We're silently chaning the directory, so this would be useful when running with no argument and the script doesn't change anything - as a confirmation that it ran over the files we wanted to.

Quoted 5 lines
devtools/dts-check-format.sh +0 -1
 errors=0
 
--

2.36.1

Other than that,

#3 lore raw

10/11/2022 10:27, Juraj Linkeš:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

devtools/dts-check-format.sh line 6

Quoted 4 lines

usage() {

devtools/dts-check-format.sh +1 -2
-	echo "Run formatting and linting programs for DTS. Usage:"
-
+	echo 'Usage: $(basename $0) [options] [directory]'

Double quotes here, otherwise $0 won't be expanded.

I wonder how I tested it :)

Quoted 7 lines

devtools/dts-check-format.sh while getopts "hfl" arg; do · line 37

Quoted 2 lines
devtools/dts-check-format.sh +2 -0
+directory=${1:-$(dirname $0)/../dts}
+cd $directory || exit 1

I'd like to include the information of where we're doing the fomatting in the console output, e.g.:
echo "Formatting in $(pwd):"

We're silently chaning the directory, so this would be useful when running with no argument and the script doesn't change anything - as a confirmation that it ran over the files we wanted to.

Good comment, I'll improve in v2.

Quoted 3 lines

Other than that,

No it does not work, so you should not add your Tested-by. And in general, Reviewed-by is enough.
And really, give your reviewed-by only when it's perfect :)

#4 lore raw
Quoted 24 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Thursday, November 10, 2022 11:26 AM
To: Juraj Linkeš <[email protected]>
Cc: [email protected]; Lijuan Tu <[email protected]>; Owen Hilyard <[email protected]>
Subject: Re: [PATCH] devtools: set DTS directory to format check

10/11/2022 10:27, Juraj Linkeš:

Quoted 7 lines

From: Thomas Monjalon <[email protected]>

devtools/dts-check-format.sh line 6

Quoted 4 lines

usage() {

devtools/dts-check-format.sh +1 -2
-	echo "Run formatting and linting programs for DTS. Usage:"
-
+	echo 'Usage: $(basename $0) [options] [directory]'

Double quotes here, otherwise $0 won't be expanded.

I wonder how I tested it :)

Quoted 3 lines
Quoted 1 line

+directory=${1:-$(dirname $0)/../dts} cd $directory || exit 1

I'd like to include the information of where we're doing the fomatting in

Quoted 8 lines

the console output, e.g.:

Quoted 3 lines

echo "Formatting in $(pwd):"

We're silently chaning the directory, so this would be useful when running

with no argument and the script doesn't change anything - as a confirmation that it ran over the files we wanted to.

Good comment, I'll improve in v2.

One more thing, if we go with changing the Formatting echo, then we should also change the Linting echo. Or we could do it in some other place just once, I'm not sure which is better.

Quoted 9 lines
Quoted 4 lines

Other than that,

No it does not work, so you should not add your Tested-by. And in general, Reviewed-by is enough.
And really, give your reviewed-by only when it's perfect :)

Thanks. It actually does work (by which I mean it does format and lint), but it's not perfect, so I guess Tested-by should be fine, but Reviewed-by isn't? :-)

#5 lore raw
Quoted 7 lines
Quoted 2 lines

Good comment, I'll improve in v2.

One more thing, if we go with changing the Formatting echo, then we should also change the Linting echo. Or we could do it in some other place just once, I'm not sure which is better.

I have one more request, could you add "echo 'Summary:'" before 'echo "Found $errors errors"' so that it's 100% clear what we're printing at the end (and that it's not part of the 'Linting:' output).

Thanks

#6 lore raw

11/11/2022 11:06, Juraj Linkeš:

Quoted 8 lines
Quoted 6 lines
Quoted 2 lines

Good comment, I'll improve in v2.

One more thing, if we go with changing the Formatting echo, then we should also change the Linting echo. Or we could do it in some other place just once, I'm not sure which is better.

I have one more request, could you add "echo 'Summary:'" before 'echo "Found $errors errors"' so that it's 100% clear what we're printing at the end (and that it's not part of the 'Linting:' output).

OK good idea

#7 lore raw

PATCH v2 1/1 devtools: set DTS directory to format check

In reply to Thomas Monjalon

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check. In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

The directory is also printed in headings,
and a last heading is added for the summary part.

---
v2: add directory in headings and improve headings

---
 devtools/dts-check-format.sh | 24 ++++++++++++++++++------
 1 file changed, 18 insertions(+), 6 deletions(-)
devtools/dts-check-format.sh +18 -6
index dc07150775..c9b3702642 100755
@@ -3,11 +3,10 @@
 # Copyright(c) 2022 University of New Hampshire
 
 usage() {
-	echo "Run formatting and linting programs for DTS. Usage:"
-
+	echo "Usage: $(basename $0) [options] [directory]"
+	echo 'Options:'
 	# Get source code comments after getopts arguments and print them both
 	grep -E '[a-zA-Z]+\) +#' "$0" | tr -d '#'
-	exit 0
 }
 
 format=true
@@ -17,7 +16,9 @@ lint=true
 while getopts "hfl" arg; do
 	case $arg in
 	h) # Display this message
+		echo 'Run formatting and linting programs for DTS.'
 		usage
+		exit 0
 		;;
 	f) # Don't run formatters
 		format=false
@@ -25,17 +26,27 @@ while getopts "hfl" arg; do
 	l) # Don't run linter
 		lint=false
 		;;
-	*)
+	?)
+		usage
+		exit 1
 	esac
 done
+shift $(($OPTIND - 1))
 
+directory=$(realpath --relative-base=$(pwd) ${1:-$(dirname $0)/../dts})
+cd $directory || exit 1
+
+heading() {
+	echo $*
+	echo $* | sed 's/./-/g' # underline
+}
 
 errors=0
 
 if $format; then
 	if command -v git > /dev/null; then
 		if git rev-parse --is-inside-work-tree >&-; then
-			echo "Formatting:"
+			heading "Formatting in $directory/"
 			if command -v black > /dev/null; then
 				echo "Formatting code with black:"
 				black .
@@ -72,7 +83,7 @@ if $lint; then
 	if $format; then
 		echo
 	fi
-	echo "Linting:"
+	heading "Linting in $directory/"
 	if command -v pylama > /dev/null; then
 		pylama .
 		errors=$((errors + $?))
@@ -83,5 +94,6 @@ if $lint; then
 fi
 
 echo
+heading "Summary for $directory/"
 echo "Found $errors errors"
 exit $errors
Signature · 1 line
2.36.1
Reviewed-by Owen Hilyard Reviewed-by Tested-by on v2 1/1
#8 lore raw

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Wednesday, November 23, 2022 12:22 PM
To: [email protected]
Cc: Juraj Linkeš <[email protected]>; Owen Hilyard <[email protected]>; Lijuan Tu <[email protected]>
Subject: [PATCH v2] devtools: set DTS directory to format check

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check. In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

The directory is also printed in headings, and a last heading is added for the summary part.

---
v2: add directory in headings and improve headings
---

Nice touch with the headings. The patch looks and works great.

author Applied
#9 lore raw
Quoted 11 lines

The script was running on the current directory.
If not in the DTS directory, it would re-format every Python files.

A new positional argument is added to specify the directory to check. In most cases, the (new) default value should be enough.

While updating argument handling,
the usage is printed in case of wrong argument.

The directory is also printed in headings, and a last heading is added for the summary part.

Quoted 8 lines

---
v2: add directory in headings and improve headings
---

Nice touch with the headings. The patch looks and works great.

Thanks for the ideas.

Quoted 1 line

Applied