From 5717126b47136a85c8100c200420ea35696c6fc5 Mon Sep 17 00:00:00 2001 From: Shengye Wan Date: Wed, 29 Jan 2025 10:43:45 -0800 Subject: [PATCH] CodeShield to use absolute imports Reviewed By: laurendeason, lisroach Differential Revision: D67810408 fbshipit-source-id: d2354f6dbcee234f3c1bab69e925f46cb169f7d9 --- CodeShield/codeshield.py | 9 +++++---- .../tests/insecure_code_detector_test.py | 8 ++++---- .../tests/test_c_insecure_code_detector.py | 3 ++- .../tests/test_cpp_insecure_code_detector.py | 3 ++- .../tests/test_csharp_insecure_code_detector.py | 3 ++- .../insecure_code_detector/tests/test_functional.py | 8 ++++---- .../tests/test_java_insecure_code_detector.py | 3 ++- .../tests/test_javascript_insecure_code_detector.py | 3 ++- .../tests/test_kotlin_insecure_code_detector.py | 3 ++- .../tests/test_objective_c_code_detector.py | 3 ++- .../tests/test_php_insecure_code_detector.py | 3 ++- .../tests/test_python_insecure_code_detector.py | 3 ++- .../tests/test_ruby_insecure_code_detector.py | 3 ++- .../tests/test_rust_insecure_code_detector.py | 3 ++- .../tests/test_swift_code_detector.py | 3 ++- .../tests/test_xml_insecure_code_detector.py | 3 ++- .../benchmark/instruct_or_autocomplete_benchmark.py | 6 +++--- 17 files changed, 42 insertions(+), 28 deletions(-) diff --git a/CodeShield/codeshield.py b/CodeShield/codeshield.py index 82d4716c2..98f13918f 100644 --- a/CodeShield/codeshield.py +++ b/CodeShield/codeshield.py @@ -15,10 +15,11 @@ import logging from dataclasses import dataclass -from .insecure_code_detector import insecure_code_detector, languages -from .insecure_code_detector.issues import Issue, Severity -from .insecure_code_detector.languages import Language -from .insecure_code_detector.usecases import UseCase +from CodeShield.insecure_code_detector import insecure_code_detector, languages + +from CodeShield.insecure_code_detector.issues import Issue, Severity +from CodeShield.insecure_code_detector.languages import Language +from CodeShield.insecure_code_detector.usecases import UseCase LOG: logging.Logger = logging.getLogger(__name__) diff --git a/CodeShield/insecure_code_detector/tests/insecure_code_detector_test.py b/CodeShield/insecure_code_detector/tests/insecure_code_detector_test.py index 367fa87c2..1ab27764b 100644 --- a/CodeShield/insecure_code_detector/tests/insecure_code_detector_test.py +++ b/CodeShield/insecure_code_detector/tests/insecure_code_detector_test.py @@ -10,13 +10,13 @@ import unittest from abc import ABC -from .. import insecure_code_detector -from ..languages import Language +from CodeShield.insecure_code_detector import insecure_code_detector +from CodeShield.insecure_code_detector.languages import Language try: - from ..internal import oss + from CodeShield.insecure_code_detector.internal import oss except ImportError: - from .. import oss + from CodeShield.insecure_code_detector import oss class InsecureCodeDetectorTest(unittest.IsolatedAsyncioTestCase, ABC): diff --git a/CodeShield/insecure_code_detector/tests/test_c_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_c_insecure_code_detector.py index 4ded120d1..c2f65c799 100644 --- a/CodeShield/insecure_code_detector/tests/test_c_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_c_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_cpp_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_cpp_insecure_code_detector.py index 88b173adb..576eea65a 100644 --- a/CodeShield/insecure_code_detector/tests/test_cpp_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_cpp_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_csharp_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_csharp_insecure_code_detector.py index 6fcf4df05..8136433f7 100644 --- a/CodeShield/insecure_code_detector/tests/test_csharp_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_csharp_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_functional.py b/CodeShield/insecure_code_detector/tests/test_functional.py index 930ce5420..6161e82e5 100644 --- a/CodeShield/insecure_code_detector/tests/test_functional.py +++ b/CodeShield/insecure_code_detector/tests/test_functional.py @@ -8,13 +8,13 @@ import unittest -from .. import insecure_code_detector -from ..languages import Language +from CodeShield.insecure_code_detector import insecure_code_detector +from CodeShield.insecure_code_detector.languages import Language try: - from ..internal import oss + from CodeShield.insecure_code_detector.internal import oss except ImportError: - from .. import oss + from CodeShield.insecure_code_detector import oss # the following test cases contain an input string, the insecure pattern match line number, and the expected rule C_REGEX_TEST_CASES = [ diff --git a/CodeShield/insecure_code_detector/tests/test_java_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_java_insecure_code_detector.py index c39a6570c..2db1c6008 100644 --- a/CodeShield/insecure_code_detector/tests/test_java_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_java_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_javascript_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_javascript_insecure_code_detector.py index 8468bf516..4c283d138 100644 --- a/CodeShield/insecure_code_detector/tests/test_javascript_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_javascript_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_kotlin_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_kotlin_insecure_code_detector.py index 88d932ea2..8ea51f72a 100644 --- a/CodeShield/insecure_code_detector/tests/test_kotlin_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_kotlin_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_objective_c_code_detector.py b/CodeShield/insecure_code_detector/tests/test_objective_c_code_detector.py index 1825dc3df..eba63332d 100644 --- a/CodeShield/insecure_code_detector/tests/test_objective_c_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_objective_c_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_php_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_php_insecure_code_detector.py index 47301943b..d79279cb2 100644 --- a/CodeShield/insecure_code_detector/tests/test_php_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_php_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest PHP_TEST_CASES = [ diff --git a/CodeShield/insecure_code_detector/tests/test_python_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_python_insecure_code_detector.py index 324c2a5aa..17edbb76e 100644 --- a/CodeShield/insecure_code_detector/tests/test_python_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_python_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_ruby_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_ruby_insecure_code_detector.py index aa03659d3..dd4c053b4 100644 --- a/CodeShield/insecure_code_detector/tests/test_ruby_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_ruby_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_rust_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_rust_insecure_code_detector.py index 86af01521..39e5f3114 100644 --- a/CodeShield/insecure_code_detector/tests/test_rust_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_rust_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_swift_code_detector.py b/CodeShield/insecure_code_detector/tests/test_swift_code_detector.py index 8311d8a48..de336d791 100644 --- a/CodeShield/insecure_code_detector/tests/test_swift_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_swift_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CodeShield/insecure_code_detector/tests/test_xml_insecure_code_detector.py b/CodeShield/insecure_code_detector/tests/test_xml_insecure_code_detector.py index c3d74a891..813d82306 100644 --- a/CodeShield/insecure_code_detector/tests/test_xml_insecure_code_detector.py +++ b/CodeShield/insecure_code_detector/tests/test_xml_insecure_code_detector.py @@ -6,7 +6,8 @@ # pyre-strict -from ..languages import Language +from CodeShield.insecure_code_detector.languages import Language + from .insecure_code_detector_test import InsecureCodeDetectorTest # the following test cases contain an input string, and the corresponding number of expected insecure pattern matches diff --git a/CybersecurityBenchmarks/benchmark/instruct_or_autocomplete_benchmark.py b/CybersecurityBenchmarks/benchmark/instruct_or_autocomplete_benchmark.py index 20e128f96..044c06620 100644 --- a/CybersecurityBenchmarks/benchmark/instruct_or_autocomplete_benchmark.py +++ b/CybersecurityBenchmarks/benchmark/instruct_or_autocomplete_benchmark.py @@ -10,10 +10,10 @@ from pathlib import Path -from tqdm import tqdm +from CodeShield.insecure_code_detector import insecure_code_detector +from CodeShield.insecure_code_detector.languages import Language -from ...CodeShield.insecure_code_detector import insecure_code_detector -from ...CodeShield.insecure_code_detector.languages import Language +from tqdm import tqdm from .benchmark import Benchmark from .bleu import compute_bleu_score