-
Notifications
You must be signed in to change notification settings - Fork 6
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
Treewide: harmonize __post_init__ #243
Conversation
WalkthroughThe pull request introduces a consistent pattern of modification across multiple driver and client classes in the Jumpstarter project. The primary change involves updating the Changes
Possibly related PRs
Suggested reviewers
Poem
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
packages/jumpstarter-driver-pyserial/jumpstarter_driver_pyserial/driver.py (1)
36-38
: Remove extra newline for better readability.While the
hasattr
check is good, the extra newline aftersuper().__post_init__()
affects readability.def __post_init__(self): if hasattr(super(), "__post_init__"): super().__post_init__() - self.device = serial_for_url(self.url, baudrate=self.baudrate)
packages/jumpstarter-driver-ustreamer/jumpstarter_driver_ustreamer/driver.py (1)
37-38
: Maintain consistent style by removing extra newline.Similar to the PySerial driver, consider removing the extra newline after
super().__post_init__()
for better readability and consistency across the codebase.def __post_init__(self): if hasattr(super(), "__post_init__"): super().__post_init__() - cmdline = [self.executable]
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (1)
94-96
: Remove redundant url field declaration.The
url
field is already defined inDutlinkSerialConfig
. SinceDutlinkSerial
inherits fromDutlinkSerialConfig
, there's no need to redeclare it.@dataclass(kw_only=True) class DutlinkSerial(PySerial, DutlinkSerialConfig): - url: str | None = field(init=False, default=None)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
__templates__/driver/jumpstarter_driver/driver.py.tmpl
(1 hunks)packages/jumpstarter-driver-can/jumpstarter_driver_can/client.py
(1 hunks)packages/jumpstarter-driver-can/jumpstarter_driver_can/driver.py
(2 hunks)packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py
(3 hunks)packages/jumpstarter-driver-http/jumpstarter_driver_http/driver.py
(1 hunks)packages/jumpstarter-driver-pyserial/jumpstarter_driver_pyserial/driver.py
(1 hunks)packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/driver.py
(2 hunks)packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py
(1 hunks)packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver.py
(1 hunks)packages/jumpstarter-driver-ustreamer/jumpstarter_driver_ustreamer/driver.py
(1 hunks)packages/jumpstarter/jumpstarter/client/core.py
(1 hunks)packages/jumpstarter/jumpstarter/client/lease.py
(1 hunks)packages/jumpstarter/jumpstarter/common/metadata.py
(0 hunks)packages/jumpstarter/jumpstarter/driver/base.py
(1 hunks)
💤 Files with no reviewable changes (1)
- packages/jumpstarter/jumpstarter/common/metadata.py
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: pytest-matrix (3.13)
- GitHub Check: pytest-matrix (3.12)
- GitHub Check: pytest-matrix (3.11)
- GitHub Check: e2e
- GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
- GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
- GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (16)
__templates__/driver/jumpstarter_driver/driver.py.tmpl (1)
13-14
: LGTM! Template change ensures consistent initialization pattern.The addition of the
hasattr
check before callingsuper().__post_init__()
is a good practice that will propagate to all new drivers created from this template.packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/driver.py (1)
18-19
: LGTM! Consistent implementation across both classes.The
hasattr
check is correctly implemented in bothDigitalOutput
andDigitalInput
classes, maintaining consistency.Also applies to: 53-54
packages/jumpstarter-driver-ustreamer/jumpstarter_driver_ustreamer/driver.py (1)
Line range hint
13-14
: Overall changes look great with minor style improvements needed.The implementation of the
hasattr
check for__post_init__
is consistent and correct across all files. The only suggestion is to maintain consistent style by removing extra newlines after the super calls in the PySerial and UStreamer drivers.Also applies to: 36-38, 18-19, 53-54, 37-38
packages/jumpstarter/jumpstarter/client/core.py (1)
44-45
: LGTM! Good defensive programming practice.The conditional check before calling
super().__post_init__()
is particularly important here due to multiple inheritance. This prevents potentialAttributeError
when parent classes don't implement__post_init__
.packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py (1)
25-27
: LGTM! Good separation of concerns.The conditional check is correctly implemented, and the blank line nicely separates the superclass initialization from the USB device discovery logic.
packages/jumpstarter/jumpstarter/client/lease.py (1)
34-36
: LGTM! Good compatibility practice.The conditional check is particularly relevant here as the class implements both synchronous and asynchronous context managers. This ensures compatibility with both abstract base classes.
packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver.py (1)
48-50
: LGTM! Clean implementation.The conditional check is correctly implemented, and the blank line nicely separates the superclass initialization from the filesystem setup logic.
packages/jumpstarter-driver-can/jumpstarter_driver_can/client.py (1)
36-38
: LGTM! Defensive programming to prevent attribute errors.The conditional check before calling
super().__post_init__()
is a good practice that prevents potentialAttributeError
exceptions when the superclass doesn't implement the method.packages/jumpstarter-driver-http/jumpstarter_driver_http/driver.py (1)
32-34
: LGTM! Consistent with the codebase-wide initialization pattern.The conditional check before calling
super().__post_init__()
aligns with the pattern being implemented across the codebase.packages/jumpstarter/jumpstarter/driver/base.py (1)
63-65
: LGTM! Essential safety check in the base class.The conditional check before calling
super().__post_init__()
in the baseDriver
class ensures safe initialization throughout the inheritance hierarchy. This is particularly important as it prevents potentialAttributeError
exceptions whenMetadata
or other superclasses don't implement__post_init__
.packages/jumpstarter-driver-can/jumpstarter_driver_can/driver.py (2)
48-50
: LGTM! Safe initialization in Can class.The conditional check before calling
super().__post_init__()
ensures safe initialization, consistent with the pattern across the codebase.
200-202
: LGTM! Safe initialization in IsoTpPython class.The conditional check before calling
super().__post_init__()
maintains consistency with the initialization pattern being implemented throughout the codebase.packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (4)
32-34
: LGTM! Defensive super() call prevents AttributeError.The conditional check before calling
super().__post_init__()
is a good practice that prevents potentialAttributeError
when the superclass doesn't implement__post_init__
.
86-93
: LGTM! Well-structured configuration class.The new
DutlinkSerialConfig
class:
- Follows Single Responsibility Principle by separating configuration logic
- Correctly inherits from both
DutlinkConfig
andDriver
- Properly initializes the
url
field from the parent'stty
attribute
255-256
: LGTM! Consistent with the harmonization pattern.The conditional
super().__post_init__()
call follows the same pattern used throughout the codebase.
94-96
: Verify Method Resolution Order (MRO) after inheritance change.The change in inheritance order from
(DutlinkConfig, PySerial)
to(PySerial, DutlinkSerialConfig)
might affect method resolution. Let's verify there are no conflicts:✅ Verification successful
MRO verification completed - inheritance structure is safe ✅
The inheritance hierarchy is well-structured with clear separation of concerns between PySerial (serial communication) and DutlinkSerialConfig (DUT configuration). The
__post_init__
method properly handles super calls, and there are no conflicting attribute definitions between the parent classes.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Check for potential method conflicts in the inheritance hierarchy # Search for method definitions in PySerial class echo "Methods defined in PySerial:" rg -A 1 "def \w+\(" --type py | rg "PySerial" # Search for method definitions in DutlinkSerialConfig and its parent classes echo "Methods defined in DutlinkSerialConfig hierarchy:" rg -A 1 "def \w+\(" --type py | rg "DutlinkSerialConfig|DutlinkConfig"Length of output: 1091
Script:
#!/bin/bash # Search for PySerial class definition and its methods echo "PySerial class definition:" ast-grep --pattern 'class PySerial { $$$ }' echo "\nDutlinkSerialConfig class definition:" ast-grep --pattern 'class DutlinkSerialConfig { $$$ }' echo "\nDutlinkConfig class definition:" ast-grep --pattern 'class DutlinkConfig { $$$ }' # Backup search using ripgrep with more context echo "\nFallback search with ripgrep:" rg -B2 -A5 "^class (PySerial|DutlinkSerialConfig|DutlinkConfig)" --type pyLength of output: 3717
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (1)
94-96
: LGTM! Consider documenting the inheritance order.The inheritance structure is well-designed with PySerial first followed by DutlinkSerialConfig. Consider adding a comment explaining this order for maintainability.
@dataclass(kw_only=True) +# PySerial first for proper method resolution order (MRO), +# followed by DutlinkSerialConfig for configuration handling class DutlinkSerial(PySerial, DutlinkSerialConfig):
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (14)
__templates__/driver/jumpstarter_driver/driver.py.tmpl
(1 hunks)packages/jumpstarter-driver-can/jumpstarter_driver_can/client.py
(1 hunks)packages/jumpstarter-driver-can/jumpstarter_driver_can/driver.py
(2 hunks)packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py
(3 hunks)packages/jumpstarter-driver-http/jumpstarter_driver_http/driver.py
(1 hunks)packages/jumpstarter-driver-pyserial/jumpstarter_driver_pyserial/driver.py
(1 hunks)packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/driver.py
(2 hunks)packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py
(1 hunks)packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver.py
(1 hunks)packages/jumpstarter-driver-ustreamer/jumpstarter_driver_ustreamer/driver.py
(1 hunks)packages/jumpstarter/jumpstarter/client/core.py
(1 hunks)packages/jumpstarter/jumpstarter/client/lease.py
(1 hunks)packages/jumpstarter/jumpstarter/common/metadata.py
(0 hunks)packages/jumpstarter/jumpstarter/driver/base.py
(1 hunks)
💤 Files with no reviewable changes (1)
- packages/jumpstarter/jumpstarter/common/metadata.py
🚧 Files skipped from review as they are similar to previous changes (12)
- packages/jumpstarter-driver-http/jumpstarter_driver_http/driver.py
- templates/driver/jumpstarter_driver/driver.py.tmpl
- packages/jumpstarter/jumpstarter/client/lease.py
- packages/jumpstarter-driver-tftp/jumpstarter_driver_tftp/driver.py
- packages/jumpstarter-driver-pyserial/jumpstarter_driver_pyserial/driver.py
- packages/jumpstarter-driver-can/jumpstarter_driver_can/client.py
- packages/jumpstarter-driver-ustreamer/jumpstarter_driver_ustreamer/driver.py
- packages/jumpstarter/jumpstarter/client/core.py
- packages/jumpstarter/jumpstarter/driver/base.py
- packages/jumpstarter-driver-sdwire/jumpstarter_driver_sdwire/driver.py
- packages/jumpstarter-driver-raspberrypi/jumpstarter_driver_raspberrypi/driver.py
- packages/jumpstarter-driver-can/jumpstarter_driver_can/driver.py
⏰ Context from checks skipped due to timeout of 90000ms (7)
- GitHub Check: pytest-matrix (3.13)
- GitHub Check: pytest-matrix (3.12)
- GitHub Check: e2e
- GitHub Check: pytest-matrix (3.11)
- GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-devspace .devfile/Containerfile.client)
- GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter-dev .devfile/Containerfile)
- GitHub Check: build-and-push-image (jumpstarter-dev/jumpstarter Dockerfile)
🔇 Additional comments (3)
packages/jumpstarter-driver-dutlink/jumpstarter_driver_dutlink/driver.py (3)
32-34
: LGTM! Consistent with the harmonization pattern.The added check for
__post_init__
in the superclass prevents potential AttributeErrors and follows good defensive programming practices.
255-256
: LGTM! Consistent implementation of the harmonization pattern.The
__post_init__
check is particularly important here due to the composite interface implementation.
86-93
: Well-structured separation of configuration concerns.The new
DutlinkSerialConfig
class appropriately separates configuration handling and follows the harmonized__post_init__
pattern.Let's verify that this configuration class is properly integrated:
✅ Verification successful
Configuration class is properly integrated and used
The
DutlinkSerialConfig
class is correctly integrated into the inheritance hierarchy and properly used as a base class forDutlinkSerial
, maintaining a clean separation between configuration and implementation.🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Search for any direct usage of DutlinkConfig that should now use DutlinkSerialConfig rg "DutlinkConfig" --type pyLength of output: 650
Script:
#!/bin/bash # Check for DutlinkSerialConfig usage and initialization patterns ast-grep --pattern 'DutlinkSerialConfig($$$)' # Get more context around DutlinkSerialConfig class rg -B 5 -A 10 "class DutlinkSerialConfig" --type pyLength of output: 1717
Summary by CodeRabbit
Refactor
__post_init__
method calls to prevent potential initialization errors.Code Structure