-
Notifications
You must be signed in to change notification settings - Fork 53
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
Release/2.0 dev #109
Draft
robberwick
wants to merge
112
commits into
master
Choose a base branch
from
release/2.0-dev
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Release/2.0 dev #109
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
Abstract away the platform specifics in the main BlinkStick class by employing a strategy pattern.
Add a minimal instantiation test for all 3 blinkstick classes.
Add pytest as test dependency and stub out GitHub action for cross-platform testing on supported python versions
use py3 style classes
Move color functionality
test: rename blinkstick test file
Return BlinkStickVariant from get_variant BREAKING CHANGE: get_variant() now returns an instance of the BlinkStickVariant Enum, where the value is a 2-tuple of variant value, and variant string
Update the test for the get_variant and get_variant_string methods to account for the new BlinkStickVariant enum
Use Enum to capture BlinkStick variant types
Add tests for string to bytes conversion and refactor
Rename `find_blinksticks` to `get_attached_blinkstick_devices`, and `_refresh_device` to `_refresh_attached_blinkstick_device`
Always return a list from the usb backend, so if no blinkstick devices are detected, the list should be empty
Use the BlinkStickDevice class to retrieve readonly device data up front, and persist it in the BlinkStick wrapper class
Use the BlinkStickDevice class to retrieve readonly device data up front, and persist it in the BlinkStick wrapper class
Rationalise accessing of read-only device attributes by use of a BlinkStickDevice class
Remove Unused find blinksticks method
move the main client classes (BlinkStick, BlinkStickPro, BlinkStickProMatrix) to a clients package Also, move the core functions (find_first etc) to core module
organise client and core code
move the entrypoint script into a scripts folder to keep things tidy.
Move entrypoint script
add a py.typed file to the package to indicate to mypy that it uses type hinting
Add py.typed file
Tidy up use of devices package
Rename BlinkStickVariant.identify() to .from_version_attrs(), for added clarity.
Add a serial number model so that it's easier to decompose th estring into constituent parts
Device major version variant
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.
This PR introduces several key changes aimed at modernizing and improving the BlinkStick Python library:
Refactoring: Significant restructuring of the codebase to enhance readability and maintainability. Legacy patterns have been replaced with more efficient and modern Python constructs.
Type Hinting: The inclusion of type annotations provides better integration with IDEs and static analysis tools, improving developer experience and reducing runtime errors.
Unit Tests: Unit tests have been added to improve the code's reliability and ensure coverage for new and existing features.
Project Configuration: The build system now conforms to PEP 517/518 standards by adopting pyproject.toml, replacing older methods for defining project dependencies and metadata.
GitHub Actions Integration: Continuous Integration (CI) workflows have been implemented using GitHub Actions to automate testing, linting, and builds, ensuring consistent code quality and streamlined development.
These updates collectively enhance the library's usability, adherence to modern Python standards, and developer experience.
Refactoring
The refactoring changes introduced in the release/2.0-dev branch of the BlinkStick Python library represent a significant overhaul of the codebase. These changes aim to enhance code quality, performance, and maintainability. Key refactoring updates include:
Improved organization of classes and functions into smaller, logical units that align with the single-responsibility principle.
Simplification of complex or redundant logic, making the code easier to understand and debug.
Removal of legacy constructs and obsolete code, replacing them with Pythonic idioms.
Utilization of f-strings for more readable and efficient string formatting.
Introduction of list comprehensions and generator expressions in place of verbose loops for concise and efficient data processing.
Use of context managers (e.g., with statements) to handle resources like files or devices, ensuring proper cleanup.
Refined exception handling mechanisms to provide more informative error messages and avoid silent failures.
Centralization of error management logic for consistent behavior across the library.
Refactoring of private and internal methods to ensure proper encapsulation and reduce interdependencies.
Consolidation of reusable logic into helper functions or utility modules.
Consistent application of PEP 8 standards across the codebase.
Addition of docstrings and inline comments to enhance code documentation and ease onboarding for new contributors.
Backend Implementations:
UnixLikeBackend
class insrc/blinkstick/backends/unix_like.py
to handle BlinkStick devices on Unix-like systems.Win32Backend
class insrc/blinkstick/backends/win32.py
to handle BlinkStick devices on Windows systems.Type Hinting
type hinting has been introduced as a key modernization effort. This update enhances code clarity, facilitates developer productivity, and supports better integration with modern development tools.
Benefits and Implementation of Type Hinting
Improved Code Readability:
Function signatures now explicitly indicate the expected types for parameters and return values. For example:
This makes the codebase self-documenting, reducing the need for extensive comments or external documentation.
Enhanced Development Tools Support:
Type hinting integrates seamlessly with IDEs like PyCharm and VS Code, enabling features such as auto-completion, inline documentation, and static type analysis.
Tools like mypy can now be used to perform static type checks, identifying potential bugs before runtime.
Error Reduction:
Explicit type definitions help prevent errors caused by incorrect data types being passed to functions, improving overall robustness.
Compatibility with Modern Python:
By using Python’s typing module, the library aligns with best practices in modern Python development. This includes the use of advanced typing constructs such as
Optional
,Union
, andList
.Foundation for Future Enhancements:
The consistent use of type hints makes the library easier to extend and maintain, especially for new contributors or developers less familiar with the project.
Examples of Type Hinting Introduced
Basic Type Annotations:
Complex Types:
Broader Impact
Type hinting not only brings immediate benefits to the BlinkStick project but also positions it as a modern and developer-friendly library in the Python ecosystem. It reduces friction for both current maintainers and new contributors.
Unit Tests
Project Configuration:
pyproject.toml
to include build system requirements, project metadata, dependencies, optional dependencies, and tool configurations for Black and isort.setup.py
and replaced it withpyproject.toml
for project configuration and dependency management.MANIFEST
andMANIFEST.in
files as they are no longer needed with the new project configuration. [1] [2]GitHub Actions Integration:
black.yml
workflow to check code formatting using Black on push and pull request events.mypy.yml
workflow to perform type checking using Mypy on push and pull request events.pytest.yml
workflow to run tests on multiple operating systems and Python versions for pull requests targeting specific branches.Misc Updates:
src/blinkstick/__init__.py
to useimportlib.metadata
for package version retrieval and restructured imports.examples/random_color.py
to demonstrate BlinkStick usage and exception handling.These changes introduce platform-specific backend implementations for better device handling, improve project configuration management, and enhance the project's CI/CD pipeline, , and .