Skip to content

Commit b76b99d

Browse files
r-sharpPierre-siddallericaneiningerjennyhickson
authored
Option to check whole repository/directory (#180)
* Tweaks to get VSCode's internal linters to quit whinging and make the ToDo plugin work nicely. * Touch O Tidying and ToDo commenting. * Adding abilty to force a check on all files. * Tweaks to get VSCode's internal linters to quit whinging and make the… (#173) * Tweaks to get VSCode's internal linters to quit whinging and make the ToDo plugin work nicely. * Touch O Tidying and ToDo commenting. * reviewer request to Update script_umdp3_checker/umdp3_conformance.py Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Update script_umdp3_checker/umdp3_checker_rules.py Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Update script_umdp3_checker/umdp3_checker_rules.py Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Update script_umdp3_checker/umdp3_checker_rules.py Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Update script_umdp3_checker/umdp3_checker_rules.py Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Update script_umdp3_checker/umdp3_checker_rules.py Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Rreviwer requested changes that I was unable to commit via GitHub's web interface --------- Co-authored-by: Pierre Siddall <43399998+Pierre-siddall@users.noreply.github.com> Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> * Update script_umdp3_checker/umdp3_conformance.py Co-authored-by: Pierre Siddall <43399998+Pierre-siddall@users.noreply.github.com> * remove redundent line Co-authored-by: Pierre Siddall <43399998+Pierre-siddall@users.noreply.github.com> * Reviewer suggestion : improving use of Path object handling Co-authored-by: Jenny Hickson <61183013+jennyhickson@users.noreply.github.com> --------- Co-authored-by: Pierre Siddall <43399998+Pierre-siddall@users.noreply.github.com> Co-authored-by: Erica Neininger <107684099+ericaneininger@users.noreply.github.com> Co-authored-by: Jenny Hickson <61183013+jennyhickson@users.noreply.github.com>
1 parent f8f8ad1 commit b76b99d

File tree

1 file changed

+70
-27
lines changed

1 file changed

+70
-27
lines changed

script_umdp3_checker/umdp3_conformance.py

Lines changed: 70 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,15 @@
2121

2222
@dataclass
2323
class CheckResult:
24-
"""Result from running a style checker on a file."""
25-
24+
"""
25+
Docstring for CheckResult
26+
A class to hold the results of running a style checker on a file.
27+
It contains the file path, the number of tests failed, whether all
28+
tests passed, and a list of TestResult objects for each test run on
29+
that file.
30+
"""
31+
"""TODO : Might be better to store number of tests run, and number passed,
32+
rather than just number failed and whether all passed."""
2633
file_path: str = "No file provided"
2734
tests_failed: int = 0
2835
all_passed: bool = False
@@ -426,6 +433,11 @@ def process_arguments():
426433
"--max-workers", type=int, default=8,
427434
help="Maximum number of parallel workers"
428435
)
436+
parser.add_argument(
437+
"--fullcheck", action="store_true",
438+
help="Instead of just checking changed files, check all files in "
439+
"the repository"
440+
)
429441
parser.add_argument(
430442
"-v", "--verbose", action="count", default=0,
431443
help="Increase output verbosity"
@@ -449,18 +461,35 @@ def process_arguments():
449461
return args
450462

451463

452-
def which_cms_is_it(path: str) -> CMSSystem:
464+
def which_cms_is_it(path: str, print_volume: int = 3) -> CMSSystem:
453465
"""Determine which CMS is in use based on the presence of certain files."""
454466
repo_path = Path(path)
455467
if (repo_path / ".git").is_dir():
456-
return GitBdiffWrapper(repo_path)
468+
cms = GitBdiffWrapper(repo_path)
457469
elif (repo_path / ".svn").is_dir():
458470
"""
459471
TODO : If we still want this to work reliably with FCM, it will need
460472
to also accept URLs and not just local paths."""
461-
return FCMBdiffWrapper(repo_path)
473+
cms = FCMBdiffWrapper(repo_path)
462474
else:
463475
raise RuntimeError("Unknown CMS type at path: " + str(path))
476+
branch_name = cms.get_branch_name()
477+
if not cms.is_branch():
478+
print(
479+
f"The path {path} is not a branch."
480+
f"\nReported branch name is : {branch_name}"
481+
"\nThe meaning of differences is unclear, and so"
482+
" checking is aborted.\n"
483+
f"Please try switching on the full check option"
484+
)
485+
exit(1)
486+
else:
487+
print(f"The branch, {branch_name}, at path {path} is a branch.")
488+
if print_volume >= 5:
489+
print("The files changed on this branch are:")
490+
for changed_file in cms.get_changed_files():
491+
print(f" {changed_file}")
492+
return cms
464493

465494

466495
def create_style_checkers(
@@ -508,38 +537,52 @@ def create_style_checkers(
508537
return checkers
509538

510539

511-
# Example usage
540+
def get_files_to_check(path: str, full_check: bool,
541+
print_volume: int = 3) -> List[Path]:
542+
"""
543+
Docstring for get_files_to_check : A routine to get the list of files to
544+
check based on the CMS or the full check override.
545+
546+
:param path: The top level path of the direcotry or clone of the
547+
repository to check.
548+
:type path: str
549+
:param full_check: Logical to force checking of all files in the
550+
repository, rather than just the changed files.
551+
:type full_check: bool
552+
:param print_volume: Verbosity level for printing. Default is 3.
553+
:type print_volume: int
554+
:return: List of relative file paths to check.
555+
:rtype: List[Path]
556+
"""
557+
if full_check: # Override to check all files present.
558+
repo_path = Path(path)
559+
all_files = [f for f in repo_path.rglob("*") if f.is_file()]
560+
if print_volume >= 3:
561+
print(f"Full check requested. Found {len(all_files)} files to "
562+
f"check in repository at path: {path}")
563+
return all_files
564+
else: # Configure CMS, and check we've been passed a branch
565+
cms = which_cms_is_it(path, print_volume)
566+
changed_files = cms.get_changed_files()
567+
return changed_files
568+
569+
570+
# Usage when run from command line.
512571
if __name__ == "__main__":
513572
args = process_arguments()
514573

515-
# Configure CMS, and check we've been passed a branch
516-
cms = which_cms_is_it(args.path)
517-
branch_name = cms.get_branch_name()
518-
if not cms.is_branch():
519-
print(
520-
f"The path {args.path} is not a branch."
521-
f"\nReported branch name is : {branch_name}"
522-
"\nThe meaning of differences is unclear, and so"
523-
" checking is aborted."
524-
)
525-
exit(1)
526-
else:
527-
print(f"The branch, {branch_name}, at path {args.path} is a branch.")
528-
if args.volume >= 5:
529-
print("The files changed on this branch are:")
530-
for changed_file in cms.get_changed_files():
531-
print(f" {changed_file}")
574+
log_volume = args.volume
575+
576+
file_paths = get_files_to_check(args.path, args.fullcheck, log_volume)
577+
full_file_paths = [Path(args.path) / f for f in file_paths]
532578

533579
# Configure checkers
534580
"""
535581
TODO : Uncertain as to how flexible this needs to be.
536582
For now, just configure checkers based on file type requested.
537583
Later, could add configuration files to specify which
538584
checkers to use for each file type."""
539-
checkers = []
540585

541-
full_file_paths = [f"{args.path}/{f}" for f in cms.get_changed_files()]
542-
full_file_paths = [Path(f) for f in full_file_paths]
543586
active_checkers = create_style_checkers(args.file_types,
544587
full_file_paths)
545588

@@ -554,7 +597,7 @@ def create_style_checkers(
554597

555598
checker.check_files()
556599

557-
all_passed = checker.print_results(print_volume=args.volume)
600+
all_passed = checker.print_results(print_volume=log_volume)
558601
print(f"Total files checked: {len(checker.results)}")
559602
print(f"Total files failed: "
560603
f"{sum(1 for r in checker.results if not r.all_passed)}")

0 commit comments

Comments
 (0)