Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add SPDX header to sources #807

Merged
merged 1 commit into from
Mar 2, 2025
Merged

Add SPDX header to sources #807

merged 1 commit into from
Mar 2, 2025

Conversation

ayerofieiev-tt
Copy link
Member

@ayerofieiev-tt ayerofieiev-tt commented Mar 1, 2025

Add SPDX header to all out sources

#!/usr/bin/env python3

import os
import sys

# The copyright header to add
COPYRIGHT_HEADER = """# SPDX-FileCopyrightText: © 2025 Tenstorrent AI ULC
#
# SPDX-License-Identifier: Apache-2.0
"""

def add_copyright_to_file(file_path):
    """Add copyright header to a Python file if it doesn't already have it."""
    with open(file_path, 'r', encoding='utf-8') as f:
        content = f.read()
    
    # Check if the header is already present
    if COPYRIGHT_HEADER.strip() in content:
        print(f"Header already present in {file_path}")
        return False
    
    # Add the header at the beginning of the file
    with open(file_path, 'w', encoding='utf-8') as f:
        f.write(COPYRIGHT_HEADER)
        # If the file has a shebang line, we need to handle it specially
        if content.startswith('#!'):
            # Split at the first newline
            shebang, rest = content.split('\n', 1)
            f.write(shebang + '\n\n')
            f.write(rest)
        else:
            f.write(content)
    
    print(f"Added header to {file_path}")
    return True

def process_directory(directory):
    """Process all Python files in a directory recursively."""
    modified_count = 0
    
    for root, dirs, files in os.walk(directory):
        for file in files:
            if file.endswith('.py'):
                full_path = os.path.join(root, file)
                if add_copyright_to_file(full_path):
                    modified_count += 1
    
    return modified_count

if __name__ == "__main__":
    project_dir = '/home/ubuntu/pytorch2.0_ttnn'
    
    # Skip directories that should be excluded (if any)
    # excluded_dirs = ['.git', '.github', '__pycache__']
    
    print(f"Adding copyright headers to Python files in {project_dir}")
    modified_count = process_directory(project_dir)
    print(f"Added copyright header to {modified_count} files")

@ayerofieiev-tt ayerofieiev-tt changed the title Add SPDX header to sourced Add SPDX header to sources Mar 1, 2025
@ayerofieiev-tt ayerofieiev-tt enabled auto-merge March 1, 2025 01:23
@ayerofieiev-tt ayerofieiev-tt disabled auto-merge March 2, 2025 20:50
@ayerofieiev-tt ayerofieiev-tt merged commit 8c78b36 into main Mar 2, 2025
1 check passed
@ayerofieiev-tt ayerofieiev-tt deleted the ay/spdx branch March 2, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant