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

🔧 MAINTAIN: Update pylint version (& fix new issues) #5087

Merged
merged 12 commits into from
Aug 19, 2021

Conversation

chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Aug 18, 2021

Update pylint pinning to v2.9 and remove restrictions on astroid and pylint-django.

  • django-not-available -> django-not-configured
  • Fix new categories: consider-using-dict-items, consider-using-enumerate, too-many-function-args, consider-using-from-import, consider-using-max-builtin, arguments-renamed, consider-using-with, use-maxsplit-arg, use-a-generator, deprecated-decorator
  • extra disables required for no-member (pylint seems to be getting worse at identifying members, or at least more strict)
  • disable unsubscriptable-object for cif.values

closes #4647

Update pylint to v2.9 and remove restrictions on astroid and pylint-django.

- `django-not-available` -> `django-not-configured`
- Fix new `consider-using-dict-items`, `consider-using-enumerate`, `too-many-function-args`, `consider-using-from-import`, `consider-using-max-builtin`, `arguments-renamed`
- extra disables required for `no-member`
- disable `unsubscriptable-object` for cif.vaues

closes aiidateam#4647
@chrisjsewell chrisjsewell requested a review from sphuber August 18, 2021 19:05
@chrisjsewell
Copy link
Member Author

chrisjsewell commented Aug 18, 2021

Also I removed useless-suppressions from the disabled list (and even tried putting it in an enable list) but pylint still does not seem to identify them. I imagine there is quite a few "dead" ones in the code base now

there was some issues in pylint about this, but they claimed to be closed with the latest pylint (i.e. this one)

@codecov
Copy link

codecov bot commented Aug 18, 2021

Codecov Report

Merging #5087 (af4f54a) into develop (c5e0118) will increase coverage by 0.03%.
The diff coverage is 85.15%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5087      +/-   ##
===========================================
+ Coverage    80.50%   80.52%   +0.03%     
===========================================
  Files          531      531              
  Lines        37020    37095      +75     
===========================================
+ Hits         29799    29867      +68     
- Misses        7221     7228       +7     
Flag Coverage Δ
django 75.02% <84.34%> (+0.03%) ⬆️
sqlalchemy 73.97% <82.74%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/cmdline/commands/cmd_daemon.py 70.88% <0.00%> (ø)
aiida/cmdline/commands/cmd_data/cmd_show.py 16.67% <0.00%> (ø)
aiida/cmdline/commands/cmd_data/cmd_structure.py 84.06% <0.00%> (ø)
aiida/orm/nodes/data/array/bands.py 76.00% <0.00%> (ø)
aiida/orm/nodes/data/array/projection.py 15.45% <0.00%> (ø)
aiida/orm/querybuilder.py 83.94% <ø> (ø)
aiida/tools/data/orbital/realhydrogen.py 70.28% <0.00%> (ø)
aiida/tools/data/structure.py 91.97% <ø> (ø)
aiida/tools/dbimporters/baseclasses.py 75.71% <0.00%> (-0.71%) ⬇️
aiida/tools/dbimporters/plugins/icsd.py 20.98% <0.00%> (-0.15%) ⬇️
... and 58 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c5e0118...af4f54a. Read the comment docs.

@chrisjsewell
Copy link
Member Author

chrisjsewell commented Aug 18, 2021

there's 100s of raise-missing-from errors, so I'm leaving that as disabled for now

@chrisjsewell
Copy link
Member Author

Intend to merge this in the next day, as it will affect all other PRs

@chrisjsewell chrisjsewell changed the title 🔧 MAINTAIN: Update pylint version 🔧 MAINTAIN: Update pylint version (& fix new issues) Aug 18, 2021
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Have a couple of questions about certain disables. Initially repeated them at each line that I though they applied, but stopped after a while because there are so many instances. If you agree that in certain places we should actually fix instead of disabling, please have a look at other instances as well

@@ -254,6 +254,7 @@ def migrate(input_file, output_file, force, in_place, archive_format, version, v

class ExtrasImportCode(Enum):
"""Exit codes for the verdi command line."""
# pylint: disable=invalid-name
Copy link
Contributor

Choose a reason for hiding this comment

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

Won't this now disable this for the entire file? Or is it properly scoped to the enum?

Copy link
Member Author

@chrisjsewell chrisjsewell Aug 18, 2021

Choose a reason for hiding this comment

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

yeh, I was hoping it would be scoped to the enum, or do you think not?

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure to be honest. You could give it a quick try by adding a global constant after the enum declaration which should then incur a warning from pylint if it is properly scoped.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep looks to work as intended, FYI scoping is detailed here: http://pylint.pycqa.org/en/latest/user_guide/message-control.html#block-disables

@@ -158,7 +158,7 @@ def logshow():

try:
currenv = get_env_with_venv_bin()
process = subprocess.Popen(['tail', '-f', client.daemon_log_file], env=currenv)
process = subprocess.Popen(['tail', '-f', client.daemon_log_file], env=currenv) # pylint: disable=consider-using-with
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of disabling, couldn't we actually not better use a with statement here?

Copy link
Member Author

Choose a reason for hiding this comment

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

It wasn't quickly apparent to me how to do this and keep the same behaviour. i.e. is the same?

currenv = get_env_with_venv_bin()
with subprocess.Popen(['tail', '-f', client.daemon_log_file], env=currenv) as process:
   try:
     process.wait()
   except KeyboardInterrupt:
     process.kill()

probably not 🤷

same with the other disable=consider-using-with

Copy link
Contributor

Choose a reason for hiding this comment

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

Fair enough. I would be tempted to do:

currenv = get_env_with_venv_bin()
try:
    with subprocess.Popen(['tail', '-f', client.daemon_log_file], env=currenv) as process:
        process.wait()
except KeyboardInterrupt:
    process.kill()

But I am not sure the try-except is even necessary when using the context manager. Keyboard interrupt should just kill it and the context manager should clean it up properly. Anyway, indeed fine to keep this as is as it is not a trivial change

@@ -220,7 +220,7 @@ def _show_xmgrace(exec_name, list_bands):
'agr', setnumber_offset=current_band_number, color_number=(iband + 1 % MAX_NUM_AGR_COLORS)
)
# write a tempfile
tempf = tempfile.NamedTemporaryFile('w+b', suffix='.agr')
tempf = tempfile.NamedTemporaryFile('w+b', suffix='.agr') # pylint: disable=consider-using-with
Copy link
Contributor

Choose a reason for hiding this comment

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

Idem: Instead of disabling, couldn't we actually not better use a with statement here?

Copy link
Member Author

@chrisjsewell chrisjsewell Aug 18, 2021

Choose a reason for hiding this comment

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

as above, what code would you propose? (just a more complex code changes then I was willing to make, when going through the 100s of issue fixes 😅)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see now. Didn't notice it was creating a list of handles and then processing them. What the hell 🤦‍♂️ OK, fine to leave this as is for now

@@ -114,7 +114,7 @@ def run(scriptname, varargs, auto_group, auto_group_label_prefix, exclude, inclu

try:
# Here we use a standard open and not open, as exec will later fail if passed a unicode type string.
handle = open(scriptname, 'r')
handle = open(scriptname, 'r') # pylint: disable=consider-using-with
Copy link
Contributor

Choose a reason for hiding this comment

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

Idem: instead of disabling, couldn't we actually not better use a with statement here?

Copy link
Member Author

@chrisjsewell chrisjsewell Aug 18, 2021

Choose a reason for hiding this comment

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

as above; basically I would maybe open a separate issue to address seom of the disable=consider-using-with, because some of them feel like they need a bit of scrutiny to double check they won't break the current behaviour

Copy link
Contributor

Choose a reason for hiding this comment

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

Good idea to open an issue and leave all of these with disable statements for now

aiida/cmdline/commands/cmd_status.py Show resolved Hide resolved
aiida/cmdline/params/types/identifier.py Show resolved Hide resolved
aiida/cmdline/params/types/path.py Outdated Show resolved Hide resolved
aiida/orm/nodes/data/data.py Outdated Show resolved Hide resolved
aiida/orm/utils/loaders.py Show resolved Hide resolved
aiida/tools/data/cif.py Outdated Show resolved Hide resolved
@chrisjsewell chrisjsewell requested a review from sphuber August 18, 2021 21:09
@chrisjsewell
Copy link
Member Author

addressed your comments thanks @sphuber

Comment on lines 154 to 162
@classmethod
def validate_resources(cls, **kwargs):
"""Validate the resources against the job resource class of this scheduler.

:param kwargs: dictionary of values to define the job resources
:return: attribute dictionary with the parsed parameters populated
:raises ValueError: if the resources are invalid or incomplete
"""

Copy link
Member Author

Choose a reason for hiding this comment

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

Guessing @abstractclassmethod didn't actually work, since this was not picked up before? @sphuber I guess this should probably have some content

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that is weird indeed. I guess the validation is already done in the constructor. We can just move that logic to the validate_resources. To be safe as to not break anything, you can always still call self.validate_resources(**kwargs) from the constructor, which is what the NodeNumberJobResource also does.

Copy link
Member Author

Choose a reason for hiding this comment

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

done

sphuber
sphuber previously approved these changes Aug 19, 2021
Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks @chrisjsewell . Would be good if you can still check the comment on the Enum and the scheduler job resource validation, but am already approving this

@chrisjsewell
Copy link
Member Author

all done cheers

@chrisjsewell chrisjsewell merged commit 3b5c975 into aiidateam:develop Aug 19, 2021
@chrisjsewell chrisjsewell deleted the update-pylint branch August 19, 2021 22:47
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.

Unpin doc/dev dependencies
2 participants