diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index aa7c7e781..fa5a6397a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -31,8 +31,15 @@ repos: hooks: - id: isort name: Import Sort (Python files) - exclude: (doc/|__init__.py) - args: ["--profile", "black", "--filter-files"] + exclude: __init__.py + args: [--profile=black, --filter-files, --treat-comment-as-code "# %%"] + + - repo: https://github.com/nbQA-dev/nbQA + rev: 1.9.1 + hooks: + - id: nbqa-isort + name: Import Sort (Jupyter Notebooks) + args: [--profile=black] - repo: https://github.com/PyCQA/flake8 rev: 7.1.1 diff --git a/doc/code/converters/1_llm_converters.ipynb b/doc/code/converters/1_llm_converters.ipynb index 6d9dc70e9..1b719ec2a 100644 --- a/doc/code/converters/1_llm_converters.ipynb +++ b/doc/code/converters/1_llm_converters.ipynb @@ -75,7 +75,6 @@ } ], "source": [ - "\n", "from pyrit.prompt_converter import (\n", " MaliciousQuestionGeneratorConverter,\n", " NoiseConverter,\n", diff --git a/doc/code/memory/chat_message.ipynb b/doc/code/memory/chat_message.ipynb index 5754b8013..a1c450668 100644 --- a/doc/code/memory/chat_message.ipynb +++ b/doc/code/memory/chat_message.ipynb @@ -88,7 +88,6 @@ } ], "source": [ - "\n", "chat_messages = normalizer.from_chatml(\n", " \"\"\"\\\n", " <|im_start|>system\n", diff --git a/doc/code/orchestrators/1_prompt_sending_orchestrator.ipynb b/doc/code/orchestrators/1_prompt_sending_orchestrator.ipynb index a5df9b1b1..8470189b5 100644 --- a/doc/code/orchestrators/1_prompt_sending_orchestrator.ipynb +++ b/doc/code/orchestrators/1_prompt_sending_orchestrator.ipynb @@ -285,7 +285,6 @@ } ], "source": [ - "\n", "import pathlib\n", "\n", "from pyrit.common.path import DATASETS_PATH\n", @@ -349,10 +348,9 @@ "source": [ "import uuid\n", "\n", - "from pyrit.common import initialize_pyrit, IN_MEMORY\n", - "from pyrit.prompt_target import OpenAIChatTarget\n", + "from pyrit.common import IN_MEMORY, initialize_pyrit\n", "from pyrit.orchestrator import PromptSendingOrchestrator\n", - "\n", + "from pyrit.prompt_target import OpenAIChatTarget\n", "\n", "initialize_pyrit(memory_db_type=IN_MEMORY)\n", "\n", diff --git a/doc/code/orchestrators/1_prompt_sending_orchestrator.py b/doc/code/orchestrators/1_prompt_sending_orchestrator.py index e583a3e26..07dc729ae 100644 --- a/doc/code/orchestrators/1_prompt_sending_orchestrator.py +++ b/doc/code/orchestrators/1_prompt_sending_orchestrator.py @@ -179,10 +179,9 @@ # %% import uuid -from pyrit.common import initialize_pyrit, IN_MEMORY -from pyrit.prompt_target import OpenAIChatTarget +from pyrit.common import IN_MEMORY, initialize_pyrit from pyrit.orchestrator import PromptSendingOrchestrator - +from pyrit.prompt_target import OpenAIChatTarget initialize_pyrit(memory_db_type=IN_MEMORY) diff --git a/doc/code/orchestrators/3_xpia_orchestrator.ipynb b/doc/code/orchestrators/3_xpia_orchestrator.ipynb index 1b188fbe2..91ed13a00 100644 --- a/doc/code/orchestrators/3_xpia_orchestrator.ipynb +++ b/doc/code/orchestrators/3_xpia_orchestrator.ipynb @@ -128,7 +128,6 @@ } ], "source": [ - "\n", "from xpia_helpers import AzureStoragePlugin, SemanticKernelPluginAzureOpenAIPromptTarget\n", "\n", "from pyrit.common import IN_MEMORY, initialize_pyrit\n", @@ -784,7 +783,6 @@ } ], "source": [ - "\n", "from pyrit.orchestrator import XPIATestOrchestrator\n", "from pyrit.prompt_target import AzureBlobStorageTarget\n", "from pyrit.score import SubStringScorer\n", @@ -1133,7 +1131,6 @@ } ], "source": [ - "\n", "import os\n", "\n", "from xpia_helpers import AzureStoragePlugin\n", diff --git a/doc/deployment/deploy_hf_model_aml.ipynb b/doc/deployment/deploy_hf_model_aml.ipynb index 18fdf2716..3003db496 100644 --- a/doc/deployment/deploy_hf_model_aml.ipynb +++ b/doc/deployment/deploy_hf_model_aml.ipynb @@ -72,7 +72,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "import os\n", "import random\n", "import string\n", diff --git a/doc/deployment/download_and_register_hf_model_aml.ipynb b/doc/deployment/download_and_register_hf_model_aml.ipynb index f830b6919..53e3b5e6e 100644 --- a/doc/deployment/download_and_register_hf_model_aml.ipynb +++ b/doc/deployment/download_and_register_hf_model_aml.ipynb @@ -75,15 +75,13 @@ "import os\n", "from typing import Union\n", "\n", - "from dotenv import load_dotenv\n", - "\n", "# Import necessary libraries for Azure ML operations and authentication\n", "from azure.ai.ml import MLClient, UserIdentityConfiguration\n", "from azure.ai.ml.dsl import pipeline\n", "from azure.ai.ml.entities import AmlCompute\n", "from azure.core.exceptions import ResourceNotFoundError\n", "from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential\n", - "\n" + "from dotenv import load_dotenv" ] }, { diff --git a/doc/deployment/download_and_register_hf_model_aml.py b/doc/deployment/download_and_register_hf_model_aml.py index c66109e53..57f0ddfea 100644 --- a/doc/deployment/download_and_register_hf_model_aml.py +++ b/doc/deployment/download_and_register_hf_model_aml.py @@ -53,14 +53,13 @@ import os from typing import Union -from dotenv import load_dotenv - # Import necessary libraries for Azure ML operations and authentication from azure.ai.ml import MLClient, UserIdentityConfiguration from azure.ai.ml.dsl import pipeline from azure.ai.ml.entities import AmlCompute from azure.core.exceptions import ResourceNotFoundError from azure.identity import DefaultAzureCredential, InteractiveBrowserCredential +from dotenv import load_dotenv # %% [markdown] # ### 1.2 Load Environment Variables diff --git a/doc/how_to_guide.ipynb b/doc/how_to_guide.ipynb index 4018bee33..8c9fca27a 100644 --- a/doc/how_to_guide.ipynb +++ b/doc/how_to_guide.ipynb @@ -46,7 +46,6 @@ "metadata": {}, "outputs": [], "source": [ - "\n", "import os\n", "\n", "from pyrit.common import DUCK_DB, initialize_pyrit\n",