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 <glenn.jocher@ultralytics.com>
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