-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Fix #5938: Lint checks will run only for the files changed by the user #6033
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #6033 +/- ##
===========================================
- Coverage 45.27% 45.21% -0.06%
===========================================
Files 521 523 +2
Lines 30688 30722 +34
Branches 4597 4605 +8
===========================================
- Hits 13894 13892 -2
- Misses 16794 16830 +36
Continue to review full report at Codecov.
|
scripts/install_third_party.sh
Outdated
if [ ! -d "$TOOLS_DIR/GitPython" ]; then | ||
echo Installing GitPython | ||
|
||
pip install gitpython --target="$TOOLS_DIR/GitPython" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of points here:
- Can we fix the version of
gitpython
we use here? - Can we use curl instead of pip?
Also, the tests seem to be failing on Travis due to import error (see here).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@lilithxxx, the import error in the tests is due to the fact that |
Hi @apb7 I changed the code to use subprocess instead of gitpython. PTAL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @lilithxxx, I think using GitPython would be quite better than using subprocess -- it will streamline the workflow here. Thanks!
@apb7 Made some changes. PTAL |
@lilithxxx, there are still import errors for the package. ptal! Thanks. |
@lilithxxx, I looked into the import error with GitPython. This SO post is useful here -- you need |
scripts/install_third_party.sh
Outdated
@@ -148,6 +148,24 @@ if [ ! -d "$TOOLS_DIR/isort-4.2.15" ]; then | |||
rm isort-4.2.15.tar.gz | |||
fi | |||
|
|||
# Install GitPython and its dependencies. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple of points here -- make this as three separate echo
s instead of one Installing GitPython and its dependencies
so that even if any one of them is already installed, we skip that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
scripts/pre_commit_linter.py
Outdated
@@ -292,6 +292,9 @@ | |||
os.path.join(_PARENT_DIR, 'oppia_tools', 'pylint-quotes-0.1.9'), | |||
os.path.join(_PARENT_DIR, 'oppia_tools', 'selenium-2.53.2'), | |||
os.path.join(_PARENT_DIR, 'oppia_tools', 'PIL-1.1.7'), | |||
os.path.join(_PARENT_DIR, 'oppia_tools', 'GitPython-2.1.11'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Place smmap
first then gitdb
and then GitPython
(in the order of the dependence relation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not done?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So sorry -- done now
scripts/pre_push_hook.py
Outdated
|
||
# Add GitPython to sys.path, then only it can be imported. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change this to Insert GitPython to sys.path so that it can be imported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
scripts/pre_push_hook.py
Outdated
remote_num += 1 | ||
remote_name = remote.name | ||
|
||
if remote_num == 0: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove the equality check, 0 will evaluate to false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this -- We are checking if there is an upstream set or not. Can you please come again? Thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, make it if not remote_num
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
for branch, sha1, remote_sha1 in zip(branches, hashes, remote_hashes): | ||
# Git reports the following for an empty / non existing branch | ||
# sha1: '0000000000000000000000000000000000000000'. | ||
if set(remote_sha1) != {'0'}: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't we require this part, that is, the removed portion of the code now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here it was comparing the changes of the local branch with the local branch itself if the branch is not empty and compared with origin if the branch was empty(i.e had no changes in it)
Now, we are making it compare to upstream at all time.
@apb7 Made the changes. PTAL |
@@ -94,6 +103,33 @@ def _start_subprocess_for_result(cmd): | |||
return out, err | |||
|
|||
|
|||
def _get_remote_name(): | |||
"""Get the remote name of the local repository. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're missing a new line here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
scripts/pre_push_hook.py
Outdated
|
||
# Insert GitPython to sys.path so that it can be imported. | ||
_PARENT_DIR = os.path.abspath(os.path.join(os.getcwd(), os.pardir)) | ||
GIT_PYTHON_PATH = os.path.join(_PARENT_DIR, 'oppia_tools', 'GitPython-2.1.11') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lilithxxx, the build is failing due to import error. I think you'll have to add paths to both the dependencies here as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks @lilithxxx! Tested it by pulling this branch and making several merge commits -- the functionality seems to be working as expected.
@nithusha21, if you're around, can you please give this a try before we merge this? Thanks! |
Tested locally, seems to be working fine! Thanks for the fix @lilithxxx :) |
Fixes #5938
Explanation
Previously the
pre_push_hook
tested against the remote branch of our local repository (i.e local_repo:develop) but now is changed to test against the remote branch of Oppia's repository (i.e oppia:develop). This will prevent the linter to check the files touched by a foreign commit.This requires user to have their upstream set.
Checklist
python scripts/pre_commit_linter.py
andbash scripts/run_frontend_tests.sh
.