Skip to content

Commit

Permalink
Update and fix copyright headers (#1589)
Browse files Browse the repository at this point in the history
Updates the header according to
https://docs.opensource.microsoft.com/releasing/general-guidance/copyright-headers/
and enforce it with ruff. Ref:
https://docs.opensource.microsoft.com/news/2019-07-02-cela-all-rights-reserved/

Fix additional ruff lint errors due to enabling `--preview` rules for
the copyright header lint check.
  • Loading branch information
justinchuby authored Jun 5, 2024
1 parent b007b12 commit 8b1a63b
Show file tree
Hide file tree
Showing 215 changed files with 454 additions and 347 deletions.
8 changes: 6 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Configuration file for the Sphinx documentation builder.
# To run the documentation: python -m sphinx docs dist/html
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Configuration file for the Sphinx documentation builder.
To run the documentation: python -m sphinx docs dist/html
"""

import os
import re
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/01_plot_selu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Generating a FunctionProto
==========================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/02_plot_square_loss.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Generating a ModelProto
=======================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/03_export_lib.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Generating a LibProto
=====================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/04_plot_eager_mode_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Eager mode evaluation
=====================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/05_plot_model_props.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
ModelProto Properties
=====================
Expand Down
2 changes: 2 additions & 0 deletions docs/examples/06_plot_model_local_funs.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""
Model Local Functions
=====================
Expand Down
4 changes: 1 addition & 3 deletions docs/test/test_documentation_examples.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

import os
import subprocess
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/dropout.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/firstdim.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/forloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/forwhileloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/hardmax_end_to_end.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import onnx

# We use ONNX opset 15 to define the function below.
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/leaky_relu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/leaky_relu_attr_promoted.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/omitted_input.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
4 changes: 3 additions & 1 deletion docs/tutorial/examples/outerscope_redef_error.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import graph, script
from onnxscript import opset15 as op

Expand All @@ -13,7 +15,7 @@ def Sum(sum_in, next):
return sum_out, sum_out

g = op.Constant(value=1)
all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
_all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
return cumulative_sum

except Exception as e:
Expand Down
4 changes: 3 additions & 1 deletion docs/tutorial/examples/scanloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import graph, script
from onnxscript import opset15 as op

Expand All @@ -9,5 +11,5 @@ def Sum(sum_in, next):
sum_out = sum_in + next
return sum_out, sum_out

all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
_all_sum, cumulative_sum = op.Scan(0, X, body=Sum, num_scan_inputs=1)
return cumulative_sum
2 changes: 2 additions & 0 deletions docs/tutorial/examples/softplus.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# We use ONNX opset 15 to define the function below.
from onnxscript import opset15 as op
from onnxscript import script
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/tensor_attr.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnx import TensorProto, helper

from onnxscript import opset15 as op
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/tensor_attr2.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnx import TensorProto, helper

from onnxscript import opset15 as op
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/tensor_attr_short.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnxscript import opset15 as op
from onnxscript import script

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/examples/whileloop.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from onnx import TensorProto
from onnx.helper import make_tensor

Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/rewriter/examples/broadcast_matmul.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Onnx Pattern Rewriting with match condition parameter.
This script shows how to define a rewriting rule based on patterns while
Expand Down
2 changes: 2 additions & 0 deletions docs/tutorial/rewriter/examples/erfgelu.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Onnx Pattern Rewriting.
This script shows how to define a rewriting rule based on patterns.
Expand Down
6 changes: 4 additions & 2 deletions docs/update_readme.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Script to update end-to-end example in README.md.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Script to update end-to-end example in README.md."""

updated_readme = []
with open("README.md", encoding="utf-8") as f:
Expand All @@ -12,7 +14,7 @@
with open(
"docs/tutorial/examples/hardmax_end_to_end.py", encoding="utf-8"
) as example_f:
example_code = example_f.readlines()
example_code = example_f.readlines()[2:] # Skip the copyright header
updated_readme += example_code
if line == "```\n" and in_stub:
updated_readme.append(line)
Expand Down
6 changes: 5 additions & 1 deletion examples/pattern_rewriting.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Onnx Pattern Rewriting.
This script shows how to define a rewriting rule based on patterns.
Expand Down Expand Up @@ -74,7 +76,9 @@ def rotary_match_pattern(op, x, pos_ids, axis):

matmul = op.MatMul(pos_ids, cast)
transpose = op.Transpose(matmul)
output, length = op.ConcatTraining(transpose, transpose, domain="com.microsoft", outputs=2)
output, _length = op.ConcatTraining(
transpose, transpose, domain="com.microsoft", outputs=2
)

sin = op.Sin(output)
cast1 = op.Cast(sin, to=onnx.TensorProto.FLOAT)
Expand Down
2 changes: 2 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Test with different environment configuration with nox.
Documentation:
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

__all__ = [
"script",
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/_internal/analysis.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations

import ast
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_internal/analysis_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import annotations

import ast
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_internal/ast_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Utilities for working with Python ASTs."""

from __future__ import annotations
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/_internal/autocast.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

from __future__ import annotations

Expand Down
4 changes: 1 addition & 3 deletions onnxscript/_internal/deprecation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
"""Utility for deprecating APIs."""

# Reference: https://github.com/pytorch/pytorch/blob/aed9bee0413dac190452fbfa9ab2a44b6e6843f5/torch/onnx/_deprecation.py
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_internal/param_manipulation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Function for manipulating input parameters of an Op or a OnnxFunction."""

from __future__ import annotations
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_internal/param_manipulation_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# mypy: disable-error-code=misc

import collections
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_internal/runtime_typing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""An internal wrapper for the beartype library.
Decorate a function with `@runtime_typing.checked` to enable runtime
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/_internal/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations

import numbers
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_internal/version_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Version utils for testing."""

import packaging.version
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_legacy_ir/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import annotations

import dataclasses
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_legacy_ir/visitor.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
from __future__ import annotations

import dataclasses
Expand Down
2 changes: 2 additions & 0 deletions onnxscript/_legacy_ir/visitor_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
import unittest

import onnx
Expand Down
4 changes: 2 additions & 2 deletions onnxscript/_thirdparty/asciichartpy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# SPDX-License-Identifier: MIT
# Modifications Copyright (c) Microsoft.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
#
# Copyright © 2016 Igor Kroitor
#
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/backend/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
6 changes: 2 additions & 4 deletions onnxscript/backend/onnx_backend.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------


import os
Expand Down Expand Up @@ -291,7 +289,7 @@ def enumerate_onnx_tests(series, fct_filter=None) -> Iterator[OnnxBackendTest]:
sub = os.path.join(root, "data", series)
if not os.path.exists(sub):
raise FileNotFoundError(
"Unable to find series of tests in {root!r}, subfolders:\n"
f"Unable to find series of tests in {root!r}, subfolders:\n"
+ "\n".join(os.listdir(root))
)
tests = os.listdir(sub)
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/backend/onnx_backend_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------

import os
import unittest
Expand Down
6 changes: 2 additions & 4 deletions onnxscript/backend/onnx_export.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations

from typing import Any, Optional, Sequence
Expand Down Expand Up @@ -311,7 +309,7 @@ def _translate_onnx_var_ref(self, var):

def _rename_domain(self, domain: str) -> str:
if domain in {"", "ai.onnx"}:
return "opset" # TODO: Need checks to avoid name conflicts.
return "opset" # TODO: Need checks to avoid name conflicts.
return _cleanup_variable_name(domain) # type: ignore[return-value]

def _make_opset_name(self, domain, version):
Expand Down
4 changes: 1 addition & 3 deletions onnxscript/backend/onnx_export_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# -------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
# --------------------------------------------------------------------------
from __future__ import annotations

import dataclasses
Expand Down
Loading

0 comments on commit 8b1a63b

Please sign in to comment.