You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR addresses a common first-run issue where systems.json is missing from the user's config directory. The approach includes packaging the file and auto-copying it, plus an important bug fix for directory existence checking.
✅ What's Good
Bug fix in search() (lines 183-186): This is a solid fix. The original code would raise FileNotFoundError when system_dir doesn't exist, since os.listdir() was evaluated before the os.path.exists() check. Your fix properly guards the os.listdir() call.
MANIFEST.in addition: Including systems.json in the package manifest is the right approach for distributing default config files.
.gitignore addition: Standard practice for Python projects.
Issue: This assumes systems.json lives outside the package directory (one level up). This works in development but will fail after pip install because:
Installed packages go to site-packages/retro/
The ../systems.json resolves to site-packages/systems.json, which won't exist
Recommendation: Use importlib.resources (Python 3.7+) or bundle systems.jsoninside the retro package:
# Option A: Python 3.9+fromimportlib.resourcesimportfilessource=files(retro).joinpath(systems.json)
# Option B: Older Pythonimportpkgutilsource=os.path.join(pkg_dir, systems.json) # Keep it inside the package
Then move systems.json to retro/systems.json and update MANIFEST.in accordingly.
Issue: Silent failures. If shutil.copy fails (permissions, disk full, etc.), the user gets no feedback.
Recommendation:
ifos.path.exists(source):
try:
shutil.copy(source, self.cfg)
except (IOError, OSError) ase:
print(f"Warning: Could not copy systems.json: {e}")
3. Race Condition (Minor)
Between os.path.exists(self.cfg) and shutil.copy(), another process could create the file. Consider using shutil.copy2() with existence check inside a try/except.
4. Missing Newline in .gitignore
- +venv/ \ No newline at end of file
It's a minor nit, but files should end with a newline. Add an empty line at the end.
Additional Suggestion
Consider adding logging instead of silent operations:
importlogginglogging.basicConfig(level=logging.INFO)
logger=logging.getLogger(__name__)
def_ensure_systems_json(self):
ifos.path.exists(self.cfg):
returnlogger.info(f"systems.json not found, creating default at {self.cfg}")
# ... rest of implementation
Verdict
Approve with minor changes requested. The bug fix is correct and the intent is solid, but the path resolution needs to be more robust for installed packages. The current implementation works only in development environments.
Would you like me to submit a patch for the importlib.resources approach?
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
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.
Without this we need to copy systems.json to retro folder.