* [PATCH] tuna: Fix string syntax warnings with raw strings
@ 2024-10-25 19:01 John B. Wyatt IV
2024-10-28 15:21 ` John Kacur
0 siblings, 1 reply; 3+ messages in thread
From: John B. Wyatt IV @ 2024-10-25 19:01 UTC (permalink / raw)
To: Clark Williams, John Kacur
Cc: John B. Wyatt IV, linux-rt-users, kernel-rts-sst,
John B. Wyatt IV
tuna save <filename> allows you to save your kthreads tunables to
a file to be used by rtctl. There were several backslashes that produce
an error that pylint and Python (at least 3.12) gives a `SyntaxWarning:
invalid escape sequence`.
Convert the strings written to the file with raw strings to resolve the
warnings.
Tested by comparing the diffs of the files outputted by save.
Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com>
---
tuna/tuna.py | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/tuna/tuna.py b/tuna/tuna.py
index bd678e2..2dbc6cb 100755
--- a/tuna/tuna.py
+++ b/tuna/tuna.py
@@ -669,7 +669,8 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
# The regex is matched against process names as printed by "ps -eo cmd".
''' % filename)
- f.write("kthreads:*:1:*:\[.*\]$\n\n")
+ f.write(r"kthreads:*:1:*:\[.*\]$")
+ f.write("\n\n")
per_cpu_kthreads = []
names = list(kthreads.keys())
@@ -688,7 +689,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
elif common[:8] == "softirq-":
common = "(sirq|softirq)" + common[7:]
name = "s" + name[4:]
- regex = common + "\/.*"
+ regex = common + r"\/.*"
except:
idx = 0
regex = name
@@ -701,9 +702,10 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
else:
mask = ",".join([hex(a) for a in \
procfs.hexbitmask(kt.affinity, nr_cpus)])
- f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
+ f.write(r"%s:%c:%d:%s:\[%s\]$" % (name, \
tuna_sched.sched_str(kt.policy)[6].lower(), \
kt.rtprio, mask, regex))
+ f.write("\n")
f.close()
--
2.47.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] tuna: Fix string syntax warnings with raw strings
2024-10-25 19:01 [PATCH] tuna: Fix string syntax warnings with raw strings John B. Wyatt IV
@ 2024-10-28 15:21 ` John Kacur
2024-10-28 19:52 ` John B. Wyatt IV
0 siblings, 1 reply; 3+ messages in thread
From: John Kacur @ 2024-10-28 15:21 UTC (permalink / raw)
To: John B. Wyatt IV
Cc: Clark Williams, linux-rt-users, kernel-rts-sst, John B. Wyatt IV
On Fri, 25 Oct 2024, John B. Wyatt IV wrote:
> tuna save <filename> allows you to save your kthreads tunables to
> a file to be used by rtctl. There were several backslashes that produce
> an error that pylint and Python (at least 3.12) gives a `SyntaxWarning:
> invalid escape sequence`.
>
> Convert the strings written to the file with raw strings to resolve the
> warnings.
>
> Tested by comparing the diffs of the files outputted by save.
>
> Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
> Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com>
> ---
> tuna/tuna.py | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/tuna/tuna.py b/tuna/tuna.py
> index bd678e2..2dbc6cb 100755
> --- a/tuna/tuna.py
> +++ b/tuna/tuna.py
> @@ -669,7 +669,8 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
> # The regex is matched against process names as printed by "ps -eo cmd".
>
> ''' % filename)
> - f.write("kthreads:*:1:*:\[.*\]$\n\n")
> + f.write(r"kthreads:*:1:*:\[.*\]$")
> + f.write("\n\n")
You can concatenate the raw string with the new lines like this, so that
we don't increase the number of lines
f.write(r"kthreads:*:1:*:\[.*\]$" + "\n\n")
>
> per_cpu_kthreads = []
> names = list(kthreads.keys())
> @@ -688,7 +689,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
> elif common[:8] == "softirq-":
> common = "(sirq|softirq)" + common[7:]
> name = "s" + name[4:]
> - regex = common + "\/.*"
> + regex = common + r"\/.*"
> except:
> idx = 0
> regex = name
> @@ -701,9 +702,10 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
> else:
> mask = ",".join([hex(a) for a in \
> procfs.hexbitmask(kt.affinity, nr_cpus)])
> - f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
> + f.write(r"%s:%c:%d:%s:\[%s\]$" % (name, \
> tuna_sched.sched_str(kt.policy)[6].lower(), \
> kt.rtprio, mask, regex))
> + f.write("\n")
Same thing here
> f.close()
>
>
> --
There are more files than this one that exhibit the new SyntaxWarning
in tuna, check tuna-cmd.py and all the files in the tuna dir, and please
fix them all at once.
John Kacur
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] tuna: Fix string syntax warnings with raw strings
2024-10-28 15:21 ` John Kacur
@ 2024-10-28 19:52 ` John B. Wyatt IV
0 siblings, 0 replies; 3+ messages in thread
From: John B. Wyatt IV @ 2024-10-28 19:52 UTC (permalink / raw)
To: John Kacur
Cc: Clark Williams, linux-rt-users, kernel-rts-sst, John B. Wyatt IV
On Mon, Oct 28, 2024 at 11:21:18AM -0400, John Kacur wrote:
>
>
> On Fri, 25 Oct 2024, John B. Wyatt IV wrote:
>
> > tuna save <filename> allows you to save your kthreads tunables to
> > a file to be used by rtctl. There were several backslashes that produce
> > an error that pylint and Python (at least 3.12) gives a `SyntaxWarning:
> > invalid escape sequence`.
> >
> > Convert the strings written to the file with raw strings to resolve the
> > warnings.
> >
> > Tested by comparing the diffs of the files outputted by save.
> >
> > Signed-off-by: John B. Wyatt IV <jwyatt@redhat.com>
> > Signed-off-by: John B. Wyatt IV <sageofredondo@gmail.com>
> > ---
> > tuna/tuna.py | 8 +++++---
> > 1 file changed, 5 insertions(+), 3 deletions(-)
> >
> > diff --git a/tuna/tuna.py b/tuna/tuna.py
> > index bd678e2..2dbc6cb 100755
> > --- a/tuna/tuna.py
> > +++ b/tuna/tuna.py
> > @@ -669,7 +669,8 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
> > # The regex is matched against process names as printed by "ps -eo cmd".
> >
> > ''' % filename)
> > - f.write("kthreads:*:1:*:\[.*\]$\n\n")
> > + f.write(r"kthreads:*:1:*:\[.*\]$")
> > + f.write("\n\n")
>
> You can concatenate the raw string with the new lines like this, so that
> we don't increase the number of lines
>
> f.write(r"kthreads:*:1:*:\[.*\]$" + "\n\n")
>
Great idea.
> >
> > per_cpu_kthreads = []
> > names = list(kthreads.keys())
> > @@ -688,7 +689,7 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
> > elif common[:8] == "softirq-":
> > common = "(sirq|softirq)" + common[7:]
> > name = "s" + name[4:]
> > - regex = common + "\/.*"
> > + regex = common + r"\/.*"
> > except:
> > idx = 0
> > regex = name
> > @@ -701,9 +702,10 @@ def generate_rtgroups(filename, kthreads, nr_cpus):
> > else:
> > mask = ",".join([hex(a) for a in \
> > procfs.hexbitmask(kt.affinity, nr_cpus)])
> > - f.write("%s:%c:%d:%s:\[%s\]$\n" % (name, \
> > + f.write(r"%s:%c:%d:%s:\[%s\]$" % (name, \
> > tuna_sched.sched_str(kt.policy)[6].lower(), \
> > kt.rtprio, mask, regex))
> > + f.write("\n")
>
> Same thing here
ack
>
>
> > f.close()
> >
> >
> > --
>
> There are more files than this one that exhibit the new SyntaxWarning
> in tuna, check tuna-cmd.py and all the files in the tuna dir, and please
> fix them all at once.
>
> John Kacur
>
I doubled checked; I could not find anymore instances of the problem.
Tested Fedora 40 with the current rpm packaged version of pylint.
Will send a v2 with the concatenated strings.
--
Sincerely,
John Wyatt
Software Engineer, Core Kernel
Red Hat
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2024-10-28 19:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-25 19:01 [PATCH] tuna: Fix string syntax warnings with raw strings John B. Wyatt IV
2024-10-28 15:21 ` John Kacur
2024-10-28 19:52 ` John B. Wyatt IV
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox