Unverified Commit 9c8fde8e authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Handle copyright in add-new-model-like (#17218)

parent 993553b2
...@@ -18,6 +18,7 @@ import os ...@@ -18,6 +18,7 @@ import os
import re import re
from argparse import ArgumentParser, Namespace from argparse import ArgumentParser, Namespace
from dataclasses import dataclass from dataclasses import dataclass
from datetime import date
from itertools import chain from itertools import chain
from pathlib import Path from pathlib import Path
from typing import Any, Callable, Dict, List, Optional, Pattern, Tuple, Union from typing import Any, Callable, Dict, List, Optional, Pattern, Tuple, Union
...@@ -32,6 +33,7 @@ from . import BaseTransformersCLICommand ...@@ -32,6 +33,7 @@ from . import BaseTransformersCLICommand
logger = logging.get_logger(__name__) # pylint: disable=invalid-name logger = logging.get_logger(__name__) # pylint: disable=invalid-name
CURRENT_YEAR = date.today().year
TRANSFORMERS_PATH = Path(__file__).parent.parent TRANSFORMERS_PATH = Path(__file__).parent.parent
REPO_PATH = TRANSFORMERS_PATH.parent.parent REPO_PATH = TRANSFORMERS_PATH.parent.parent
...@@ -421,6 +423,7 @@ def duplicate_module( ...@@ -421,6 +423,7 @@ def duplicate_module(
with open(module_file, "r", encoding="utf-8") as f: with open(module_file, "r", encoding="utf-8") as f:
content = f.read() content = f.read()
content = re.sub("# Copyright (\d+)\s", f"# Copyright {CURRENT_YEAR} ", content)
objects = parse_module_content(content) objects = parse_module_content(content)
# Loop and treat all objects # Loop and treat all objects
...@@ -1062,6 +1065,7 @@ def duplicate_doc_file( ...@@ -1062,6 +1065,7 @@ def duplicate_doc_file(
with open(doc_file, "r", encoding="utf-8") as f: with open(doc_file, "r", encoding="utf-8") as f:
content = f.read() content = f.read()
content = re.sub("<!--\s*Copyright (\d+)\s", f"<!--Copyright {CURRENT_YEAR} ", content)
if frameworks is None: if frameworks is None:
frameworks = get_default_frameworks() frameworks = get_default_frameworks()
if dest_file is None: if dest_file is None:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment