Skip to content

Commit

Permalink
Add missing licenses (#4170)
Browse files Browse the repository at this point in the history
* Enable copyright rule

* Update licenses

* Apply simplify rule

* Add a notice on preview rules

* Update license in utils file
  • Loading branch information
sovrasov authored Jan 7, 2025
1 parent 7fda29c commit 8296a43
Show file tree
Hide file tree
Showing 31 changed files with 93 additions and 12 deletions.
12 changes: 11 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ select = [
"B", # flake8-bugbear (`B`)
"A", # flake8-builtins (`A`)
"COM", # flake8-commas (`COM`)
# "CPY", # flake8-copyright (`CPY`) -> Rules included in the preview version of RUFF. It may be added in the future, but for now, disable it.
"C4", # flake8-comprehensions (`C4`)
"DTZ", # flake8-datatimez (`DTZ`)
"T10", # flake8-debugger (`T10`)
Expand Down Expand Up @@ -246,6 +245,11 @@ select = [
"RUF", # Ruff-specific rules (`RUF`)
]

# to be removed when updating to ruff>=2.0
preview = true
explicit-preview-rules = true
extend-select = ["CPY001"]

ignore = [
# pydocstyle
# On top of the Google convention, disable `D417`, which requires
Expand Down Expand Up @@ -360,6 +364,12 @@ max-branches = 50
max-statements = 150
max-returns = 10

[tool.ruff.lint.flake8-copyright]
notice-rgx = """
# Copyright \\(C\\) (\\d{4}(-\\d{4})?) Intel Corporation
# SPDX-License-Identifier: Apache-2\\.0
"""

[tool.ruff.per-file-ignores]
# Declare an additional exclude rule for test code
"tests/**/*.py" = [
Expand Down
2 changes: 1 addition & 1 deletion src/otx/algo/common/utils/assigners/hungarian_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ def batch_preparation(
"pred_masks": outputs["pred_masks"][i] if "pred_masks" in outputs else None,
"target_boxes": targets[i]["boxes"],
"target_labels": targets[i]["labels"].long(),
"target_mask": targets[i]["masks"] if "masks" in targets[i] else None,
"target_mask": targets[i].get("masks", None),
}
for i in range(batch_size)
]
Expand Down
6 changes: 3 additions & 3 deletions src/otx/algo/detection/losses/rtdetr_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ def __init__(
super().__init__()
self.num_classes = num_classes
self.matcher = HungarianMatcher(cost_dict={"cost_class": 2, "cost_bbox": 5, "cost_giou": 2})
loss_bbox_weight = weight_dict["loss_bbox"] if "loss_bbox" in weight_dict else 1.0
loss_giou_weight = weight_dict["loss_giou"] if "loss_giou" in weight_dict else 1.0
self.loss_vfl_weight = weight_dict["loss_vfl"] if "loss_vfl" in weight_dict else 1.0
loss_bbox_weight = weight_dict.get("loss_bbox", 1.0)
loss_giou_weight = weight_dict.get("loss_giou", 1.0)
self.loss_vfl_weight = weight_dict.get("loss_vfl", 1.0)
self.alpha = alpha
self.gamma = gamma
self.lossl1 = L1Loss(loss_weight=loss_bbox_weight)
Expand Down
4 changes: 2 additions & 2 deletions src/otx/algo/instance_segmentation/losses/maskdino_loss.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ def __init__(
self.num_classes = num_classes
self.matcher = matcher
self.weight_dict = weight_dict
loss_bbox_weight = weight_dict["loss_bbox"] if "loss_bbox" in weight_dict else 1.0
loss_giou_weight = weight_dict["loss_giou"] if "loss_giou" in weight_dict else 1.0
loss_bbox_weight = weight_dict.get("loss_bbox", 1.0)
loss_giou_weight = weight_dict.get("loss_giou", 1.0)
self.lossl1 = L1Loss(loss_weight=loss_bbox_weight)
self.giou = GIoULoss(loss_weight=loss_giou_weight)

Expand Down
3 changes: 2 additions & 1 deletion src/otx/algo/keypoint_detection/heads/rtmcc_head.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (C) 2024 Intel Corporation
# # SPDX-License-Identifier: Apache-2.0
# SPDX-License-Identifier: Apache-2.0

# Copyright (c) OpenMMLab. All rights reserved.
"""Implementation of RTMCCHead."""
from __future__ import annotations
Expand Down
2 changes: 1 addition & 1 deletion src/otx/algo/utils/mmengine_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def load_checkpoint_to_model(
state_dict = checkpoint["ema"]["module"] if "ema" in checkpoint else checkpoint.get("state_dict", checkpoint)

# TODO(Eugene): remove this when MaskDINO weights is updloaded to openvino storage.
state_dict = state_dict["model"] if "model" in state_dict else state_dict
state_dict = state_dict.get("model", state_dict)

# strip prefix of state_dict
metadata = getattr(state_dict, "_metadata", OrderedDict())
Expand Down
4 changes: 3 additions & 1 deletion src/otx/core/utils/pylogger.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (C) 2023-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

# MIT License

# Copyright (c) 2023 Intel Corporation
# Copyright (c) 2021 ashleve

# Permission is hereby granted, free of charge, to any person obtaining a copy
Expand Down
4 changes: 2 additions & 2 deletions src/otx/core/utils/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2024 Intel Corporation
# Copyright (C) 2024-2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
#

"""Utility functions."""

from __future__ import annotations
Expand Down
3 changes: 3 additions & 0 deletions tests/fuzzing/cli_fuzzing.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!.tox/fuzzing/bin/python

# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys

import atheris
Expand Down
3 changes: 3 additions & 0 deletions tests/fuzzing/eval_fuzzing_crash.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!.tox/fuzzing/bin/python

# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import sys
from pathlib import Path

Expand Down
3 changes: 3 additions & 0 deletions tests/fuzzing/helper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import atheris


Expand Down
3 changes: 3 additions & 0 deletions tests/unit/algo/callbacks/test_unlabeled_loss_warmup.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import math

import pytest
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/algo/instance_segmentation/test_evaluation.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import torch
from otx.core.metrics.mean_ap import MaskRLEMeanAveragePrecision
from otx.core.utils.mask_util import encode_rle
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/algo/segmentation/backbones/test_litehrnet.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from unittest.mock import MagicMock

import pytest
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/algo/segmentation/backbones/test_mscan.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path
from unittest.mock import MagicMock

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/algo/segmentation/heads/test_ham_head.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from functools import partial
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/core/config/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0
3 changes: 3 additions & 0 deletions tests/unit/core/data/dataset/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from unittest import mock

import numpy as np
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from pathlib import Path
from unittest.mock import MagicMock, patch

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from unittest.mock import Mock, patch

import numpy as np
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/core/exporter/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from unittest.mock import MagicMock, patch

import pytest
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/core/exporter/test_native.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import onnx
import pytest
import torch
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/core/model/test_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import pytest
import torch
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/core/utils/test_mask_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import numpy as np
import torch
from otx.core.utils.mask_util import encode_rle
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/engine/adaptive_bs/test_adaptive_bs_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from math import sqrt
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/engine/adaptive_bs/test_bs_search_algo.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from unittest.mock import MagicMock

import pytest
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/hpo/test_hpo_base.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import json
from pathlib import Path

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/hpo/test_resource_manager.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import pytest
from otx.core.types.device import DeviceType
from otx.hpo import resource_manager as target_file
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/hpo/test_search_space.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

import copy
import math

Expand Down
3 changes: 3 additions & 0 deletions tests/unit/utils/test_signal.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

import signal
Expand Down
3 changes: 3 additions & 0 deletions tests/unit/utils/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Copyright (C) 2025 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from __future__ import annotations

from functools import partial
Expand Down

0 comments on commit 8296a43

Please sign in to comment.