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

Bug fixes, linting, drop python3.4 and Travis rework #255

Merged
merged 45 commits into from Jun 5, 2018

Conversation

Bastian-Krause
Copy link
Member

@Bastian-Krause Bastian-Krause commented Jun 1, 2018

This PR includes several bug fixes. These bugs were found while using pylint. To be more consistent in coding style fix most of the linting warnings and all errors. Some warnings were left out, because the fix is either not obvious or time consuming. This is work tbd.

While at it python3.4 support was dropped.

Finally Travis-CI should check for linting errors to prevent those bugs from now on.

I think more warnings and errors should be ignored, but we need a separate discussion for that. Some warnings are caused by pylint not recognizing attr behavior. Discussion happens in #257.

@Bastian-Krause Bastian-Krause force-pushed the bst/linting branch 2 times, most recently from c73c43f to 6fb53a0 Compare June 1, 2018 09:36
@codecov-io
Copy link

codecov-io commented Jun 1, 2018

Codecov Report

Merging #255 into master will decrease coverage by 0.3%.
The diff coverage is 47.4%.

Impacted file tree graph

@@           Coverage Diff            @@
##           master    #255     +/-   ##
========================================
- Coverage    54.9%   54.5%   -0.4%     
========================================
  Files         105     105             
  Lines        6229    6181     -48     
========================================
- Hits         3424    3374     -50     
- Misses       2805    2807      +2
Impacted Files Coverage Δ
labgrid/util/agentwrapper.py 100% <ø> (ø) ⬆️
labgrid/resource/ykushpowerport.py 100% <ø> (ø) ⬆️
labgrid/protocol/commandprotocol.py 100% <ø> (ø) ⬆️
labgrid/resource/serialport.py 94.1% <ø> (ø) ⬆️
labgrid/driver/smallubootdriver.py 42.4% <ø> (-8.9%) ⬇️
labgrid/util/expect.py 76.4% <ø> (-2.5%) ⬇️
labgrid/protocol/linuxbootprotocol.py 100% <ø> (ø) ⬆️
labgrid/pytestplugin/reporter.py 34.5% <0%> (ø) ⬆️
labgrid/driver/powerdriver.py 69.3% <0%> (-0.2%) ⬇️
labgrid/remote/authenticator.py 0% <0%> (ø) ⬆️
... and 62 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 8289085...ed61360. Read the comment docs.

@Emantor
Copy link
Member

Emantor commented Jun 4, 2018

Do you have any idea why coverages takes a nosedive?

@Bastian-Krause
Copy link
Member Author

Do you have any idea why coverages takes a nosedive?

Yes, this is mostly caused by "drop python3.4 support" and "linting: do miscellaneous linting". These commits remove lines, either by dropping the @asyncio.coroutine decorator line on tested code or by
reformatting (joining lines of tested code or adding line breaks in untested code). See code coverage drops in:

@Bastian-Krause
Copy link
Member Author

  • rebased
  • drop "factory: normalize config with correct driver class" in favor of merged minor factory fixes #258
  • sort "strategy/graphstrategy: simplify dict iteration in graph()" after "linting: strategy/graphstrategy: no empty list as arg default" and prefix with "linting: "

@Bastian-Krause
Copy link
Member Author

  • rebased
  • ignore linting errors when emitting exit code

@Bastian-Krause
Copy link
Member Author

  • tox.ini: use leading minus instead of ignore_errors=True in order not to influence the tox exit code

Copy link
Member

@jluebbe jluebbe left a comment

Choose a reason for hiding this comment

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

Please leave out the tox-related changes for now. I'd like to do my own experiments with it first.

@@ -73,7 +73,7 @@ def run(self):
self.context['target'] = self.target
if self.target is None:
raise KeyError
except:
except KeyError:
Copy link
Member

Choose a reason for hiding this comment

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

Other exceptions can be generated by env.get_target() during target creation, which should also be caught by this catch all.

"""
Helper function to get a resource of the target.
Returns the first valid resource found, otherwise None.

Arguments:
cls -- resource-class to return as a resource
name -- optional name to use as a filter
await -- wait for the resource to become available (default True)
wait_for -- wait for the resource to become available (default True)
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer wait_avail instead of wait_for. wait_for suggests that you need to pass the thing you want to wait for.

@@ -381,13 +381,9 @@ def onChallenge(self, challenge):
self.loop.stop()

async def acquire(self, group_name, resource_name):
resource = self.groups[group_name][resource_name]
Copy link
Member

Choose a reason for hiding this comment

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

This (and the one below) should actually be TODOs. We want to be able to perform local actions when a resource is acquired, and this would be the correct place when we get around to that.

@@ -61,13 +61,14 @@ def on_activate(self):
self._inject_run()
if self.keyfile:
self._put_ssh_key(self.keyfile)
self._run("dmesg -n 1") # Turn off Kernel Messages to the console
# Turn off Kernel Messages to the console
self._run("dmesg -n 1") # pylint: disable=missing-kwoa
Copy link
Member

Choose a reason for hiding this comment

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

Please disable missing-kwoa and unused-argument for the whole file. The annotations are too noisy.

@@ -103,8 +103,8 @@ class Place:
acquired = attr.ib(default=None)
acquired_resources = attr.ib(default=attr.Factory(list))
allowed = attr.ib(default=attr.Factory(set), convert=set)
created = attr.ib(default=attr.Factory(lambda: time.time()))
changed = attr.ib(default=attr.Factory(lambda: time.time()))
created = attr.ib(default=attr.Factory(lambda: time.time())) # pylint: disable=unnecessary-lambda
Copy link
Member

Choose a reason for hiding this comment

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

This message seems correct, we should just use Factory(time.time).

@@ -16,27 +16,27 @@ def __attrs_post_init__(self):

@property
def avail(self):
return self.data['avail']
return self.data['avail'] # pylint: disable=unsubscriptable-object
Copy link
Member

Choose a reason for hiding this comment

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

Disable this for the whole file.

…erFoundError

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
The attr property is a duplicate of the property method with the same
name. As this property is not intended to be given to the init method,
remove it.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Prevent overwriting built-in function vars().

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
This was propably a copy/paste error.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
There is no need to use the list type constructor for "args". "args" is
alreay a list.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
This is useful for debugging.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Do not use mutable values as dangerous default values for arguments. See
pylint W0102 error message.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
It is enough to just iterate through the dictionary itself, as in:

    for key in dictionary:
        pass

Signed-off-by: Bastian Stender <bst@pengutronix.de>
"resource" should only be used in the loop and not lateron. Use the
resource name from the method argument instead.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
See pylint error messag C0123.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Order imports: standard libraries followed by external libraries
followed by local imports

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
See pylint error messages R1705 and R1710.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Instead of comparing the length to 0, rely on the fact that empty sequences
are False.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
"await" will become a keyword in Python 3.7.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
In case unpacking gets complicated use _ for unused variables.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
See pylint error messge W1201.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
Signed-off-by: Bastian Stender <bst@pengutronix.de>
This makes travis stall in case the diff is big enough that git decides
to display it in a pager.

Signed-off-by: Bastian Stender <bst@pengutronix.de>
@Bastian-Krause
Copy link
Member Author

  • dropped tox related changes as advised
  • moved accidental raw string transformation from driver/serialdigitaloutput: raise error on unexpected arg in get() to linting: do miscellaneous linting
  • autoinstall/main: catch Exception instead of KeyError in Handler.run()
  • replace wait_for with wait_avail
  • remote/exporter: comment unused variable and add TODO
  • driver/shelldriver: annotate whole file for pylint and remove specific annotations
  • remote/common: annotate whole file for pylint and remove specific annotations
  • add commit remote/common: remove unnecessary lambda in Place and remove unnecessary-lambda annotation

@jluebbe jluebbe merged commit 2933466 into labgrid-project:master Jun 5, 2018
@Bastian-Krause Bastian-Krause deleted the bst/linting branch September 14, 2022 15:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants