Skip to content
Closed

test #51

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/scripts/merge_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import json
import sys

def load_file(filename):
f = open(filename, "r")

Check warning

Code scanning / CodeQL

File is not always closed Warning

File is opened but is not closed.

Copilot Autofix

AI about 1 month ago

The best way to fix this problem is to ensure that the file is always closed, even if an exception occurs. The most Pythonic and robust way to do this is to use a with statement when opening the file. This ensures that the file is closed automatically when the block is exited, regardless of whether an exception is raised. Specifically, in .github/scripts/merge_packages.py, the function load_file(filename) should be modified so that the file is opened using a with statement, and the file's contents are read within that block. No additional imports or method definitions are needed.


Suggested changeset 1
.github/scripts/merge_packages.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/scripts/merge_packages.py b/.github/scripts/merge_packages.py
--- a/.github/scripts/merge_packages.py
+++ b/.github/scripts/merge_packages.py
@@ -18,4 +18,4 @@
 def load_file(filename):
-    f = open(filename, "r")
-    pkg = json.loads(f.read())["packages"][0]
+    with open(filename, "r") as f:
+        pkg = json.loads(f.read())["packages"][0]
     return pkg
EOF
@@ -18,4 +18,4 @@
def load_file(filename):
f = open(filename, "r")
pkg = json.loads(f.read())["packages"][0]
with open(filename, "r") as f:
pkg = json.loads(f.read())["packages"][0]
return pkg
Copilot is powered by AI and may make mistakes. Always verify output.
pkg = json.loads(f.read())["packages"][0]
return pkg

def load_package(filename):
pkg = json.load(open(filename))["packages"][0]
pkg = load_file(filename)
print("Loaded package {0} from {1}".format(pkg["name"], filename), file=sys.stderr)
print("{0} platform(s), {1} tools".format(len(pkg["platforms"]), len(pkg["tools"])), file=sys.stderr)
return pkg
Expand Down
Loading