MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / _apply_reuse_annotation

Method _apply_reuse_annotation

scripts/add-spdx-attribution.py:389–429  ·  view source on GitHub ↗

Apply SPDX headers using the REUSE tool.

(self, file_path: Path, headers: List[str])

Source from the content-addressed store, hash-verified

387 return "Apache-2.0"
388
389 def _apply_reuse_annotation(self, file_path: Path, headers: List[str]) -> bool:
390 """Apply SPDX headers using the REUSE tool."""
391 if not headers:
392 return False
393
394 try:
395 # Prepare REUSE command - pass full SPDX-FileCopyrightText headers directly
396 cmd = ["reuse", "annotate"]
397
398 # Add all copyright lines with full SPDX-FileCopyrightText format
399 for header in headers:
400 cmd.extend(
401 ["--copyright", header]
402 ) # Keep the full SPDX-FileCopyrightText: format
403
404 # Preserve existing license or use Apache-2.0 as default
405 existing_license = self._get_existing_license(file_path)
406 cmd.extend(["--license", existing_license])
407
408 # Handle Solidity files which need explicit style specification
409 if file_path.suffix == ".sol":
410 cmd.extend(["--style", "c"])
411
412 # Add the file
413 cmd.append(str(file_path))
414
415 if self.dry_run:
416 print(f"Would run: {' '.join(cmd)}")
417 return True
418 else:
419 result = subprocess.run(
420 cmd, capture_output=True, text=True, cwd=self.repo_root
421 )
422 if result.returncode != 0:
423 print(f"REUSE command failed for {file_path}: {result.stderr}")
424 return False
425 return True
426
427 except subprocess.SubprocessError as e:
428 print(f"Error running REUSE on {file_path}: {e}")
429 return False
430
431 def process_file(self, file_path: Path) -> bool:
432 """Process a single file to add SPDX attribution."""

Callers 1

process_fileMethod · 0.95

Calls 3

_get_existing_licenseMethod · 0.95
appendMethod · 0.80
runMethod · 0.45

Tested by

no test coverage detected