Skip to content

fix: make preconfigure download paths consistent#2648

Merged
pcarruscag merged 5 commits intosu2code:developfrom
shbhmexe:bugfix/preconfigure-download-paths
Dec 18, 2025
Merged

fix: make preconfigure download paths consistent#2648
pcarruscag merged 5 commits intosu2code:developfrom
shbhmexe:bugfix/preconfigure-download-paths

Conversation

@shbhmexe
Copy link

@shbhmexe shbhmexe commented Dec 17, 2025

Proposed Changes

This PR fixes path handling in the Meson/Ninja preconfigure tooling so downloads and extracted artifacts are placed relative to the script directory (not the current working directory). This makes preconfigure.py/meson.py more reliable when invoked from outside the repo root.

Files Modified:

Module File Changes
SU2_BUILD preconfigure.py Download ninja-win.zip into the script directory; fix undefined exception variable in the download error path; ensure built ninja is copied into the script directory; close zip after extraction.
SU2_BUILD meson_scripts/init.py Save downloaded module archives into the script directory (consistent with later open/remove); close zip after extraction.

Issues Fixed

Preconfigure Tooling:

Issue Impact Fix
ninja-win.zip saved to CWD but later opened/removed from script dir FileNotFoundError when running preconfigure.py from outside repo root (Windows) Download to sys.path[0]/ninja-win.zip and extract from the same path.
Undefined exception variable in download failure path NameError that hides the real download failure Use except Exception as e: and print the actual exception.
Module archives saved to CWD but later opened/removed from script dir FileNotFoundError for non-git source distributions or when using URL downloads from outside repo root Download to sys.path[0] (expected filepath).
Zip files not closed after extraction Potential file-handle leaks / Windows file lock issues Use context managers (with ZipFile(...) as zipf).
Built ninja copied to . instead of script dir (non-Windows) meson.py expects sys.path[0]/ninja, which can break if invoked from another working directory Copy to sys.path[0]/ninja.

Related Work

This PR improves the build/preconfiguration workflow described in README.md (Meson + Ninja via meson.py) by making downloads path-safe.

PR Checklist

  • I am submitting my contribution to the develop branch.
  • My contribution generates no new compiler warnings.
  • My contribution is commented and consistent with SU2 style.
  • I used the pre-commit hook to prevent dirty commits.
  • I have added a test case that demonstrates my contribution, if necessary.
  • I have updated appropriate documentation, if necessary.

shbhmexe added 2 commits December 17, 2025 16:30
Ensure preconfigure tooling saves downloaded archives next to the scripts that later extract/remove them (ninja-win.zip and module zips), making invocations from outside the repo root reliable. Also fix a NameError in the download error path and close zipfiles after extraction.

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
preconfigure.py Outdated
# 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")

preconfigure.py Outdated
)
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.

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.

Signed-off-by: shbhmexe <shubhushukla586@gmail.com>
@pcarruscag pcarruscag merged commit 0ce78f6 into su2code:develop Dec 18, 2025
19 of 20 checks passed
@shbhmexe
Copy link
Author

@pcarruscag Sir please check this also #2636

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants