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
USHIFT-1030: fix pylint finding issues #1614
USHIFT-1030: fix pylint finding issues #1614
Conversation
@chiragkyal: This pull request references USHIFT-1031 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Skipping CI for Draft Pull Request. |
@chiragkyal: This pull request references USHIFT-1030 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
/jira refresh |
@chiragkyal: This pull request references USHIFT-1030 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra 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.
Most of these changes look good. I had a couple of questions but nothing jumps out at me as problematic.
Some of these scripts are dev tools and are not tested in CI, so I wonder if we should apply the same approach we said we would for the bash linter? That would give us a chance to test some of them individually in case we miss an issue with visual inspection.
Apart from these, there are a lot of
I think we can snooze them, because it may impact code readability with not so valuable code changes. |
For sure, so if I'm not wrong, the plan would be to merge one file at a time. |
scripts/auto-rebase/handle-assets.py
Outdated
@@ -19,18 +26,23 @@ | |||
|
|||
|
|||
def merge_paths(pathl, pathr): | |||
"""Merge two paths into one by removing any '/' prefix from pathr and then appending it to pathl""" |
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 exactly.
If pathr
starts with /
it means it's absolute, so we discard that leading /
and return what's left.
If it's relative, then we return pathl/pathr
.
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.
Oh, yes, I misread the code again. :-(
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.
Changed this to :
"""
Merge two paths depending upon following conditions:
- If `pathr` is absolute (starts with `/`), then discard the leading `/` and return rest `pathr`.
- If `pathr` is relative, then return `pathl/pathr`.
"""
|
||
|
||
def main(): | ||
"""Main function for handling assets based on the recipe file.""" |
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 see that this docstring ends with .
but it doesn't seem to be the case for other docstrings. Do we need to be consistent? Does pep8 or other code style guidelines say anything about this?
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.
Checked a few examples in PEP 257 – Docstring Conventions, and most of them end with .
So, I've added .
for all other docstring to be consistent
scripts/auto-rebase/rebase.py
Outdated
""" | ||
Posts a comment on a GitHub pull request. | ||
If there are any extra messages in the global `_extra_msgs` list, | ||
they will be appended to the comment. |
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.
Actually they're not appended to a comment - a new comment is created with contents of _extra_msgs
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.
Changed to
"""
Posts a comment on a GitHub pull request with
the contents of the global `_extra_msgs` list.
"""
|
||
actions = [] | ||
actions_list = [] |
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.
query_str = JQL_FILTER_QUERY
and this line makes me want to ignore the rule... This reminds me of C language code style
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.
C0103 is a very broad check for all types of naming conventions; I think we should keep it.
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.
The main reason for this change is because actions
and query
are conflicting with the local variables defined in other functions. We need to either change in main
function or in all other functions where it has been used.
for i in tqdm(range(len(query))): | ||
try: | ||
issue = query[i] | ||
issuee = query[i] |
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.
What is reason for this change?
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.
W0621: Redefining name 'issue' from outer scope (line 338) (redefined-outer-name)
Because issue
is getting used in most of the function definitions. So, either change it in main
function or in all the functions where issue
is used. I chose to change in main
function for simplicity and less line of change.
Before merging this needs be tested in rebase scenario - either manually running |
scripts/auto-rebase/handle-assets.py
Outdated
@@ -19,18 +26,23 @@ | |||
|
|||
|
|||
def merge_paths(pathl, pathr): | |||
"""Merge two paths into one by removing any '/' prefix from pathr and then appending it to pathl""" |
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.
Oh, yes, I misread the code again. :-(
@@ -1,8 +1,15 @@ | |||
#!/usr/bin/env python | |||
# pylint: disable=fixme,global-statement,too-many-statements,too-many-locals,broad-except |
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.
Yes, let's be very careful with this file.
b84f3e6
to
431046d
Compare
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 had 2 comments, but nothing to hold this up. They can be addressed in another PR, unless you want to fix them as part of addressing other comments.
I want to leave this open for @pmtk to approve, since he is more familiar with the code being changed and had previous review comments.
hack/verify-py.sh
Outdated
|
||
if ! command -v ${PYLINT} &>/dev/null; then | ||
|
||
check="$(python3 -m pip install -r ${REQ_FILE} 2>&1 | { grep 'Permission denied' || true; })" |
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 not just use the virtualenv all the time?
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.
The pylint installation worked fine directly in RHEL dev VM, without virtualenv. And as virtualenv will put a little overhead in the VM, I think we should do that only for CI.
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'm on a fence with this one, I'd like to have the same flow in CI and locally whenever possible.
Do we need all the packages listed in requirements.txt
for pylint? (I'd move that file to scripts/auto-rebase/
)
If pylint can run without all packages, then what about:
- here we just setup venv and install pylint - this will reduce the overhead
- to further reduce it, we could run
venv --symlinks
on my local system it's 33mb vs 23mb - we could setup pylint venv in
_output/
, so consecutive runs (in local VM) don't have to redo the venv
What do you think?
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.
Yes, we need all the packages listed in requirements.txt
for pylint to run successfully, otherwise it will throw (import-error)
.
For having venv locally, we could setup that in _output/
folder and install all the dependencies there. In that case, we should run all python screipts from that venv, and install further dependencies there only. We should not have two copies of 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.
As discussed in Slack, we may later on, create a separate PR to run all .py scripts from venv rather than requiring to have deps installed on system (usually /usr/, and not $HOME...)
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.
It's not really recommended practice to use pip to install things directly into the system python space, so I would prefer we use virtualenv all the time.
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.
Okay, I've updated the script to create a virtual environment all the time.
requirements.txt
Outdated
@@ -0,0 +1,7 @@ | |||
PyGithub==1.56 |
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.
Over time, especially as we set up e2e tests, we are likely to have different requirements files for different purposes. This one should probably move to hack as something like hack/requirements.txt
so we can differentiate it from validate-microshift/requirements.txt
in the future.
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 that script/auto-rebase/rebase.py
and (if we decide so) e2e/tests.py
should have separate requirements.txt
in their own dirs. Does it make sense from how python project operate?
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 am unsure what is the recommended way, however we need all the dependencies installed before running pylint. We may have to loop over all the requirements.txt
files if we choose to have multiple.
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.
As discussed, moved the requirements.txt
into scripts/
dir
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.
Let's get "venv in CI and locally" and "/requirements.txt" topics sorted out and I think we're good to go
hack/verify-py.sh
Outdated
|
||
if ! command -v ${PYLINT} &>/dev/null; then | ||
|
||
check="$(python3 -m pip install -r ${REQ_FILE} 2>&1 | { grep 'Permission denied' || true; })" |
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'm on a fence with this one, I'd like to have the same flow in CI and locally whenever possible.
Do we need all the packages listed in requirements.txt
for pylint? (I'd move that file to scripts/auto-rebase/
)
If pylint can run without all packages, then what about:
- here we just setup venv and install pylint - this will reduce the overhead
- to further reduce it, we could run
venv --symlinks
on my local system it's 33mb vs 23mb - we could setup pylint venv in
_output/
, so consecutive runs (in local VM) don't have to redo the venv
What do you think?
requirements.txt
Outdated
@@ -0,0 +1,7 @@ | |||
PyGithub==1.56 |
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 that script/auto-rebase/rebase.py
and (if we decide so) e2e/tests.py
should have separate requirements.txt
in their own dirs. Does it make sense from how python project operate?
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: chiragkyal, pmtk The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@chiragkyal: all tests passed! Full PR test history. Your PR dashboard. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
@chiragkyal: This pull request references USHIFT-1030 which is a valid jira issue. In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Which issue(s) this PR addresses:
https://issues.redhat.com/browse/USHIFT-1030
This PR will
hack/verify-py.sh
script to create a virtual python environment in_output/venv
and install all python dependency packages in that environment and run pylint..py
files.scripts/requirements.txt
, which lists all the dependency packagesmake verify-py
in theverify
CI job