Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update check_git_status() to run under ROOT working directory #5441

Merged
merged 9 commits into from
Nov 2, 2021
Merged

Update check_git_status() to run under ROOT working directory #5441

merged 9 commits into from
Nov 2, 2021

Conversation

MrinalJain17
Copy link
Contributor

@MrinalJain17 MrinalJain17 commented Nov 1, 2021

Fixes #5440

🛠️ PR Summary

Made with ❤️ by Ultralytics Actions

🌟 Summary

New context manager for changing working directory in code sections.

📊 Key Changes

  • Introduced a new class WorkingDirectory as a context manager to change the current working directory within a code block.
  • The @WorkingDirectory(ROOT) decorator has been applied to the check_git_status function.

🎯 Purpose & Impact

  • 🎯 Purpose: This change allows developers to seamlessly change the working directory while executing certain functions or code blocks, improving code organization and keeping file path references relative and consistent.
  • 💥 Impact: Users can expect more reliable file handling when the script changes directories, potentially reducing file path errors. Additionally, the developers can use this functionality to ensure that certain functions always run in the same directory context, which is especially helpful for maintaining relative paths.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

👋 Hello @MrinalJain17, thank you for submitting a 🚀 PR! To allow your work to be integrated as seamlessly as possible, we advise you to:

  • ✅ Verify your PR is up-to-date with upstream/master. If your PR is behind upstream/master an automatic GitHub actions rebase may be attempted by including the /rebase command in a comment body, or by running the following code, replacing 'feature' with the name of your local branch:
git remote add upstream https://github.com/ultralytics/yolov5.git
git fetch upstream
git checkout feature  # <----- replace 'feature' with local branch name
git merge upstream/master
git push -u origin -f
  • ✅ Verify all Continuous Integration (CI) checks are passing.
  • ✅ Reduce changes to the absolute minimum required for your bug fix or feature addition. "It is not daily increase but daily decrease, hack away the unessential. The closer to the source, the less wastage there is." -Bruce Lee

@MrinalJain17
Copy link
Contributor Author

@glenn-jocher This PR fixes the issue raised in #5440 . Let me know if you have any thoughts on this.

@glenn-jocher
Copy link
Member

@MrinalJain17 this is a nice solution! I like the context manager approach.

My main question here is would it be possible to pass a directory argument to the context manager to generalize it's capability? i.e. something like:

with ChangeWorkingDirectory(dir=ROOT):
    # do stuff

@MrinalJain17
Copy link
Contributor Author

My main question here is would it be possible to pass a directory argument to the context manager to generalize it's capability? i.e. something like:

@glenn-jocher That makes sense. Updated the PR accordingly.

I didn't set a default value within the context manager to avoid any unintended change in the working directory. The user has to explicitly specify the directory to which it should switch.

@glenn-jocher glenn-jocher changed the title Updating check_git_status() to switch to the repository root before performing git ops Update check_git_status() to run under ROOT working directory Nov 2, 2021
@glenn-jocher glenn-jocher merged commit 7476012 into ultralytics:master Nov 2, 2021
@glenn-jocher
Copy link
Member

@MrinalJain17 PR is merged. Thank you for your contributions to YOLOv5 🚀 and Vision AI ⭐

BjarneKuehl pushed a commit to fhkiel-mlaip/yolov5 that referenced this pull request Aug 26, 2022
…tralytics#5441)

* Updating check_git_status() to switch to the repository root before performing git ops

* More pythonic

* Linting

* Remove redundant Path() call

* Generalizing the context manager

* Fixing error in context manager

* Cleanup

* Change to decorator

Co-authored-by: Glenn Jocher <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unexpected behavior of check_git_status() utility function
2 participants