Skip to content

Commit 9f612da

Browse files
committed
refactor(version-scanner): rename targets file to matrix file to resolve ambiguity
1 parent 8fc7e61 commit 9f612da

4 files changed

Lines changed: 29 additions & 29 deletions

File tree

.github/workflows/version_scanner.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
# Uses -o to output a detailed, raw CSV to a file
3636
# Uses --stdout to print a slim, easier to parse summary to the GitHub Actions UI
3737
# Uses --soft-fail to temporarily limit causing CI/CD failures during the migration to full operation.
38-
python scripts/version_scanner/version_scanner.py --targets-file scripts/version_scanner/targets.yaml --package-file scripts/version_scanner/python-310-package-list.txt --stdout -o version_scanner_output.csv --soft-fail
38+
python scripts/version_scanner/version_scanner.py --matrix-file scripts/version_scanner/matrix.yaml --package-file scripts/version_scanner/python-310-package-list.txt --stdout -o version_scanner_output.csv --soft-fail
3939
4040
- name: Upload CSV Results
4141
if: always()

scripts/version_scanner/tests/unit/test_version_scanner.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -782,16 +782,16 @@ def test_format_for_console(sample_match):
782782
assert "python_requires = " not in log_str # Slim format doesn't print context line
783783

784784

785-
def test_parse_targets_file(tmp_path):
786-
from version_scanner import parse_targets_file
787-
yaml_file = tmp_path / "targets.yaml"
785+
def test_parse_matrix_file(tmp_path):
786+
from version_scanner import parse_matrix_file
787+
yaml_file = tmp_path / "matrix.yaml"
788788
yaml_file.write_text("""
789789
python:
790790
- "3.7"
791791
- "3.8"
792792
protobuf: "4.25.8"
793793
""")
794-
targets = parse_targets_file(str(yaml_file))
794+
targets = parse_matrix_file(str(yaml_file))
795795
assert targets == [("python", "3.7"), ("python", "3.8"), ("protobuf", "4.25.8")]
796796

797797
@pytest.mark.parametrize(
@@ -803,18 +803,18 @@ def test_parse_targets_file(tmp_path):
803803
("python:\n - null", True), # Invalid version type (null/None value)
804804
]
805805
)
806-
def test_parse_targets_file_failures(tmp_path, file_content, file_exists):
807-
from version_scanner import parse_targets_file
806+
def test_parse_matrix_file_failures(tmp_path, file_content, file_exists):
807+
from version_scanner import parse_matrix_file
808808

809809
if file_exists:
810-
yaml_file = tmp_path / "targets_failures.yaml"
810+
yaml_file = tmp_path / "matrix_failures.yaml"
811811
yaml_file.write_text(file_content)
812812
path = str(yaml_file)
813813
else:
814814
path = "nonexistent_file.yaml"
815815

816816
with pytest.raises(SystemExit) as excinfo:
817-
parse_targets_file(path)
817+
parse_matrix_file(path)
818818
assert excinfo.value.code == 1
819819

820820
def test_scan_repository_multi_targets(tmp_path):

scripts/version_scanner/version_scanner.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -624,23 +624,23 @@ def scan_repository(
624624
return results
625625

626626

627-
def parse_targets_file(file_path: str) -> List[Tuple[str, str]]:
627+
def parse_matrix_file(file_path: str) -> List[Tuple[str, str]]:
628628
"""
629-
Parses a YAML targets file into a list of (dependency, version) tuples.
629+
Parses a YAML matrix file into a list of (dependency, version) tuples.
630630
"""
631-
content = _safe_read_file(file_path, required=True, description="targets file")
631+
content = _safe_read_file(file_path, required=True, description="matrix file")
632632
try:
633-
raw_targets = yaml.safe_load(content)
633+
raw_matrix = yaml.safe_load(content)
634634
except Exception as e:
635-
print(f"Error parsing targets YAML mapping: {e}", file=sys.stderr)
635+
print(f"Error parsing matrix YAML mapping: {e}", file=sys.stderr)
636636
sys.exit(1)
637637

638-
if not isinstance(raw_targets, dict):
639-
print("Error: Targets file content must resolve to a YAML mapping", file=sys.stderr)
638+
if not isinstance(raw_matrix, dict):
639+
print("Error: Matrix file content must resolve to a YAML mapping", file=sys.stderr)
640640
sys.exit(1)
641641

642642
targets = []
643-
for dep, versions in raw_targets.items():
643+
for dep, versions in raw_matrix.items():
644644
if isinstance(versions, list):
645645
for v in versions:
646646
if v is None or isinstance(v, (dict, list)):
@@ -675,7 +675,7 @@ def main():
675675
)
676676

677677
parser.add_argument(
678-
"--targets-file",
678+
"-m", "--matrix-file",
679679
help="Path to a YAML file containing target dependencies and versions."
680680
)
681681

@@ -744,16 +744,16 @@ def main():
744744

745745
# Validation of required inputs
746746
has_single_target = bool(args.dependency and args.version)
747-
has_targets_file = bool(args.targets_file)
747+
has_matrix_file = bool(args.matrix_file)
748748

749-
if not (has_single_target or has_targets_file):
750-
parser.error("Must specify either (-d/--dependency AND -v/--version) OR (--targets-file)")
751-
if has_single_target and has_targets_file:
752-
parser.error("Cannot specify both single target (-d/-v) and targets file (--targets-file)")
749+
if not (has_single_target or has_matrix_file):
750+
parser.error("Must specify either (-d/--dependency AND -v/--version) OR (-m/--matrix-file)")
751+
if has_single_target and has_matrix_file:
752+
parser.error("Cannot specify both single target (-d/-v) and matrix file (-m/--matrix-file)")
753753

754754
targets = []
755-
if has_targets_file:
756-
targets = parse_targets_file(args.targets_file)
755+
if has_matrix_file:
756+
targets = parse_matrix_file(args.matrix_file)
757757
else:
758758
targets = [(args.dependency, args.version)]
759759

@@ -772,7 +772,7 @@ def main():
772772
elif args.package_file:
773773
target_packages = read_package_file(args.package_file)
774774

775-
if has_targets_file:
775+
if has_matrix_file:
776776
print("Starting scan for multiple targets:")
777777
for dep, ver in targets:
778778
print(f" - {dep}: {ver}")
@@ -809,7 +809,7 @@ def main():
809809
rules,
810810
target_packages,
811811
ignore_dirs,
812-
version_string=(None if has_targets_file else args.version),
812+
version_string=(None if has_matrix_file else args.version),
813813
targets=targets
814814
)
815815

@@ -833,8 +833,8 @@ def main():
833833
script_dir = os.path.dirname(os.path.abspath(__file__))
834834
results_dir = os.path.join(script_dir, "results")
835835
os.makedirs(results_dir, exist_ok=True)
836-
if has_targets_file:
837-
base_name = os.path.splitext(os.path.basename(args.targets_file))[0]
836+
if has_matrix_file:
837+
base_name = os.path.splitext(os.path.basename(args.matrix_file))[0]
838838
output_path = os.path.join(results_dir, f"{base_name}-{timestamp}.csv")
839839
else:
840840
output_path = os.path.join(results_dir, f"{args.dependency}-{args.version}-{timestamp}.csv")

0 commit comments

Comments
 (0)