[Lldb-commits] [clang] [clang-tools-extra] [lldb] [llvm] [NFC] Prefer subprocess.DEVNULL over os.devnull (PR #106500)
https://github.com/nicovank created https://github.com/llvm/llvm-project/pull/106500 There is no need to support Python 2.7 anymore, Python 3.3+ has `subprocess.DEVNULL`. This is good practice and also prevents file handles from staying open unnecessarily. Also remove a couple unused or unneeded `__future__` imports. >From f0fa35d2a955ba4971e94e3c8bf1a6e0453e8bf9 Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Thu, 29 Aug 2024 02:44:13 -0400 Subject: [PATCH] [NFC] Prefer subprocess.DEVNULL over os.devnull There is no need to support Python 2.7 anymore, Python 3.3+ has `subprocess.DEVNULL`. This is good practice and also prevents file handles from staying open unnecessarily. Also remove a couple unused or unneeded `__future__` imports. --- .../clang-tidy/tool/run-clang-tidy.py| 10 -- clang/docs/tools/generate_formatted_state.py | 6 ++ clang/tools/scan-view/share/startfile.py | 2 +- clang/utils/creduce-clang-crash.py | 4 +--- lldb/bindings/interface/SBErrorDocstrings.i | 6 -- .../packages/Python/lldbsuite/test/decorators.py | 6 ++ lldb/packages/Python/lldbsuite/test/lldbtest.py | 3 +-- llvm/utils/UpdateTestChecks/common.py| 16 +++- llvm/utils/git/pre-push.py | 15 ++- llvm/utils/gn/gn.py | 2 +- 10 files changed, 25 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index 48401ba5ea42a9..b702eece37002b 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -511,12 +511,10 @@ async def main() -> None: ) invocation.append("-list-checks") invocation.append("-") -if args.quiet: -# Even with -quiet we still want to check if we can call clang-tidy. -with open(os.devnull, "w") as dev_null: -subprocess.check_call(invocation, stdout=dev_null) -else: -subprocess.check_call(invocation) +# Even with -quiet we still want to check if we can call clang-tidy. +subprocess.check_call( +invocation, stdout=subprocess.DEVNULL if args.quiet else None +) except: print("Unable to run clang-tidy.", file=sys.stderr) sys.exit(1) diff --git a/clang/docs/tools/generate_formatted_state.py b/clang/docs/tools/generate_formatted_state.py index 66cebbf7af33a4..2de43dc383f557 100755 --- a/clang/docs/tools/generate_formatted_state.py +++ b/clang/docs/tools/generate_formatted_state.py @@ -78,8 +78,6 @@ def get_style(count, passed): - {style2}`{percent}%` """ -FNULL = open(os.devnull, "w") - with open(DOC_FILE, "wb") as output: cleanfiles = open(CLEAN_FILE, "wb") @@ -101,8 +99,8 @@ def get_style(count, passed): # interested in it, just the return code. git_check = subprocess.Popen( ["git", "ls-files", "--error-unmatch", act_sub_dir], -stdout=FNULL, -stderr=FNULL, +stdout=subprocess.DEVNULL, +stderr=subprocess.DEVNULL, ) if git_check.wait() != 0: print("Skipping directory: ", act_sub_dir) diff --git a/clang/tools/scan-view/share/startfile.py b/clang/tools/scan-view/share/startfile.py index d63e69280e90dd..c72475e8b6212e 100644 --- a/clang/tools/scan-view/share/startfile.py +++ b/clang/tools/scan-view/share/startfile.py @@ -48,7 +48,7 @@ def _invoke(self, cmdline): or sys.platform[:3] == "win" or sys.platform == "darwin" ): -inout = file(os.devnull, "r+") +inout = subprocess.DEVNULL else: # for TTY programs, we need stdin/out inout = None diff --git a/clang/utils/creduce-clang-crash.py b/clang/utils/creduce-clang-crash.py index db4a3435a3aef7..180dfbeab224e9 100755 --- a/clang/utils/creduce-clang-crash.py +++ b/clang/utils/creduce-clang-crash.py @@ -8,7 +8,6 @@ *.test.sh -- interestingness test for C-Reduce """ -from __future__ import print_function from argparse import ArgumentParser, RawTextHelpFormatter import os import re @@ -228,8 +227,7 @@ def check_interestingness(self): testfile = os.path.abspath(self.testfile) # Check that the test considers the original file interesting -with open(os.devnull, "w") as devnull: -returncode = subprocess.call(testfile, stdout=devnull) +returncode = subprocess.call(testfile, stdout=subprocess.DEVNULL) if returncode: sys.exit("The interestingness test does not pass for the original file.") diff --git a/lldb/bindings/interface/SBErrorDocstrings.i b/lldb/bindings/interface/SBErrorDocstrings.i index b64c3d64c6c77b..c272ffb7605f
[Lldb-commits] [clang] [clang-tools-extra] [lldb] [llvm] [NFC] Prefer subprocess.DEVNULL over os.devnull (PR #106500)
https://github.com/nicovank updated https://github.com/llvm/llvm-project/pull/106500 >From b86b6ca2a14d5e26bd00b5e72c194ee5fbe23f5d Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Thu, 29 Aug 2024 02:47:58 -0400 Subject: [PATCH] [NFC] Prefer subprocess.DEVNULL over os.devnull There is no need to support Python 2.7 anymore, Python 3.3+ has `subprocess.DEVNULL`. This is good practice and also prevents file handles from staying open unnecessarily. Also remove a couple unused or unneeded `__future__` imports. --- .../clang-tidy/tool/run-clang-tidy.py| 10 -- clang/docs/tools/generate_formatted_state.py | 6 ++ clang/tools/scan-view/share/startfile.py | 2 +- clang/utils/creduce-clang-crash.py | 4 +--- lldb/bindings/interface/SBErrorDocstrings.i | 6 -- .../packages/Python/lldbsuite/test/decorators.py | 6 ++ lldb/packages/Python/lldbsuite/test/lldbtest.py | 3 +-- llvm/utils/UpdateTestChecks/common.py| 16 +++- llvm/utils/git/pre-push.py | 15 ++- llvm/utils/gn/gn.py | 2 +- 10 files changed, 25 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index 48401ba5ea42a9..b702eece37002b 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -511,12 +511,10 @@ async def main() -> None: ) invocation.append("-list-checks") invocation.append("-") -if args.quiet: -# Even with -quiet we still want to check if we can call clang-tidy. -with open(os.devnull, "w") as dev_null: -subprocess.check_call(invocation, stdout=dev_null) -else: -subprocess.check_call(invocation) +# Even with -quiet we still want to check if we can call clang-tidy. +subprocess.check_call( +invocation, stdout=subprocess.DEVNULL if args.quiet else None +) except: print("Unable to run clang-tidy.", file=sys.stderr) sys.exit(1) diff --git a/clang/docs/tools/generate_formatted_state.py b/clang/docs/tools/generate_formatted_state.py index 66cebbf7af33a4..2de43dc383f557 100755 --- a/clang/docs/tools/generate_formatted_state.py +++ b/clang/docs/tools/generate_formatted_state.py @@ -78,8 +78,6 @@ def get_style(count, passed): - {style2}`{percent}%` """ -FNULL = open(os.devnull, "w") - with open(DOC_FILE, "wb") as output: cleanfiles = open(CLEAN_FILE, "wb") @@ -101,8 +99,8 @@ def get_style(count, passed): # interested in it, just the return code. git_check = subprocess.Popen( ["git", "ls-files", "--error-unmatch", act_sub_dir], -stdout=FNULL, -stderr=FNULL, +stdout=subprocess.DEVNULL, +stderr=subprocess.DEVNULL, ) if git_check.wait() != 0: print("Skipping directory: ", act_sub_dir) diff --git a/clang/tools/scan-view/share/startfile.py b/clang/tools/scan-view/share/startfile.py index d63e69280e90dd..c72475e8b6212e 100644 --- a/clang/tools/scan-view/share/startfile.py +++ b/clang/tools/scan-view/share/startfile.py @@ -48,7 +48,7 @@ def _invoke(self, cmdline): or sys.platform[:3] == "win" or sys.platform == "darwin" ): -inout = file(os.devnull, "r+") +inout = subprocess.DEVNULL else: # for TTY programs, we need stdin/out inout = None diff --git a/clang/utils/creduce-clang-crash.py b/clang/utils/creduce-clang-crash.py index db4a3435a3aef7..180dfbeab224e9 100755 --- a/clang/utils/creduce-clang-crash.py +++ b/clang/utils/creduce-clang-crash.py @@ -8,7 +8,6 @@ *.test.sh -- interestingness test for C-Reduce """ -from __future__ import print_function from argparse import ArgumentParser, RawTextHelpFormatter import os import re @@ -228,8 +227,7 @@ def check_interestingness(self): testfile = os.path.abspath(self.testfile) # Check that the test considers the original file interesting -with open(os.devnull, "w") as devnull: -returncode = subprocess.call(testfile, stdout=devnull) +returncode = subprocess.call(testfile, stdout=subprocess.DEVNULL) if returncode: sys.exit("The interestingness test does not pass for the original file.") diff --git a/lldb/bindings/interface/SBErrorDocstrings.i b/lldb/bindings/interface/SBErrorDocstrings.i index b64c3d64c6c77b..c272ffb7605ffb 100644 --- a/lldb/bindings/interface/SBErrorDocstrings.i +++ b/lldb/bindings/interface/SBErrorDocstrings.i @@ -10,8 +10,10 @@ For example (from test/python_api/hello_world/TestHelloWorld.py), :: # Spawn a new process and don't
[Lldb-commits] [clang] [clang-tools-extra] [lldb] [llvm] [NFC] Prefer subprocess.DEVNULL over os.devnull (PR #106500)
https://github.com/nicovank updated https://github.com/llvm/llvm-project/pull/106500 >From b86b6ca2a14d5e26bd00b5e72c194ee5fbe23f5d Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Thu, 29 Aug 2024 02:47:58 -0400 Subject: [PATCH] [NFC] Prefer subprocess.DEVNULL over os.devnull There is no need to support Python 2.7 anymore, Python 3.3+ has `subprocess.DEVNULL`. This is good practice and also prevents file handles from staying open unnecessarily. Also remove a couple unused or unneeded `__future__` imports. --- .../clang-tidy/tool/run-clang-tidy.py| 10 -- clang/docs/tools/generate_formatted_state.py | 6 ++ clang/tools/scan-view/share/startfile.py | 2 +- clang/utils/creduce-clang-crash.py | 4 +--- lldb/bindings/interface/SBErrorDocstrings.i | 6 -- .../packages/Python/lldbsuite/test/decorators.py | 6 ++ lldb/packages/Python/lldbsuite/test/lldbtest.py | 3 +-- llvm/utils/UpdateTestChecks/common.py| 16 +++- llvm/utils/git/pre-push.py | 15 ++- llvm/utils/gn/gn.py | 2 +- 10 files changed, 25 insertions(+), 45 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py index 48401ba5ea42a9..b702eece37002b 100755 --- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py +++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py @@ -511,12 +511,10 @@ async def main() -> None: ) invocation.append("-list-checks") invocation.append("-") -if args.quiet: -# Even with -quiet we still want to check if we can call clang-tidy. -with open(os.devnull, "w") as dev_null: -subprocess.check_call(invocation, stdout=dev_null) -else: -subprocess.check_call(invocation) +# Even with -quiet we still want to check if we can call clang-tidy. +subprocess.check_call( +invocation, stdout=subprocess.DEVNULL if args.quiet else None +) except: print("Unable to run clang-tidy.", file=sys.stderr) sys.exit(1) diff --git a/clang/docs/tools/generate_formatted_state.py b/clang/docs/tools/generate_formatted_state.py index 66cebbf7af33a4..2de43dc383f557 100755 --- a/clang/docs/tools/generate_formatted_state.py +++ b/clang/docs/tools/generate_formatted_state.py @@ -78,8 +78,6 @@ def get_style(count, passed): - {style2}`{percent}%` """ -FNULL = open(os.devnull, "w") - with open(DOC_FILE, "wb") as output: cleanfiles = open(CLEAN_FILE, "wb") @@ -101,8 +99,8 @@ def get_style(count, passed): # interested in it, just the return code. git_check = subprocess.Popen( ["git", "ls-files", "--error-unmatch", act_sub_dir], -stdout=FNULL, -stderr=FNULL, +stdout=subprocess.DEVNULL, +stderr=subprocess.DEVNULL, ) if git_check.wait() != 0: print("Skipping directory: ", act_sub_dir) diff --git a/clang/tools/scan-view/share/startfile.py b/clang/tools/scan-view/share/startfile.py index d63e69280e90dd..c72475e8b6212e 100644 --- a/clang/tools/scan-view/share/startfile.py +++ b/clang/tools/scan-view/share/startfile.py @@ -48,7 +48,7 @@ def _invoke(self, cmdline): or sys.platform[:3] == "win" or sys.platform == "darwin" ): -inout = file(os.devnull, "r+") +inout = subprocess.DEVNULL else: # for TTY programs, we need stdin/out inout = None diff --git a/clang/utils/creduce-clang-crash.py b/clang/utils/creduce-clang-crash.py index db4a3435a3aef7..180dfbeab224e9 100755 --- a/clang/utils/creduce-clang-crash.py +++ b/clang/utils/creduce-clang-crash.py @@ -8,7 +8,6 @@ *.test.sh -- interestingness test for C-Reduce """ -from __future__ import print_function from argparse import ArgumentParser, RawTextHelpFormatter import os import re @@ -228,8 +227,7 @@ def check_interestingness(self): testfile = os.path.abspath(self.testfile) # Check that the test considers the original file interesting -with open(os.devnull, "w") as devnull: -returncode = subprocess.call(testfile, stdout=devnull) +returncode = subprocess.call(testfile, stdout=subprocess.DEVNULL) if returncode: sys.exit("The interestingness test does not pass for the original file.") diff --git a/lldb/bindings/interface/SBErrorDocstrings.i b/lldb/bindings/interface/SBErrorDocstrings.i index b64c3d64c6c77b..c272ffb7605ffb 100644 --- a/lldb/bindings/interface/SBErrorDocstrings.i +++ b/lldb/bindings/interface/SBErrorDocstrings.i @@ -10,8 +10,10 @@ For example (from test/python_api/hello_world/TestHelloWorld.py), :: # Spawn a new process and don't
[Lldb-commits] [clang] [clang-tools-extra] [lldb] [llvm] [NFC] Prefer subprocess.DEVNULL over os.devnull (PR #106500)
nicovank wrote: Thanks! I have no commit access, please click the merge button :) https://github.com/llvm/llvm-project/pull/106500 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [lldb] [llvm] Apply modernize-use-starts-ends-with on llvm-project (PR #89140)
https://github.com/nicovank updated https://github.com/llvm/llvm-project/pull/89140 >From 2c82316a0f6641b93c666143211a87f06de8feab Mon Sep 17 00:00:00 2001 From: Nicolas van Kempen Date: Wed, 17 Apr 2024 14:27:42 -0400 Subject: [PATCH] Apply modernize-use-starts-ends-with on llvm-project --- clang-tools-extra/clang-doc/Representation.cpp | 4 ++-- lldb/unittests/Host/FileSystemTest.cpp | 2 +- llvm/unittests/Support/VirtualFileSystemTest.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/clang-tools-extra/clang-doc/Representation.cpp b/clang-tools-extra/clang-doc/Representation.cpp index 84233c36e15d98..2afff2929cf79c 100644 --- a/clang-tools-extra/clang-doc/Representation.cpp +++ b/clang-tools-extra/clang-doc/Representation.cpp @@ -380,8 +380,8 @@ ClangDocContext::ClangDocContext(tooling::ExecutionContext *ECtx, this->SourceRoot = std::string(SourceRootDir); if (!RepositoryUrl.empty()) { this->RepositoryUrl = std::string(RepositoryUrl); -if (!RepositoryUrl.empty() && RepositoryUrl.find("http://";) != 0 && -RepositoryUrl.find("https://";) != 0) +if (!RepositoryUrl.empty() && !RepositoryUrl.starts_with("http://";) && +!RepositoryUrl.starts_with("https://";)) this->RepositoryUrl->insert(0, "https://";); } } diff --git a/lldb/unittests/Host/FileSystemTest.cpp b/lldb/unittests/Host/FileSystemTest.cpp index 3b5ee7c8bc2237..58887f6b2467e0 100644 --- a/lldb/unittests/Host/FileSystemTest.cpp +++ b/lldb/unittests/Host/FileSystemTest.cpp @@ -93,7 +93,7 @@ class DummyFileSystem : public vfs::FileSystem { std::map::iterator I; std::string Path; bool isInPath(StringRef S) { - if (Path.size() < S.size() && S.find(Path) == 0) { + if (Path.size() < S.size() && S.starts_with(Path)) { auto LastSep = S.find_last_of('/'); if (LastSep == Path.size() || LastSep == Path.size() - 1) return true; diff --git a/llvm/unittests/Support/VirtualFileSystemTest.cpp b/llvm/unittests/Support/VirtualFileSystemTest.cpp index e9b4ac3d92e1dd..e9fd9671ea6ab5 100644 --- a/llvm/unittests/Support/VirtualFileSystemTest.cpp +++ b/llvm/unittests/Support/VirtualFileSystemTest.cpp @@ -101,7 +101,7 @@ class DummyFileSystem : public vfs::FileSystem { std::map::iterator I; std::string Path; bool isInPath(StringRef S) { - if (Path.size() < S.size() && S.find(Path) == 0) { + if (Path.size() < S.size() && S.starts_with(Path)) { auto LastSep = S.find_last_of('/'); if (LastSep == Path.size() || LastSep == Path.size() - 1) return true; ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [lldb] [llvm] Apply modernize-use-starts-ends-with on llvm-project (PR #89140)
nicovank wrote: Added one missed instance due to CMake configuration options. https://github.com/llvm/llvm-project/pull/89140 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits
[Lldb-commits] [clang-tools-extra] [lldb] [llvm] Apply modernize-use-starts-ends-with on llvm-project (PR #89140)
nicovank wrote: Maybe @kazutakahirata (or anyone else) can stamp the minor `clang-doc` change? I don't have commit access, feel free to hit merge when everything is in order 👍 . https://github.com/llvm/llvm-project/pull/89140 ___ lldb-commits mailing list lldb-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits