Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Sort BoardGroup and fix iteration #74

Merged
merged 6 commits into from
Feb 15, 2019
Merged

Sort BoardGroup and fix iteration #74

merged 6 commits into from
Feb 15, 2019

Conversation

kierdavis
Copy link
Contributor

Resolves #37 and #38. See commit messages for more details.

Implementing #37 requires being able to test that Boards in a
BoardGroup are sorted by serial number. If serial numbers can
differ between test runs, this can lead to inconsistent test
results. Therefore we switch from using the `id` (address) of
the Board object to using known constant strings.
Previously, boards were sorted by the order in which they were
discovered. The discovery order should be considered
nondeterministic, since it depends on things like USB addresses
for hardware backends and is currently undefined for non-hardware
backends.

In an effort to make this more useful to a user, boards will now
be ordered deterministically by sorting the collection by board
serial number.

This order is only visible when iterating through the BoardGroup,
since #25 removed the ability to index boards by integer indices.

Closes #37.
…ependent

Previously, the iteration state was contained in the `BoardGroup`,
and `BoardGroup.__iter__` simply returned the same `BoardGroup`.
This prevented being able to perform multiplie iterations
concurrently due to state being incorrectly shared between the
corresponding iterators.

Closes #38.
@kierdavis
Copy link
Contributor Author

I'm not sure what to do about these linting errors, pertaining to single-line docstrings being too long.

j5/boards/base.py:105:91: E501 line too long (94 > 90 characters)
tests/boards/test_base.py:254:91: E501 line too long (98 > 90 characters)

If I attempt to wrap the text onto multiple lines, the linter thinks that I now have a summary line (missing a period, since it is only the first half of a sentence) and a description line (missing a blank line between it and the preceding summary line).

j5/boards/base.py:105:1: D205 1 blank line required between summary line and description
j5/boards/base.py:105:1: D400 First line should end with a period
tests/boards/test_base.py:254:1: D205 1 blank line required between summary line and description
tests/boards/test_base.py:254:1: D400 First line should end with a period

Should I just reword the docstring to have a shorter summary sentence?

@trickeydan
Copy link
Contributor

I'd be happy with either:

  • Add an ignore for E501 on those lines.
  • Split it onto separate linres with a short description at the top e.g:
def eat_bees(bee_hive: BeeHive):
    """
    Eat the bees.

    Eat all of the bees in the bee hive whilst also being careful to 
    not allow them to sting my tongue as that would likely be painful
    and make me not want to eat bees in the future.
    """    
    bee_hive.consume()
    bee_hive.consume_more()

These were causing linting issues, but cannot be wrapped without
the linter instead thinking the docstring contained an unterminated
summary and a description not correctly separated from the summary.
Copy link
Member

@sedders123 sedders123 left a comment

Choose a reason for hiding this comment

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

LGTM! Just the one question

for board in self.board_class.discover(self._backend):
discovered_boards = self.board_class.discover(self._backend)
discovered_boards.sort(key=lambda board: board.serial)
for board in discovered_boards:
Copy link
Member

@sedders123 sedders123 Feb 13, 2019

Choose a reason for hiding this comment

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

What is the minimum version of Python we are supporting?

Dictionaries being ordered was introduced to the Python standard in 3.7 and as a side effect to the CPython implementation in 3.6. If we wanted to support Python 3.5 (which is the first to allow syntactical type hints) or non CPython 3.6 we'd have to change self.boards to be an OrderdDict from collections

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, we should really specify this somewhere. I've created #79.

@kierdavis kierdavis merged commit 15a3d2b into master Feb 15, 2019
@kierdavis kierdavis deleted the boardgroup-iteration branch February 15, 2019 11:46
@kierdavis kierdavis mentioned this pull request Feb 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants