From nobody Sun Jan 11 05:25:52 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4dpkWR5Tp5z6NVhr for ; Sun, 11 Jan 2026 05:26:11 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "smtp.gmail.com", Issuer "WR4" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4dpkWR214Rz3LWZ for ; Sun, 11 Jan 2026 05:26:11 +0000 (UTC) (envelope-from yaneurabeya@gmail.com) Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20230601 header.b="c/kZpfBA"; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of yaneurabeya@gmail.com designates 2607:f8b0:4864:20::62e as permitted sender) smtp.mailfrom=yaneurabeya@gmail.com Received: by mail-pl1-x62e.google.com with SMTP id d9443c01a7336-2a09d981507so32082435ad.1 for ; Sat, 10 Jan 2026 21:26:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1768109165; x=1768713965; darn=freebsd.org; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:from:to:cc:subject:date:message-id:reply-to; bh=bvadG6WCKihagz6E2j6chFP1tXL0cXiZNXMAwM7LF7w=; b=c/kZpfBA2aNs6AGoPmxI++3DFxA6/tqWf9TY69vndGPkEITe8b4DuBMpI7nW6VQuVs Y9dyVfWcQcUd0GlLeBV1HFAaz5tkrN5FqammNoYOGFujLMkx8JgrxIEDBvOCu+S51uZm RNMlpe1AEXQLu3CSfFPn1G4hEISBqgBcwwhzIpy2GxuuPIw/PRpIZ2Q9qtOzlmFwPqef MzTPHNNZILOFWUpH5sC18lptqsGFmiHcVWAxUtd8HaO+0zzh9QPF90pDWHhM3MthNMDE M9lDomnLAAGHFadpMz1Qmihd32wS5EwbDFsw+EsOwkX9aAQy1X/lMw6Z7zKBpgVsA4MA 2n4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1768109165; x=1768713965; h=references:to:cc:in-reply-to:date:subject:mime-version:message-id :from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=bvadG6WCKihagz6E2j6chFP1tXL0cXiZNXMAwM7LF7w=; b=cw5lzL9URC+v6hwlCccQ+cx52/s9vw7JowlvT8yT4WM6L1BxPHGtn3l7g+PMiRgq5p +AyFVoXFjOnPmq4pM/xjn4IkOh41SS3ykxlF1ii3iei4rtZRenTCGeKCOzJimHgDs/d/ oMv3ZqW3OBjS6qBivOLVbDTELcNy0jjwc6cfmYnFQl19fB5yJRYwornTWtoxYh6FzjZR eb+UEjzU6B6xKTwz3pacfOWQsep4OS86Fp8nD1ZCpSIdF8V2QaBC7UkxrgSydgT8PiqU xnvAUUWsj6nsBYcm1u2BEhxCVZpyfAy0zYgAqJiHlHfzdJ6UL1QjgtkasYYKxChuaZML a34Q== X-Forwarded-Encrypted: i=1; AJvYcCX7APhV9sB72j11FWoQB+Wa8XSxv6BPzNVNvtNAWZWXqp/WrK97gGXuTN9czMoT28BvMcjITLGmxrKeajd6UqjTsrSD@freebsd.org X-Gm-Message-State: AOJu0YxVYq5TL98H8NL9BD9IxmhzSnWW35MIadwIpKKW+VoE0d95mf/D 7NJIRE90SvAVP9ItG95Wgub6C54DKLJy7Vu3PcVs7fQZCiCzur+HqnD1 X-Gm-Gg: AY/fxX7Gy8VdtP1tX2NanhSC4SZKIlWB+UnujSsJgnrTBTYLQE57iaTcBIByiMr3DpO iPmGb6opzJsxB0dbjVVOJES7MGN8/t52V5SzAgs9ryCqen1/lyISQOqcqaTMiTHAUppLKBDzrMl csR6zvhDsPEpvGFFWOnsVgz5omX2w2uuhd+PZiA2vc5KwJRROJ4mAE6E/kRIeA9h5qvfPpIXPnN X9qkD3XJXU3wp85RnspkKBSiYHChaR2f46Vt5g4HCaJ4L0uvY04dRS5PEs2YNF2a1hNc/xEAOsJ QfjyofbzfuV5hzu/ebpgnjtaoofB1s/NfgaoePgVhprCHvQsjMHYkk9FZ7RinW4unbbSugw8QMi ST5iIOvCjkaDSC7PUMfZK4g1cPnC1PRjmicur2dACHtWkc98LdmAuzAYBljaYaq6ko1w7MpkYKX V3Z0VLXiU/cnGTAV5KxW6PeWTqjuSwkhw7 X-Google-Smtp-Source: AGHT+IGBPovwz+bzKztaJiW9IlZpG/3P4Y/g6Je+ECe/c3UrrqwZgzOlIccWYko2mASSK9fprmBAPA== X-Received: by 2002:a17:903:187:b0:2a0:d527:4d07 with SMTP id d9443c01a7336-2a3edb73820mr156274715ad.17.1768109164977; Sat, 10 Jan 2026 21:26:04 -0800 (PST) Received: from smtpclient.apple ([45.90.222.74]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a3e3cb2df6sm142380185ad.61.2026.01.10.21.26.03 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 10 Jan 2026 21:26:04 -0800 (PST) From: "Enji Cooper (yaneurabeya)" Message-Id: <76722189-7324-4BAE-9359-65948F51DDD1@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_58919F3F-F4E4-4A0F-B837-EABBBE06AE34" List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3826.700.81.1.4\)) Subject: Re: git: eb1c0d74cbb9 - main - Convert fully to Python 3. Remove licence text, only keep Date: Sat, 10 Jan 2026 21:25:52 -0800 In-Reply-To: <695ba4fb.35e3f.3a916a95@gitrepo.freebsd.org> Cc: "src-committers@freebsd.org" , "dev-commits-src-all@freebsd.org" , "dev-commits-src-main@freebsd.org" To: "George V. Neville-Neil" References: <695ba4fb.35e3f.3a916a95@gitrepo.freebsd.org> X-Mailer: Apple Mail (2.3826.700.81.1.4) X-Spamd-Bar: --- X-Spamd-Result: default: False [-3.29 / 15.00]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.79)[-0.793]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; MV_CASE(0.50)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20230601]; MIME_GOOD(-0.10)[multipart/alternative,text/plain]; RCVD_TLS_LAST(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+,1:+,2:~]; FREEMAIL_ENVFROM(0.00)[gmail.com]; TO_DN_EQ_ADDR_SOME(0.00)[]; FREEMAIL_FROM(0.00)[gmail.com]; TO_DN_SOME(0.00)[]; DKIM_TRACE(0.00)[gmail.com:+]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; RCVD_IN_DNSWL_NONE(0.00)[2607:f8b0:4864:20::62e:from]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_THREE(0.00)[4]; PREVIOUSLY_DELIVERED(0.00)[dev-commits-src-all@freebsd.org]; MID_RHS_MATCH_FROM(0.00)[]; MLMMJ_DEST(0.00)[dev-commits-src-all@freebsd.org]; RCVD_VIA_SMTP_AUTH(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com:dkim] X-Rspamd-Queue-Id: 4dpkWR214Rz3LWZ --Apple-Mail=_58919F3F-F4E4-4A0F-B837-EABBBE06AE34 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 Some comments below=E2=80=A6 +o pedantic-python > On Jan 5, 2026, at 3:48=E2=80=AFAM, George V. Neville-Neil = wrote: >=20 > The branch main has been updated by gnn: >=20 > URL: = https://cgit.FreeBSD.org/src/commit/?id=3Deb1c0d74cbb99f329767b3d565ae57a3= ec032bee >=20 > commit eb1c0d74cbb99f329767b3d565ae57a3ec032bee > Author: George V. Neville-Neil > AuthorDate: 2026-01-05 11:40:12 +0000 > Commit: George V. Neville-Neil > CommitDate: 2026-01-05 11:40:12 +0000 >=20 > Convert fully to Python 3. Remove licence text, only keep >=20 > SPDX. >=20 > Update to use argparse rather than OptionParser (now deprecated). All good stuff :). > -import sys > import subprocess > from subprocess import PIPE > +import argparse Please sort imports =E2=80=94 thanks :). > -# Use input() for Python version 3 > -if sys.version_info[0] =3D=3D 3: > - raw_input =3D input > +def gather_counters(): > + """Run program and return output as array of lines.""" > + result =3D subprocess.run("pmccontrol -L", shell=3DTrue, = capture_output=3DTrue, text=3DTrue) Instead of using `shell=3DTrue`, please use `[=E2=80=9Cpmccontrol=E2=80=9D= , =E2=80=9C-L=E2=80=9D] =E2=80=94 this employs best practices and avoids = complaints from bandit [1] and ruff [2]. Will this command ever return non-UTF8 encodable characters? If so, this = call will crash when decoding the output. > + tabbed =3D result.stdout.strip().split('\n') Please use `.splitlines()` instead of `.split(=E2=80=9C\n=E2=80=9D)`: it = avoids hardcoding the text form of the character and achieves the same = thing as the bytes form. Plus, it=E2=80=99s a bit easier to read/grok = for humans. > + return [line.replace('\t', '') for line in tabbed] >=20 > # A list of strings that are not really counters, just > # name tags that are output by pmccontrol -L > @@ -62,37 +36,28 @@ notcounter =3D ["IAF", "IAP", "TSC", "UNC", "UCF", = "UCP", "SOFT" ] >=20 > def main(): >=20 > - from optparse import OptionParser > - =20 > - parser =3D OptionParser() > - parser.add_option("-p", "--program", dest=3D"program",=20 > - help=3D"program to execute") > - parser.add_option("-w", "--wait", action=3D"store_true", = dest=3D"wait", > - default=3DTrue, help=3D"wait after each = execution") > + parser =3D argparse.ArgumentParser(description=3D'Exercise a = program under hwpmc') > + parser.add_argument('--program', type=3Dstr, required=3DTrue, = help=3D'target program') > + parser.add_argument('--wait', action=3D'store_true', help=3D'Wait = after each counter.') >=20 > - (options, args) =3D parser.parse_args() > + args =3D parser.parse_args() >=20 > - if (options.program =3D=3D None): > - print("specify program, such as ls, with -p/--program") > - sys.exit() > - =20 > - p =3D subprocess.Popen(["pmccontrol", "-L"], stdout=3DPIPE) > - counters =3D p.communicate()[0] > + counters =3D gather_counters() >=20 > if len(counters) <=3D 0: This is tautologically impossible for < 0. PEP8 says to express it this = way: `If not counters:` > print("no counters found") > sys.exit() >=20 > - for counter in counters.split(): > + for counter in counters: > if counter in notcounter: > continue > - p =3D subprocess.Popen(["pmcstat", "-p", counter, = options.program], > - stdout=3DPIPE) > - result =3D p.communicate()[0] > + p =3D subprocess.Popen(["pmcstat", "-p", counter, = args.program], > + text=3DTrue, stderr=3DPIPE) > + result =3D p.communicate()[1] > print(result) > - if (options.wait =3D=3D True): > + if (args.wait =3D=3D True): `if args.wait:` is the equivalent simpler PEP8-compatible form. You = don=E2=80=99t need to compare against True/False explicitly. > try: > - value =3D raw_input("next?") > + value =3D input("Waitin for you to press ENTER") This wording=E2=80=99s a bit more direct and fixes a typo: `"Please = press ENTER=E2=80=9D`. > except EOFError: > sys.exit() Cheers! -Enji 1. https://bandit.readthedocs.io/en/latest/ 2. https://docs.astral.sh/ruff/= --Apple-Mail=_58919F3F-F4E4-4A0F-B837-EABBBE06AE34 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=utf-8 Some comments = below=E2=80=A6

+o pedantic-python

On Jan 5, 2026, at 3:48=E2=80=AFAM, George V. = Neville-Neil <gnn@FreeBSD.org> wrote:

The branch main has been = updated by gnn:

URL: = https://cgit.FreeBSD.org/src/commit/?id=3Deb1c0d74cbb99f329767b3d565ae57a3= ec032bee

commit = eb1c0d74cbb99f329767b3d565ae57a3ec032bee
Author: =     George V. Neville-Neil = <gnn@FreeBSD.org>
AuthorDate: 2026-01-05 11:40:12 = +0000
Commit:     George V. Neville-Neil = <gnn@FreeBSD.org>
CommitDate: 2026-01-05 11:40:12 +0000

=    Convert fully to Python 3.  Remove licence text, = only keep

   SPDX.

=    Update to use argparse rather than OptionParser (now = deprecated).

All good stuff = :).

-import sys
= import subprocess
from subprocess import PIPE
+import = argparse

Please sort imports = =E2=80=94 thanks :).

-# Use = input() for Python version 3
-if sys.version_info[0] =3D=3D 3:
- =    raw_input =3D input
+def gather_counters():
+ =    """Run program and return output as array of = lines."""
+    result =3D subprocess.run("pmccontrol = -L", shell=3DTrue, capture_output=3DTrue, = text=3DTrue)

Instead of using = `shell=3DTrue`, please use `[=E2=80=9Cpmccontrol=E2=80=9D, =E2=80=9C-L=E2=80= =9D] =E2=80=94 this employs best practices and avoids complaints from = bandit [1] and ruff [2].

Will this command ever = return non-UTF8 encodable characters? If so, this call will crash when = decoding the output.

+ =    tabbed =3D = result.stdout.strip().split('\n')

Please use `.splitlines()` instead of `.split(=E2=80=9C\n=E2=80=9D)`: = it avoids hardcoding the text form of the character and achieves the = same thing as the bytes form. Plus, it=E2=80=99s a bit easier to = read/grok for humans.

+ =    return [line.replace('\t', '') for line in = tabbed]

# A list of strings that are not really counters, = just
# name tags that are output by pmccontrol -L
@@ -62,37 = +36,28 @@ notcounter =3D ["IAF", "IAP", "TSC", "UNC", "UCF", "UCP", = "SOFT" ]

def main():

-    from optparse = import OptionParser
-    
- =    parser =3D OptionParser()
- =    parser.add_option("-p", "--program", dest=3D"program", =
- =             &n= bsp;        help=3D"program to = execute")
-    parser.add_option("-w", "--wait", = action=3D"store_true", dest=3D"wait",
- =             &n= bsp;        default=3DTrue, = help=3D"wait after each execution")
+    parser =3D = argparse.ArgumentParser(description=3D'Exercise a program under = hwpmc')
+    parser.add_argument('--program', = type=3Dstr, required=3DTrue, help=3D'target program')
+ =    parser.add_argument('--wait', action=3D'store_true', = help=3D'Wait after each counter.')

-    (options, = args) =3D parser.parse_args()
+    args =3D = parser.parse_args()

-    if (options.program =3D=3D = None):
-        print("specify = program, such as ls, with -p/--program")
- =        sys.exit()
- =        
-    p =3D = subprocess.Popen(["pmccontrol", "-L"], stdout=3DPIPE)
- =    counters =3D p.communicate()[0]
+ =    counters =3D gather_counters()

=     if len(counters) <=3D = 0:

This is tautologically = impossible for < 0. PEP8 says to express it this = way:

`If not = counters:`

=         print("no counters = found")
=         sys.exit()

- =    for counter in counters.split():
+ =    for counter in counters:
=         if counter in = notcounter:
=             co= ntinue
-        p =3D = subprocess.Popen(["pmcstat", "-p", counter, options.program],
- =             &n= bsp;           &nbs= p;   stdout=3DPIPE)
- =        result =3D = p.communicate()[0]
+        p =3D = subprocess.Popen(["pmcstat", "-p", counter, args.program],
+ =             &n= bsp;           &nbs= p;   text=3DTrue, stderr=3DPIPE)
+ =        result =3D = p.communicate()[1]
=         print(result)
- =        if (options.wait =3D=3D = True):
+        if (args.wait =3D=3D= True):

`if args.wait:` is = the equivalent simpler PEP8-compatible form. You don=E2=80=99t need to = compare against True/False = explicitly.

=             tr= y:
- =             &n= bsp;  value =3D raw_input("next?")
+ =             &n= bsp;  value =3D input("Waitin for you to press = ENTER")

This wording=E2=80= =99s a bit more direct and fixes a typo: `"Please press = ENTER=E2=80=9D`.

=             ex= cept EOFError:
=             &n= bsp;   sys.exit()

Cheers!
-Enji

2. https://docs.astral.sh/ruff/= --Apple-Mail=_58919F3F-F4E4-4A0F-B837-EABBBE06AE34--