Fix FileNotFoundError in Constellations Generation Testing by Ensuring Parent Directories Exist#3
Open
Jxpro wants to merge 2 commits intoSpaceNetLab:release/v2.0from
Open
Fix FileNotFoundError in Constellations Generation Testing by Ensuring Parent Directories Exist#3Jxpro wants to merge 2 commits intoSpaceNetLab:release/v2.0from
Jxpro wants to merge 2 commits intoSpaceNetLab:release/v2.0from
Conversation
Member
|
Good catch! @Jxpro But I believe there's a better way to refactor this issue: We can define a helper function globally that automatically gets called whenever Here's an example for your reference: Func Defdef safe_open(file_path, mode='r', *args, **kwargs):
"""Safely open a file, automatically creating parent directories if needed.
Args
param file_path: Path to the file.
param mode: File open mode, e.g., 'r', 'w', 'a'.
"""
if 'w' in mode or 'a' in mode or 'x' in mode:
os.makedirs(os.path.dirname(file_path), exist_ok=True)
return open(file_path, mode, *args, **kwargs)Func Callingwith safe_open('data/TLE_constellation/sat_data.txt', 'w') as f:
f.write('satellite info')HighlightLet's go further, there are some similar problems to be solved:
It would be great if these common scenarios could all be encapsulated within a single, versatile function. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The StarPerf suite's XML and TLE Constellations Testing modules encounter a
FileNotFoundErrorwhen attempting to create or access.h5files within thedata/XML_constellation/anddata/TLE_constellation/directories. This issue predominantly arises after agit cloneoperation, as Git does not track empty directories, resulting in the absence of these critical paths in the cloned repository structure.The primary cause of this issue is the nature of
git cloneoperations where directories without files are not created in the cloned repository. As a result, the expected directory structure needed for file operations does not exist, causing runtime errors during constellation data generation.Log
Solution
Modified the
constellation_configurationfunction to check and create thedata/XML_constellation/anddata/TLE_constellation/directories if it does not exist. This is achieved using theos.makedirs()function with theexist_ok=Trueparameter, ensuring idempotency.Testing
✅ Ensured existing unit tests pass with the proposed changes
✅ Manual testing performed post-
git cloneto validate the fix