Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 3 additions & 3 deletions meson_scripts/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ def _extract_member(self, member, targetpath, pwd):

if not os.path.exists(filepath) and not os.path.exists(alt_filepath):
try:
urllib.request.urlretrieve(url, commit_sha + ".zip")
urllib.request.urlretrieve(url, filepath)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't look equivalent.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urlretrieve() now writes to filename again (commit_sha + ".zip"), which matches the previous behavior. We still compute filepath/alt_filepath for the later existence check/unzip. Verified locally with python -m compileall preconfigure.py meson_scripts/init.py.

except Exception as e:
print(e)
print("Download of module " + name + " failed.")
Expand All @@ -303,8 +303,8 @@ def _extract_member(self, member, targetpath, pwd):
filepath = alt_filepath

# Unzip file
zipf = MyZipFile(filepath)
zipf.extractall(target_dir)
with MyZipFile(filepath) as zipf:
zipf.extractall(target_dir)

# Remove directory if exists
if os.path.exists(alt_name):
Expand Down
15 changes: 9 additions & 6 deletions preconfigure.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def build_ninja():
# If we are on windows, we don't need to compile ninja, we just download the executable
if os.name == "nt":
ninja_exe_url = "https://github.com/ninja-build/ninja/releases/download/v1.13.0/ninja-win.zip"
ninja_zip_path = sys.path[0] + os.path.sep + "ninja-win.zip"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't path.Join the pythonic way of doing it?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os.path.join() / Path is the more idiomatic and safer way to build paths (cleaner, avoids manual separator handling, and stays cross-platform). I’ll switch this to os.path.join(sys.path[0], "ninja-win.zip") for consistency.
Does that work for your expectations here, or would you prefer I keep the current sys.path[0] + os.path.sep + ... style? If it’s not suitable, I can revert/adjust accordingly.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change to join please

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done , updated it to use os.path.join(sys.path[0], "ninja-win.zip")


# Try to execute ninja, if it fails, download .exe from github
try:
Expand All @@ -48,18 +49,18 @@ def build_ninja():
except OSError:
print("Downloading ninja ... ")
try:
urllib.request.urlretrieve(ninja_exe_url, "ninja-win.zip")
except:
urllib.request.urlretrieve(ninja_exe_url, ninja_zip_path)
except Exception as e:
print(e)
print("Download of ninja executable failed.")
print("Get archive at " + ninja_exe_url)
print("extract ninja.exe in the source code root folder.")
print("Run meson.py again.")
sys.exit(1)

zipf = zipfile.ZipFile(sys.path[0] + os.path.sep + "ninja-win.zip")
zipf.extractall(sys.path[0])
remove_file(sys.path[0] + os.path.sep + "ninja-win.zip")
with zipfile.ZipFile(ninja_zip_path) as zipf:
zipf.extractall(sys.path[0])
remove_file(ninja_zip_path)
else:
ninjapath = sys.path[0] + os.path.sep + "externals" + os.path.sep + "ninja"
try:
Expand All @@ -75,7 +76,9 @@ def build_ninja():
subprocess.run(
["python3", "configure.py", "--bootstrap"], cwd=ninjapath, env=env
)
shutil.copy(ninjapath + os.path.sep + "ninja", ".")
shutil.copy(
ninjapath + os.path.sep + "ninja", sys.path[0] + os.path.sep + "ninja"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done — updated the shutil.copy() call to use os.path.join(...) for both src/dst, so the ninja binary is copied to the repo root (sys.path[0]) without relying on the current working directory.

)


def run(
Expand Down
Loading