o
    	Ti                      @   sd   d dl Z d dlZd dlZd dlmZ de j dZdd Zdd Zd	d
 Z	e
dkr0e	  dS dS )    N)datetimez# Copyright 2020-aN   The HuggingFace Team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
c               
   C   sp   zt jddgt jddd} | j }dd |D }|W S  t jy7 } ztd|  g W  Y d}~S d}~ww )	z1Get a list of all tracked Python files using git.gitzls-filesT)stdouttextcheckc                 S   s   g | ]	}| d r|qS )z.py)endswith).0f r
   J/home/ubuntu/.local/lib/python3.10/site-packages/scripts/add_copyrights.py
<listcomp>-   s    z,get_tracked_python_files.<locals>.<listcomp>zError fetching tracked files: N)
subprocessrunPIPEr   
splitlinesCalledProcessErrorprint)resultfilespy_fileser
   r
   r   get_tracked_python_files%   s   
r   c                 C   s   t j| std|  d dS t| dd}| }W d   n1 s%w   Y  d|tr4dS td|  d	 t| d
dd}|	td d|  W d   dS 1 s[w   Y  dS )zECheck if the file contains a copyright notice, and add it if missing.z[SKIP] z does not exist.Nzutf-8)encoding Tz[MODIFY] Adding copyright to .w
F)
ospathisfiler   open	readlinesjoin
startswithCOPYRIGHT_HEADERwrite)	file_pathr	   contentr
   r
   r   check_and_add_copyright4   s   

r(   c                  C   sl   t  } | std dS tdt|  d dd | D }t|s+td td dS td	 td
 dS )zFMain function to check and add copyright for all tracked Python files.z.No Python files are tracked in the repository.Nz	Checking z% Python files for copyright notice...c                 S   s   g | ]}t |qS r
   )r(   )r   r&   r
   r
   r   r   R   s    zmain.<locals>.<listcomp>uI   ❌ Some files were missing the required copyright and have been updated.   u*   ✅ All files have the required copyright.r   )r   r   lenallsysexit)r   have_copyrightr
   r
   r   mainI   s   r/   __main__)r   r   r,   r   nowyearr$   r   r(   r/   __name__r
   r
   r
   r   <module>   s   
