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

Refactor BOM generation to centralize logic #177

Merged
merged 1 commit into from
Aug 29, 2024
Merged

Conversation

shrik450
Copy link
Collaborator

@shrik450 shrik450 commented Aug 27, 2024

As it turns out, System Capture BOM generation did not get the benefits of the changes in #157 as the functions for filtering and sorting rows were not called in the system capture BOM function. This was an entirely avoidable mistake as the logic for BOM generation for all formats is substantially the same. This commit moves the logic for BOM generation into the generate_bom function and makes the format specific functions aliases of the same. This should avoid similar mistakes in the future.

Closes ID-529.

As it turns out, System Capture BOM generation did not get the benefits
of the changes in #157 as the functions for filtering and sorting rows
were not called in the system capture BOM function. This was an entirely
avoidable mistake as the logic for BOM generation for all formats is
substantially the same. This commit moves the logic for BOM generation
into the `generate_bom` function and makes the format specific functions
aliases of the same. This should avoid similar mistakes in the future.
@shrik450 shrik450 requested a review from a team as a code owner August 27, 2024 21:09
Copy link

Copy link

Coverage Summary

Total Project Coverage

  • Line Coverage: 86.00% (1769/2057)
  • Branch Coverage: 73.60% (446/606)

Coverage by File

File Line Coverage Branch Coverage Lines (Covered/Total) Branches (Covered/Total)
allspice/__init__.py 100.00% 100.00% 5/5 0/0
allspice/allspice.py 81.43% 69.23% 171/210 54/78
allspice/apiobject.py 83.67% 60.66% 1030/1231 165/272
allspice/baseapiobject.py 87.25% 84.62% 89/102 44/52
allspice/exceptions.py 100.00% 100.00% 14/14 0/0
allspice/ratelimiter.py 100.00% 100.00% 22/22 4/4
allspice/utils/__init__.py 100.00% 100.00% 0/0 0/0
allspice/utils/bom_generation.py 99.07% 98.00% 106/107 49/50
allspice/utils/core.py 94.12% 50.00% 16/17 1/2
allspice/utils/list_components.py 90.17% 86.92% 266/295 113/130
allspice/utils/netlist_generation.py 92.59% 88.89% 50/54 16/18

Diff Coverage

Diff: origin/main...HEAD, staged and unstaged changes

  • allspice/utils/bom_generation.py (100%)
  • allspice/utils/list_components.py (88.9%): Missing lines 293

Summary

  • Total: 28 lines
  • Missing: 1 line
  • Coverage: 96%
Diff Coverage Details

allspice/utils/list_components.py

Lines 289-297

  289         return SupportedTool.ORCAD
  290     elif source_file.lower().endswith(".sdax"):
  291         return SupportedTool.SYSTEM_CAPTURE
  292     else:
! 293         raise ValueError("""
  294 The source file for generate_bom must be:
  295 
  296 - A PrjPcb file for Altium projects; or
  297 - A DSN file for OrCAD projects; or

if remove_non_bom_components:
project_tool = infer_project_tool(source_file)
if project_tool == SupportedTool.ALTIUM:
components = _remove_non_bom_components(components)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless the plan is to use the same function for the other file formats I think we should prefix this as altium specific.

Copy link
Contributor

@McRaeAlex McRaeAlex left a comment

Choose a reason for hiding this comment

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

Very nice, the shared logic in nice and keeping the functions per format makes it easy to document each case.

Copy link
Contributor

@kdumontnu kdumontnu left a comment

Choose a reason for hiding this comment

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

Any PR with a net negative lines of code is a 👍 by me

@shrik450 shrik450 merged commit 53b6b60 into main Aug 29, 2024
4 checks passed
@shrik450 shrik450 deleted the su/refactor-bom branch August 29, 2024 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants