-
Notifications
You must be signed in to change notification settings - Fork 3
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
fix(lint): reformat & resolve discovered Ruff errors #12
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
rmlibre
added
bug
Something isn't working
style
Format, refactor, & idiom choices - no noticeable side-effects
labels
Jul 1, 2024
Implements a ``ConcurrencyGuard`` class to provide a standard interface for guarding against unwatned simultaneous context executions. Incorporated by ``(Async)CipherStream`` & ``(Async)DecipherStream`` classes to avoid data buffer calls from clobbering each other. Tests added for the new integrations. Refactorings done to aid the cohesion of the changes with the codebase. Resolves Bug 2 in [#12]
rmlibre
changed the title
[DRAFT] fix(lint): reformat & resolve discovered Ruff errors
fix(lint): reformat & resolve discovered Ruff errors
Jul 4, 2024
rmlibre
commented
Jul 4, 2024
Suggested in review: #12 (comment)
Suggested in review: #12 (comment)
Suggested in review: #12 (comment)
rmlibre
added a commit
that referenced
this pull request
Jul 5, 2024
Better resemble a rainbow color sequence. Suggested in review: #12 (comment)
rmlibre
added a commit
that referenced
this pull request
Jul 8, 2024
Add the following flags: + "A", # flake8-builtins + "ANN", # flake8-annotations + "PIE", # flake8-pie + "PL", # Pylint + "PTH", # flake8-use-pathlib + "T20", # flake8-print + "TD", # flake8-todos View 'ruff.toml' for exceptions & rationale commentary.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Quite a few issues were found when running Ruff on the codebase. The benign included unused imports, formatting style choices, & complaints related to
import *
clauses primarily in the__init__.py
files of subpackages. The package's standard for styling is declared asblack
in the readme, but it's only loosely abiding by that formatting. An automated formatter to enforce style standards is missing from the project.Moreover, there were some
NameError
bugs in branching code. These were the offending lines:Bug 1:
Issue
was missing as an importThis resulted in
NameError
being raised instead ofPermissionError
.aiootp/aiootp/databases/async_database.py
Line 654 in 5ca2d61
aiootp/aiootp/databases/sync_database.py
Line 620 in 5ca2d61
Bug 2:
sleep
was missing as an importThe impact is uncertain, as these lines of code weren't reached in tests. They were intended to be guard clauses against the potential of simultaneous data buffering. These clauses weren't sufficient solutions to concurrency race conditions.
aiootp/aiootp/ciphers/cipher_streams.py
Lines 459 to 460 in 5ca2d61
aiootp/aiootp/ciphers/decipher_streams.py
Lines 576 to 577 in 5ca2d61
Expected behavior
When the configured Ruff linter & formatter are run on a release:
There are no reported errors
There are no changes to formatting
The result is the canonical style standard for the package, with the only exceptions being for changes that would harm readability, hinder the communication of essential information, or are oddities / inconsistencies that would otherwise merit the raising of an issue upstream.
Remediations
Fix Bug 1:
Fix Bug 2:
Add missing import
Write proper concurrency protection
The critical sections were wrapped in the new
ConcurrencyGuard
class. It works by assigning each context a unique, random authorization token & appending it to a double-ended queue (collections.deque
). Depending on the class, it (a)synchronously sleeps until its token is at the 0th index of the queue. At that time, the code block wrapped by the instance's context manager is allowed to run. When it's done, it callspopleft()
on the queue to take its token out of the queue so the next instance can run. If thepopleft()
call returns a different token, thenIncoherentConcurrencyState
exception is raised, indicating a potentially corrupt control flow / buffering of data.aiootp/aiootp/ciphers/cipher_streams.py
Lines 242 to 246 in c9c13c6
aiootp/aiootp/ciphers/cipher_streams.py
Lines 455 to 459 in c9c13c6
aiootp/aiootp/ciphers/decipher_streams.py
Lines 307 to 310 in c9c13c6
aiootp/aiootp/ciphers/decipher_streams.py
Lines 581 to 584 in c9c13c6
That class is defined here:
aiootp/aiootp/asynchs/concurrency_interface.py
Lines 43 to 75 in c9c13c6
aiootp/tests/test_online_cipher_interfaces.py
Lines 263 to 321 in c9c13c6
aiootp/tests/test_ConcurrencyGuard.py
Lines 21 to 64 in c9c13c6
High-level style choices:
The options for Ruff have been configured & annotated with rationale. For now, what Ruff says when running in that configuration defines most of the style guide. The caveats are described in this PR, but will be subject to refinement in the future. The work of fully documenting all style choices may not be necessary, albeit desirable. However, that'll be the work of a future PR.
ruff.toml
orpyproject.toml
.aiootp/ruff.toml
Lines 37 to 48 in f9cf094
Add lint & format automation to GitHub workflows:
aiootp/.github/workflows/linux-python-app.yml
Lines 23 to 25 in f9cf094
aiootp/.github/workflows/windows-python-app.yml
Lines 23 to 25 in f9cf094
aiootp/.github/workflows/macos-python-app.yml
Lines 23 to 25 in f9cf094