From ac7d3fb8ae4493979c041dc446cd824439c2028c Mon Sep 17 00:00:00 2001
From: Shenghang Tsai <jackalcooper@gmail.com>
Date: Thu, 3 Jun 2021 20:48:45 +0800
Subject: [PATCH] CI checks if license duplicated (#5091)

* Remove redundant copyright header

* ci check if license duplicated

* refine

* refine

* refine

* address review

Co-authored-by: liujuncheng <liujuncheng1022@gmail.com>
Co-authored-by: oneflow-ci-bot <69100618+oneflow-ci-bot@users.noreply.github.com>
---
 ci/check/run_license_format.py                | 33 +++++++++++--------
 .../graph/stream_index_getter_registry.cpp    | 24 --------------
 .../core/graph/stream_index_getter_registry.h | 12 -------
 .../stream_index_getter_registry_manager.cpp  | 24 --------------
 .../stream_index_getter_registry_manager.h    | 12 -------
 oneflow/python/nn/modules/dataset.py          | 12 -------
 oneflow/python/test/modules/test_dropout.py   | 12 -------
 oneflow/python/test/ops/test_logsoftmax.py    | 12 -------
 oneflow/user/kernels/pad2d_kernels.cpp        | 12 -------
 9 files changed, 20 insertions(+), 133 deletions(-)

diff --git a/ci/check/run_license_format.py b/ci/check/run_license_format.py
index 6fcf851f3..0842328f1 100644
--- a/ci/check/run_license_format.py
+++ b/ci/check/run_license_format.py
@@ -35,29 +35,33 @@ def check_file(path):
     with open(path) as f:
         content = f.read()
         txt = get_txt(path)
+        if content.count("The OneFlow Authors. All rights reserved.") > 1:
+            return ("duplicated", content)
         if content.startswith(txt) or (not content):
-            return (True, content)
+            return ("ok", content)
         else:
-            return (False, content)
+            return ("absent", content)
 
 
 def format_file(path):
     txt = get_txt(path)
     with open(path, "r", encoding="utf-8") as r:
         content = r.read()
-    is_formatted, content = check_file(path)
-    if is_formatted:
+    format_status, content = check_file(path)
+    if format_status == "ok":
         return True
-    else:
+    elif format_status == "absent":
         with open(path, "w") as w:
             new_content = txt + content
             w.write(new_content)
         return False
+    else:
+        raise ValueError(f"license {format_status} {path}")
 
 
 def do_check(x):
-    is_formatted, _ = check_file(x)
-    return (x, is_formatted)
+    format_status, _ = check_file(x)
+    return (x, format_status)
 
 
 def do_format(x):
@@ -91,13 +95,16 @@ if __name__ == "__main__":
     with Pool(10) as p:
         if args.check:
             any_absence = False
-            for (p, is_formatted) in p.map(do_check, files):
-                if is_formatted == False:
-                    print("license absent:", p)
+            for (p, format_status) in p.map(do_check, files):
+                if format_status != "ok":
+                    print(f"license {format_status}:", p)
                     any_absence = True
             if any_absence:
                 exit(1)
         if args.fix:
-            for (p, is_formatted) in p.map(do_format, files):
-                if is_formatted == False:
-                    print("license added:", p)
+            for (p, format_result) in p.map(do_format, files):
+                if format_result == True:
+                    if args.verbose:
+                        print("license already added:", p)
+                else:
+                    print("license just added:", p)
diff --git a/oneflow/core/graph/stream_index_getter_registry.cpp b/oneflow/core/graph/stream_index_getter_registry.cpp
index 099d1f36d..67f5659ac 100644
--- a/oneflow/core/graph/stream_index_getter_registry.cpp
+++ b/oneflow/core/graph/stream_index_getter_registry.cpp
@@ -13,30 +13,6 @@ 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.
 */
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
 #include "oneflow/core/graph/stream_index_getter_registry.h"
 #include "oneflow/core/graph/compute_task_node.h"
 #include "oneflow/core/graph/stream_index_getter_registry_manager.h"
diff --git a/oneflow/core/graph/stream_index_getter_registry.h b/oneflow/core/graph/stream_index_getter_registry.h
index ff2206893..f11778ab4 100644
--- a/oneflow/core/graph/stream_index_getter_registry.h
+++ b/oneflow/core/graph/stream_index_getter_registry.h
@@ -13,18 +13,6 @@ 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.
 */
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
 #ifndef ONEFLOW_CORE_GRAPH_STREAM_INDEX_GETTER_REGISTRY_H_
 #define ONEFLOW_CORE_GRAPH_STREAM_INDEX_GETTER_REGISTRY_H_
 
diff --git a/oneflow/core/graph/stream_index_getter_registry_manager.cpp b/oneflow/core/graph/stream_index_getter_registry_manager.cpp
index ccac17082..518354144 100644
--- a/oneflow/core/graph/stream_index_getter_registry_manager.cpp
+++ b/oneflow/core/graph/stream_index_getter_registry_manager.cpp
@@ -13,30 +13,6 @@ 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.
 */
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
 #include "oneflow/core/graph/stream_index_getter_registry_manager.h"
 
 namespace oneflow {
diff --git a/oneflow/core/graph/stream_index_getter_registry_manager.h b/oneflow/core/graph/stream_index_getter_registry_manager.h
index ee3a144d2..8fd6f0cb5 100644
--- a/oneflow/core/graph/stream_index_getter_registry_manager.h
+++ b/oneflow/core/graph/stream_index_getter_registry_manager.h
@@ -13,18 +13,6 @@ 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.
 */
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
 #ifndef ONEFLOW_CORE_GRAPH_STREAM_INDEX_GETTER_REGISTRY_MANAGER_H_
 #define ONEFLOW_CORE_GRAPH_STREAM_INDEX_GETTER_REGISTRY_MANAGER_H_
 
diff --git a/oneflow/python/nn/modules/dataset.py b/oneflow/python/nn/modules/dataset.py
index 5337e5e06..3f6442427 100644
--- a/oneflow/python/nn/modules/dataset.py
+++ b/oneflow/python/nn/modules/dataset.py
@@ -13,18 +13,6 @@ 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.
 """
-"""
-Copyright 2020 The OneFlow Authors. 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.
-"""
 import oneflow as flow
 
 from oneflow.python.oneflow_export import oneflow_export, experimental_api
diff --git a/oneflow/python/test/modules/test_dropout.py b/oneflow/python/test/modules/test_dropout.py
index 2cbd66a71..635b20873 100644
--- a/oneflow/python/test/modules/test_dropout.py
+++ b/oneflow/python/test/modules/test_dropout.py
@@ -13,18 +13,6 @@ 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.
 """
-"""
-Copyright 2020 The OneFlow Authors. 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.
-"""
 import unittest
 from collections import OrderedDict
 
diff --git a/oneflow/python/test/ops/test_logsoftmax.py b/oneflow/python/test/ops/test_logsoftmax.py
index 3df36be67..2279a5619 100644
--- a/oneflow/python/test/ops/test_logsoftmax.py
+++ b/oneflow/python/test/ops/test_logsoftmax.py
@@ -13,18 +13,6 @@ 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.
 """
-"""
-Copyright 2020 The OneFlow Authors. 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.
-"""
 import oneflow as flow
 import numpy as np
 import oneflow.typing as tp
diff --git a/oneflow/user/kernels/pad2d_kernels.cpp b/oneflow/user/kernels/pad2d_kernels.cpp
index 5360f019b..ea801d00f 100644
--- a/oneflow/user/kernels/pad2d_kernels.cpp
+++ b/oneflow/user/kernels/pad2d_kernels.cpp
@@ -13,18 +13,6 @@ 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.
 */
-/*
-Copyright 2020 The OneFlow Authors. 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.
-*/
 #include "oneflow/core/common/nd_index_offset_helper.h"
 #include "oneflow/core/device/memory_copier.h"
 #include "oneflow/core/framework/framework.h"
-- 
GitLab