Skip to content

pylint: enable additional checks #4122

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

Merged
merged 1 commit into from
Jun 29, 2020
Merged

pylint: enable additional checks #4122

merged 1 commit into from
Jun 29, 2020

Conversation

skshetry
Copy link
Collaborator

@skshetry skshetry commented Jun 26, 2020

  • ❗ I have followed the Contributing to DVC checklist.

  • πŸ“– If this PR requires documentation updates, I have created a separate PR (or issue, at least) in dvc.org and linked it here.

  • ❌ I will check DeepSource, CodeClimate, and other sanity checks below. (We consider them recommendatory and don't expect everything to be addressed. Please fix things that actually improve code or fix bugs.)

Thank you for the contribution - we'll try to review it as soon as possible. πŸ™

@skshetry skshetry added the enhancement Enhances DVC label Jun 26, 2020
@skshetry skshetry self-assigned this Jun 26, 2020
@skshetry skshetry force-pushed the pylint-additional-checks branch 2 times, most recently from 85622a4 to 3001392 Compare June 28, 2020 08:23
@codecov
Copy link

codecov bot commented Jun 28, 2020

Codecov Report

Merging #4122 into master will decrease coverage by 0.06%.
The diff coverage is 85.71%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #4122      +/-   ##
==========================================
- Coverage   92.76%   92.70%   -0.07%     
==========================================
  Files         162      162              
  Lines       11278    11288      +10     
==========================================
+ Hits        10462    10464       +2     
- Misses        816      824       +8     
Impacted Files Coverage Ξ”
dvc/cache.py 90.42% <ΓΈ> (ΓΈ)
dvc/external_repo.py 86.59% <ΓΈ> (ΓΈ)
dvc/logger.py 87.50% <ΓΈ> (ΓΈ)
dvc/main.py 77.77% <0.00%> (-4.58%) ⬇️
dvc/output/base.py 95.34% <ΓΈ> (ΓΈ)
dvc/remote/gs.py 94.95% <ΓΈ> (ΓΈ)
dvc/repo/__init__.py 98.19% <ΓΈ> (ΓΈ)
dvc/scm/git/tree.py 94.49% <0.00%> (ΓΈ)
dvc/scm/git/__init__.py 87.45% <50.00%> (ΓΈ)
dvc/api.py 97.67% <100.00%> (ΓΈ)
... and 25 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 83a2afc...3259a43. Read the comment docs.

Created a separate pylint plugin to disable some checks for tests.
@skshetry skshetry force-pushed the pylint-additional-checks branch from 3001392 to 3259a43 Compare June 29, 2020 06:00
# Enabling soon:
no-member,
unused-argument,
arguments-differ,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Only checks that are important is for missing docstring and logging format (with lazy logging).

Comment on lines -68 to +69
except Exception as exc: # pylint: disable=broad-except
if isinstance(exc, OSError) and exc.errno == errno.EMFILE:
except OSError as exc:
if exc.errno == errno.EMFILE:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Changed code to make pylint understand Exception better.

Copy link
Contributor

Choose a reason for hiding this comment

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

This one is questionable, just duplicating the code :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's worth it to separate exception here. The duplication is 2 lines and most of it is incidental, the return code and message can change independently like in the above try-except ladder.

I could do:

if ret == 255:
  logger.info("unexpected error")

But, I don't think it's worth the hassle.

@@ -100,7 +100,7 @@ class BaseRemoteTree:

CACHE_MODE = None
SHARED_MODE_MAP = {None: (None, None), "group": (None, None)}
CHECKSUM_DIR_SUFFIX = ".dir"
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Duplicated above

@@ -79,7 +79,7 @@ def getsize(self, path):

return 0

def exists(self, path, sftp=None):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Unused arg.

@@ -841,7 +841,7 @@ def test(self):
self.assertTrue(filecmp.cmp(foo, bar, shallow=False))


class TestReproExternalBase(SingleStageRun, TestDvc):
class ReproExternalTestMixin(SingleStageRun, TestDvc):
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pylint understands use of Mixin, so, it does not throw any error if any member is not found. eg: self.bucket.

@@ -0,0 +1,47 @@
"""
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pylint does not allow different configs per directory. It requires a "run-twice" or a "disable-on-each-file" solution.
Therefore, I wrote this hack/plugin for now. If it becomes hard to maintain, I'll just remove this and substitute with "run-twice" solution with two .pylintrc, one for dvc and one for tests.

@skshetry skshetry changed the title [WIP] pylint: enable additional checks pylint: enable additional checks Jun 29, 2020
Comment on lines +18 to +22
init-hook="import sys; \
from pathlib import Path; \
from pylint.config import find_pylintrc; \
sys.path.append(Path(find_pylintrc()).parent / 'tests');"

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Required for loading the plugin.

@skshetry skshetry marked this pull request as ready for review June 29, 2020 06:12
@skshetry skshetry requested review from pmrowla, efiop and pared June 29, 2020 06:13
@@ -413,7 +419,7 @@ def upload(self, from_info, to_info, name=None, no_progress_bar=False):

name = name or from_info.name

self._upload(
self._upload( # noqa, pylint: disable=no-member
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think, we should create an _upload/_download function in the base class that just throws RemoteActionNotImplemented error. It would make this cleaner (without ignore, that is), and provide stronger checks-and-balances.


def is_node_in_tests(node: "node_classes.NodeNG"):
module: "scoped_nodes.Module" = node.root()
return module.file.startswith(TESTS_FOLDER)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@efiop, @pmrowla, @pared, I think we could do a similar prefix-based solution to reduce some relpath/abspath calls.

def open(self, path, mode="r", encoding="utf-8", remote=None):
def open(
self, path, mode="r", encoding="utf-8", remote=None
): # pylint: disable=arguments-differ
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we start preferring the use of **kwargs in these kinds of cases instead of suppressing this pylint test each time?

@efiop efiop merged commit 1c0f5cd into master Jun 29, 2020
@delete-merged-branch delete-merged-branch bot deleted the pylint-additional-checks branch June 29, 2020 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhances DVC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants