From 313696ecf950ec745a48bd2e9026e6745b1da947 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Tue, 11 Mar 2025 15:27:09 -0500 Subject: [PATCH] scripts: Fixed openio issue where some scripts didn't import os This only failed if "-" was used as an argument (for stdin/stdout), so the issue was pretty hard to spot. openio is a heavily copy-pasted function, so it makes sense to just add the import os to openio directly. Otherwise this mistake will likely happen again in the future. --- scripts/bench.py | 1 + scripts/changeprefix.py | 1 + scripts/code.py | 1 + scripts/codemap.py | 1 + scripts/codemapd3.py | 1 + scripts/cov.py | 1 + scripts/crc32c.py | 1 + scripts/csv.py | 1 + scripts/ctx.py | 1 + scripts/data.py | 1 + scripts/parity.py | 1 + scripts/perf.py | 1 + scripts/perfbd.py | 1 + scripts/plot.py | 1 + scripts/plotmpl.py | 1 + scripts/prettyasserts.py | 1 + scripts/stack.py | 1 + scripts/structs.py | 1 + scripts/tailpipe.py | 1 + scripts/teepipe.py | 1 + scripts/test.py | 1 + scripts/tracebd.py | 1 + scripts/treemap.py | 1 + scripts/treemapd3.py | 1 + scripts/watch.py | 1 + 25 files changed, 25 insertions(+) diff --git a/scripts/bench.py b/scripts/bench.py index ec85f1d1..f997f367 100755 --- a/scripts/bench.py +++ b/scripts/bench.py @@ -46,6 +46,7 @@ PERF_SCRIPT = ['./scripts/perf.py'] def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/changeprefix.py b/scripts/changeprefix.py index 950d26a6..869306ae 100755 --- a/scripts/changeprefix.py +++ b/scripts/changeprefix.py @@ -32,6 +32,7 @@ GIT_PATH = ['git'] def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/code.py b/scripts/code.py index 6c405f23..233db5eb 100755 --- a/scripts/code.py +++ b/scripts/code.py @@ -157,6 +157,7 @@ class CodeResult(co.namedtuple('CodeResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/codemap.py b/scripts/codemap.py index b732c850..6c71c95e 100755 --- a/scripts/codemap.py +++ b/scripts/codemap.py @@ -43,6 +43,7 @@ CTX_PATH = ['./scripts/ctx.py'] def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/codemapd3.py b/scripts/codemapd3.py index 416a1932..906da578 100755 --- a/scripts/codemapd3.py +++ b/scripts/codemapd3.py @@ -61,6 +61,7 @@ CTX_PATH = ['./scripts/ctx.py'] def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/cov.py b/scripts/cov.py index b6c0a140..4e3be2f6 100755 --- a/scripts/cov.py +++ b/scripts/cov.py @@ -264,6 +264,7 @@ class CovResult(co.namedtuple('CovResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/crc32c.py b/scripts/crc32c.py index 07dde8fd..aa483917 100755 --- a/scripts/crc32c.py +++ b/scripts/crc32c.py @@ -12,6 +12,7 @@ import sys def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/csv.py b/scripts/csv.py index 59746f5b..633328a4 100755 --- a/scripts/csv.py +++ b/scripts/csv.py @@ -1330,6 +1330,7 @@ def punescape_help(): def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/ctx.py b/scripts/ctx.py index 34437770..caabab23 100755 --- a/scripts/ctx.py +++ b/scripts/ctx.py @@ -162,6 +162,7 @@ class CtxResult(co.namedtuple('CtxResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/data.py b/scripts/data.py index bc6ed733..4b64d5e1 100755 --- a/scripts/data.py +++ b/scripts/data.py @@ -157,6 +157,7 @@ class DataResult(co.namedtuple('DataResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/parity.py b/scripts/parity.py index a4f56406..911a1289 100755 --- a/scripts/parity.py +++ b/scripts/parity.py @@ -14,6 +14,7 @@ import operator as op def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/perf.py b/scripts/perf.py index c83c7748..3e155071 100755 --- a/scripts/perf.py +++ b/scripts/perf.py @@ -182,6 +182,7 @@ class PerfResult(co.namedtuple('PerfResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/perfbd.py b/scripts/perfbd.py index 8b99d4a7..e8f363c5 100755 --- a/scripts/perfbd.py +++ b/scripts/perfbd.py @@ -166,6 +166,7 @@ class PerfBdResult(co.namedtuple('PerfBdResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/plot.py b/scripts/plot.py index 59c9d4f8..59edf4e0 100755 --- a/scripts/plot.py +++ b/scripts/plot.py @@ -134,6 +134,7 @@ def si2(x, w=5): def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/plotmpl.py b/scripts/plotmpl.py index 9ac61654..e16234b0 100755 --- a/scripts/plotmpl.py +++ b/scripts/plotmpl.py @@ -160,6 +160,7 @@ class AutoMultipleLocator(mpl.ticker.MultipleLocator): def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/prettyasserts.py b/scripts/prettyasserts.py index 4df3ec6d..00c8ee37 100755 --- a/scripts/prettyasserts.py +++ b/scripts/prettyasserts.py @@ -80,6 +80,7 @@ L.lex('STUFF', '[^;{}?:,()"\'=!<>\-&|/#]+', def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/stack.py b/scripts/stack.py index ef7843ae..f732bc7a 100755 --- a/scripts/stack.py +++ b/scripts/stack.py @@ -162,6 +162,7 @@ class StackResult(co.namedtuple('StackResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/structs.py b/scripts/structs.py index a302ea91..40090de8 100755 --- a/scripts/structs.py +++ b/scripts/structs.py @@ -160,6 +160,7 @@ class StructResult(co.namedtuple('StructResult', [ def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/tailpipe.py b/scripts/tailpipe.py index ee3a1efa..48f21efc 100755 --- a/scripts/tailpipe.py +++ b/scripts/tailpipe.py @@ -25,6 +25,7 @@ import time def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/teepipe.py b/scripts/teepipe.py index 743b281a..77be41e9 100755 --- a/scripts/teepipe.py +++ b/scripts/teepipe.py @@ -21,6 +21,7 @@ import sys def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/test.py b/scripts/test.py index 49d02f8a..88466922 100755 --- a/scripts/test.py +++ b/scripts/test.py @@ -47,6 +47,7 @@ PERF_SCRIPT = ['./scripts/perf.py'] def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/tracebd.py b/scripts/tracebd.py index 039d7b2b..335f0587 100755 --- a/scripts/tracebd.py +++ b/scripts/tracebd.py @@ -46,6 +46,7 @@ CHARS_BRAILLE = ( def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/treemap.py b/scripts/treemap.py index 78cc43dc..def804e6 100755 --- a/scripts/treemap.py +++ b/scripts/treemap.py @@ -36,6 +36,7 @@ CHARS_BRAILLE = ( def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/treemapd3.py b/scripts/treemapd3.py index b4a9bfe7..02cb013d 100755 --- a/scripts/treemapd3.py +++ b/scripts/treemapd3.py @@ -53,6 +53,7 @@ FONT_SIZE = 10 def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering) diff --git a/scripts/watch.py b/scripts/watch.py index 4d84591a..3c0d66b5 100755 --- a/scripts/watch.py +++ b/scripts/watch.py @@ -36,6 +36,7 @@ except ModuleNotFoundError: def openio(path, mode='r', buffering=-1): # allow '-' for stdin/stdout + import os if path == '-': if 'r' in mode: return os.fdopen(os.dup(sys.stdin.fileno()), mode, buffering)