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

Update base_kcell to base and add locked setters #599

Merged
merged 4 commits into from
Feb 8, 2025

Conversation

MatthewMckee4
Copy link
Member

@MatthewMckee4 MatthewMckee4 commented Feb 8, 2025

Summary by Sourcery

Rename the _base_kcell attribute to _base and add a public setter for the locked property.

Enhancements:

  • Add a public setter for the locked property of KCells.

Tests:

  • Update tests to reflect the renaming of _base_kcell to _base.

Copy link
Contributor

sourcery-ai bot commented Feb 8, 2025

Reviewer's Guide by Sourcery

This PR refactors the code to replace the 'base_kcell' attribute with a more generic 'base' property across the codebase, while also adding locked setters for the locked property in multiple classes. The changes are implemented by renaming member variables and updating property accessors, setters, and constructors to use the new attribute, ensuring consistency in both internal logic and the public API. Additionally, the PR updates the call sites in layout handling and test files to align with these modifications.

Updated Class Diagram for KCell Hierarchy (Class Diagram)

classDiagram
  %% Abstract base class for cells containing the new 'base' attribute and locked property with setter
  class ProtoKCell {
    <<abstract>>
    - _base: TBaseCell
    + locked() : bool
    + locked(value: bool) : void
    + lock() : void
    + base() : TBaseCell
  }

  %% A concrete implementation that uses its own _locked attribute
  class TVCell {
    - _locked: bool
    + locked() : bool
    + locked(value: bool) : void
    + lock() : void
  }

  %% ProtoTKCell extends ProtoKCell and is used as a base for specific cell types
  class ProtoTKCell {
    <<abstract>>
    + __getitem__(key: int | str | None) : ProtoPort
    + dup() : Self
    %% ... other methods ...
  }

  %% KCell: A concrete cell, user-facing with ports and instances
  class KCell {
    + ports() : Ports
    + insts() : Instances
    %% ... other methods ...
  }

  %% DKCell: Another concrete cell type for a different design, e.g., um cell
  class DKCell {
    + ports() : DPorts
    + insts() : DInstances
    %% ... other methods ...
  }

  %% TKCell represents the underlying cell structure that is now encapsulated in 'base'
  class TKCell {
    %% Represents the underlying cell properties like locked, info, settings, etc.
  }

  %% Relationships
  ProtoKCell <|-- ProtoTKCell : extends
  ProtoTKCell <|-- KCell : extends
  ProtoTKCell <|-- DKCell : extends
  TVCell ..|> ProtoKCell : implements
  %% Composition: ProtoKCell holds a reference to a TKCell via 'base'
  ProtoKCell o-- TKCell : base
Loading

File-Level Changes

Change Details Files
Renamed attribute 'base_kcell' to 'base' across KCell and its variants
  • Replaced all instances of '_base_kcell' with '_base' in class definitions
  • Updated property getters/setters to use the new 'base' attribute
  • Modified constructors to accept 'base' instead of 'base_kcell'
src/kfactory/kcell.py
src/kfactory/layout.py
tests/test_cell.py
tests/test_layout.py
tests/test_dkcell.py
tests/test_meta.py
Added locked setters for the locked property
  • Implemented locked setter in the base abstract class using the '@locked.setter' decorator
  • Provided concrete implementations of the locked setter in derived classes (TVCell, KCell, etc.)
  • Ensured that the locked setter updates the underlying kdb_cell properties
src/kfactory/kcell.py
tests/test_dkcell.py
Updated related method calls and tests to align with new property names
  • Refactored layout manipulation functions to reference 'base' instead of 'base_kcell'
  • Updated test assertions and mocks to check the new 'base' property usage
  • Revised meta data retrieval and port drawing methods to correctly access the new attribute
src/kfactory/kcell.py
src/kfactory/layout.py
tests/test_cell.py
tests/test_layout.py
tests/test_meta.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

We've reviewed this pull request using the Sourcery rules engine. If you would also like our AI-powered code review then let us know.

Comment on lines 1267 to +1274
if isinstance(inst, Instance):
return Instance(self.kcl, self._base_kcell.kdb_cell.insert(inst.instance))
return Instance(self.kcl, self._base.kdb_cell.insert(inst.instance))
else:
if not property_id:
return Instance(self.kcl, self._base_kcell.kdb_cell.insert(inst))
return Instance(self.kcl, self._base.kdb_cell.insert(inst))
else:
assert isinstance(inst, kdb.CellInstArray | kdb.DCellInstArray)
return Instance(
self.kcl, self._base_kcell.kdb_cell.insert(inst, property_id)
)
return Instance(self.kcl, self._base.kdb_cell.insert(inst, property_id))
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): We've found these issues:

Copy link

codecov bot commented Feb 8, 2025

Codecov Report

Attention: Patch coverage is 82.48175% with 24 lines in your changes missing coverage. Please review.

Project coverage is 65.90%. Comparing base (ccb2a2e) to head (e43d625).
Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/kfactory/kcell.py 81.74% 20 Missing and 3 partials ⚠️
src/kfactory/ports.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #599      +/-   ##
==========================================
+ Coverage   65.85%   65.90%   +0.04%     
==========================================
  Files          64       64              
  Lines        9636     9644       +8     
  Branches     1786     1786              
==========================================
+ Hits         6346     6356      +10     
- Misses       2766     2767       +1     
+ Partials      524      521       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@MatthewMckee4 MatthewMckee4 added the enhancement New feature or request label Feb 8, 2025
@sebastian-goeldi sebastian-goeldi merged commit 0a8cde9 into main Feb 8, 2025
16 checks passed
@sebastian-goeldi sebastian-goeldi deleted the kcell-updates branch February 8, 2025 20:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants