Skip to content

Commit

Permalink
Merge pull request #178 from AllSpiceIO/su/bom-skip
Browse files Browse the repository at this point in the history
Add column configuration to skip in output
  • Loading branch information
shrik450 authored Aug 31, 2024
2 parents 5acce01 + e95fd66 commit cd413f4
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 56 deletions.
31 changes: 31 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,36 @@
# Changelog

## v3.5.0

### What's Changed

- Fix many, but not all, typing failures by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/168

This also fixes a few bugs that have been present in the library for a while, such as adding comments failing for issues requested using `Issue.request`.

- Add endpoint to fetch git trees by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/175

The new `Repository.get_tree` method can be used to fetch the tree of a commit in a repository. This is useful if you want to list all files in a commit, and can replace most uses of `Repository.get_git_content`.

- Refactor BOM generation to centralize logic by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/177

This also fixes bugs in the System Capture SDAX BOM generation which prevented sorting and filtering from being applied there.

- Filter out blank components in list_components by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/176

- Add column configuration to skip in output by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/178

A new column configuration, `skip_in_output`, can be used to remove a column from the BOM output, which is useful when a column is used for grouping, filtering or sorting but isn't required in the BOM.

### Internal Changes

- Update column config cassette to include reference changes by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/166
- Apply Ruff formatting to examples by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/173
- Skip coverage comment on dependabot PRs by @shrik450 in https://github.com/AllSpiceIO/py-allspice/pull/174
- Update pytest requirement from ~=8.2 to ~=8.3 by @dependabot in https://github.com/AllSpiceIO/py-allspice/pull/170

**Full Changelog**: https://github.com/AllSpiceIO/py-allspice/compare/v3.4.0...v3.5.0

## v3.4.0

### What's Changed
Expand Down
2 changes: 1 addition & 1 deletion allspice/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
)
from .exceptions import AlreadyExistsException, NotFoundException

__version__ = "3.4.0"
__version__ = "3.5.0"

__all__ = [
"AllSpice",
Expand Down
29 changes: 27 additions & 2 deletions allspice/utils/bom_generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ class SortOrder(Enum):
the BOM. Otherwise, both will be included.
"""

skip_in_output: bool = False
"""
If True, this column will be skipped in the output BOM. This can be useful
for columns that are used for grouping, sorting or filtering, but should
not be included in the final BOM.
"""


ColumnsMapping = dict[str, ColumnConfig | list[str] | str]
"""
Expand Down Expand Up @@ -171,7 +178,7 @@ def generate_bom(
if remove_non_bom_components:
project_tool = infer_project_tool(source_file)
if project_tool == SupportedTool.ALTIUM:
components = _remove_non_bom_components(components)
components = _remove_altium_non_bom_components(components)

columns_mapping = {
column_name: (
Expand All @@ -186,6 +193,7 @@ def generate_bom(
bom = _group_entries(mapped_components, group_by, columns_mapping)
bom = _filter_rows(bom, columns_mapping)
bom = _sort_columns(bom, columns_mapping)
bom = _skip_columns(bom, columns_mapping)

return bom

Expand Down Expand Up @@ -419,7 +427,9 @@ def _group_entries(
return rows


def _remove_non_bom_components(components: list[ComponentAttributes]) -> list[ComponentAttributes]:
def _remove_altium_non_bom_components(
components: list[ComponentAttributes],
) -> list[ComponentAttributes]:
"""
Filter out components of types that should not be included in the BOM.
"""
Expand Down Expand Up @@ -498,3 +508,18 @@ def _filter_rows(bom_entries: Bom, columns_config: dict[str, ColumnConfig]) -> B
for row in bom_entries
if not any(re.search(pattern, row[column]) for column, pattern in columns_to_filter.items())
]


def _skip_columns(bom_entries: Bom, columns_config: dict[str, ColumnConfig]) -> Bom:
"""
Skip columns based on the configuration.
"""

return [
{
column: value
for column, value in row.items()
if column not in columns_config or not columns_config[column].skip_in_output
}
for row in bom_entries
]
Loading

0 comments on commit cd413f4

Please sign in to comment.