fix: use absolute path for aco_tsp data file#383
Open
himanksingh2024-svg wants to merge 5 commits intomesa:mainfrom
Open
fix: use absolute path for aco_tsp data file#383himanksingh2024-svg wants to merge 5 commits intomesa:mainfrom
himanksingh2024-svg wants to merge 5 commits intomesa:mainfrom
Conversation
Contributor
|
also can you improve the PR description following the PR requirements mentioned in : mesa/mesa#3536 (comment) |
ShreyasN707
approved these changes
Mar 15, 2026
|
|
||
| tsp_graph = TSPGraph.from_tsp_file("aco_tsp/data/kroA100.tsp") | ||
| tsp_graph = TSPGraph.from_tsp_file( | ||
| os.path.join(os.path.dirname(__file__), "aco_tsp/data/kroA100.tsp") |
Contributor
There was a problem hiding this comment.
since app.py is already inside the aco_tsp directory, the joined path may not need the extra aco_tsp/ prefix. Using:
os.path.join(os.path.dirname(__file__), "data/kroA100.tsp")
would resolve directly to the data folder next to the script.
Author
|
Updated the fix based on @ShreyasN707's review. The path is correct as aco_tsp/data/kroA100.tsp relative to app.py since the data folder is inside the aco_tsp subdirectory. |
Member
|
Cool seeing a peer-review going! I wrote down a checklist, maybe it's useful! |
Author
himanksingh2024-svg
left a comment
There was a problem hiding this comment.
Self-review:
- ✅ Fix is minimal — only changes the file path, nothing else
- ✅ Tested locally — python examples/aco_tsp/app.py runs with no errors
- ✅ No dead code or unused imports added (os was already needed)
- ✅ No deprecated APIs used
- ✅ Simplest solution to the FileNotFoundError problem
ShreyasN707
approved these changes
Mar 16, 2026
Contributor
ShreyasN707
left a comment
There was a problem hiding this comment.
@EwoutH I have checked this PR locally and works. This is the notes:
Is it correct and current?
- Uses current Mesa APIs (no deprecated features)
- Fixes the
FileNotFoundErrorcaused by the relative data path - Example runs correctly from different working directories
Is the fix appropriate?
- Uses a robust path resolution (
os.path.dirname(__file__)) - Change is minimal and does not affect model logic
Is it clean?
- No unnecessary code changes
- Clear and readable modification
- PR description explains the issue and fix
- Commits are clean and relevant
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.
Thanks for opening a PR! Please click the
Previewtab and select a PR template:Problem: The aco_tsp example fails with FileNotFoundError when run from the repo root directory because the data file path is relative.
Fix: Used os.path.dirname(file) to make the path absolute, so it works regardless of where the script is run from.
Fixes the error: FileNotFoundError: No such file or directory: 'aco_tsp/data/kroA100.tsp'
GSoC contributor checklist
Context & motivation
I found this bug while testing mesa-examples locally. When running the aco_tsp example from the repo root, it throws a FileNotFoundError because the data file path is relative to the working directory, not the script location. This is a real usability issue for anyone trying to run the examples.
What I learned
I learned that file paths in Python scripts should use os.path.dirname(file) to be robust regardless of where the script is run from. I also learned the Mesa contribution workflow including forking, branching, and PR process.
Learning repo
🔗 My learning repo: https://github.com/himanksingh2024-svg/GSoC-learning-space
🔗 Relevant model(s): N/A (bug fix PR)
Readiness checks