Skip to content

Commit

Permalink
coverage_report: Allow package filtering for --by-platform
Browse files Browse the repository at this point in the history
Originally, both a --by-package and --by-platform flag was created to
describe the types of coverage reports able to be generated, and allow
for grouping the command line arguments based on these two flags.

With the adding of the ability to filter on packages for the platform
report, the --by-package flag no longer has any special arguments and
can be deprecated. Due to this, this change also removes the
--by-package flag, making it the default behavior, which is overridden
by --py-platform.
  • Loading branch information
Javagedes committed Feb 5, 2024
1 parent 1bae338 commit fa902a1
Showing 1 changed file with 17 additions and 23 deletions.
40 changes: 17 additions & 23 deletions edk2toolext/environment/reporttypes/coverage_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,6 @@ def report_info(self) -> Tuple[str, str]:

def add_cli_options(self, parserobj: ArgumentParser) -> None:
"""Configure command line arguments for this report."""
# Group 1 - Calculate coverage only for files in a specific package
group = parserobj.add_argument_group("Coverage by package options")
group.add_argument("--by-package", action="store_true", dest="by_package", default=False,
help="Filters test coverage to only files in the specified packages(s)")
group.add_argument("-p", "--package", "--Package", "--PACKAGE", dest="package_list",
action=SplitCommaAction, default=[],
help="The package to include in the report. Can be specified multiple times.")

# Group 2 - Calculate coverage only on files used by a specific platform
group = parserobj.add_argument_group("Coverage by platform options")
group.add_argument("--by-platform", action="store_true", dest="by_platform", default=False,
Expand All @@ -83,9 +75,15 @@ def add_cli_options(self, parserobj: ArgumentParser) -> None:
action=SplitCommaAction, default=[],
help="Package path relative paths or file (.txt). Globbing is supported. Can be "
"specified multiple times")
parserobj.add_argument("-p", "--package", "--Package", "--PACKAGE", dest="package_list",
action=SplitCommaAction, default=[],
help="The package to include in the report. Can be specified multiple times.")
parserobj.add_argument("--flatten", action="store_true", dest="flatten", default=False,
help="Flatten the report to only source files. This removes duplicate files that are in "
"multiple INFs.")
group = parserobj.add_argument_group("Deprecated Options")
group.add_argument("--by-package", action="store_true", dest="by_package", default=False,
help="Filters test coverage to only files in the specified packages(s)")

def run_report(self, db: Edk2DB, args: Namespace) -> None:
"""Generate the Coverage report."""
Expand All @@ -97,17 +95,19 @@ def run_report(self, db: Edk2DB, args: Namespace) -> None:
self.update_excluded_files()

with db.session() as session:
if args.by_package:
logging.info("Organizing coverage report by Package.")
return self.run_by_package(session)
package_list = self.args.package_list or [pkg.name for pkg in session.query(Package).all()]
logging.info(f"Packages requested: {', '.join(package_list)}")
if args.by_platform:
logging.info("Organizing coverage report by Platform.")
return self.run_by_platform(session)

logging.error("No report type specified via command line or configuration file.")
return -1
return self.run_by_platform(session, package_list)
if args.by_package:
logging.warning(
"The --by-package flag is deprecated and will be removed in a future release."
" by-package is now the default behavior and overriden with by-platform."
)
return self.run_by_package(session, package_list)

def run_by_platform(self, session: Session) -> None:
def run_by_platform(self, session: Session, package_list: list) -> None:

Check failure on line 110 in edk2toolext/environment/reporttypes/coverage_report.py

View workflow job for this annotation

GitHub Actions / CI / Run

Ruff (D417)

edk2toolext/environment/reporttypes/coverage_report.py:110:9: D417 Missing argument description in the docstring for `run_by_platform`: `package_list`
"""Runs the report, only adding coverage data for source files used to build the platform.
Args:
Expand Down Expand Up @@ -136,8 +136,6 @@ def run_by_platform(self, session: Session) -> None:
return -1
env_id = result.id

package_list = [pkg.name for pkg in session.query(Package).all()]

# Build source / coverage association dictionary
coverage_files = self.build_source_coverage_dictionary(self.args.xml, package_list)

Expand All @@ -164,7 +162,7 @@ def run_by_platform(self, session: Session) -> None:
# Build the report
return self.build_report(session, env_id, coverage_files, package_files)

def run_by_package(self, session: Session) -> bool:
def run_by_package(self, session: Session, package_list: list) -> bool:

Check failure on line 165 in edk2toolext/environment/reporttypes/coverage_report.py

View workflow job for this annotation

GitHub Actions / CI / Run

Ruff (D417)

edk2toolext/environment/reporttypes/coverage_report.py:165:9: D417 Missing argument description in the docstring for `run_by_package`: `package_list`
"""Runs the report, only adding coverage data for source files in the specified packages.
Args:
Expand All @@ -173,10 +171,6 @@ def run_by_package(self, session: Session) -> bool:
Returns:
(bool): True if the report was successful, False otherwise.
"""
# Get package_list
package_list = self.args.package_list or [pkg.name for pkg in session.query(Package).all()]
logging.info(f"Packages requested: {', '.join(package_list)}")

# Get env_id
env_id, = session.query(Environment.id).order_by(Environment.date.desc()).first()

Expand Down

0 comments on commit fa902a1

Please sign in to comment.