Skip to content

Commit

Permalink
remove unused imports automatically (Significant-Gravitas#4449)
Browse files Browse the repository at this point in the history
* remove unused imports automatically

* add linters to pr template

* remove useless try statement
  • Loading branch information
waynehamadi authored May 28, 2023
1 parent 7877452 commit ee9f10a
Show file tree
Hide file tree
Showing 33 changed files with 28 additions and 70 deletions.
8 changes: 7 additions & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,13 @@ By following these guidelines, your PRs are more likely to be merged quickly aft
- [ ] I have considered potential risks and mitigations for my changes.
- [ ] I have documented my changes clearly and comprehensively.
- [ ] I have not snuck in any "extra" small tweaks changes. <!-- Submit these as separate Pull Requests, they are the easiest to merge! -->
- [ ] I have run `black .` and `isort .` against my code to ensure it passes our linter.
- [ ] I have run the following commands against my code to ensure it passes our linters:
```shell
black .
isort .
mypy
autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests --in-place
```

<!-- If you haven't added tests, please explain why. If you have, check the appropriate box. If you've ensured your PR is atomic and well-documented, check the corresponding boxes. -->

Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ jobs:
run: mypy
if: success() || failure()

- name: Check for unused imports and pass statements
run: |
cmd="autoflake --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests"
$cmd --check || (echo "You have unused imports or pass statements, please run '${cmd} --in-place'" && exit 1)
test:
permissions:
# Gives the action the necessary permissions for publishing new
Expand Down
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,19 @@ repos:
hooks:
- id: black
language_version: python3.10

- repo: https://github.com/pre-commit/mirrors-mypy
rev: 'v1.3.0'
hooks:
- id: mypy

- repo: local
hooks:
- id: autoflake
name: autoflake
entry: autoflake --in-place --remove-all-unused-imports --recursive --ignore-init-module-imports autogpt tests
language: python
types: [ python ]
- id: pytest-check
name: pytest-check
entry: pytest --cov=autogpt --without-integration --without-slow-integration
Expand Down
2 changes: 1 addition & 1 deletion autogpt/app.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
""" Command and Control """
import json
from typing import Dict, List, NoReturn, Union
from typing import Dict, List, Union

from autogpt.agent.agent_manager import AgentManager
from autogpt.commands.command import CommandRegistry, command
Expand Down
2 changes: 1 addition & 1 deletion autogpt/commands/command.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import functools
import importlib
import inspect
from typing import TYPE_CHECKING, Any, Callable, Optional
from typing import Any, Callable, Optional

from autogpt.config import Config
from autogpt.logs import logger
Expand Down
1 change: 0 additions & 1 deletion autogpt/commands/execute_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os
import subprocess
from pathlib import Path
from typing import TYPE_CHECKING

import docker
from docker.errors import ImageNotFound
Expand Down
1 change: 0 additions & 1 deletion autogpt/commands/file_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import os.path
from typing import TYPE_CHECKING, Generator, Literal

import charset_normalizer
import requests
from colorama import Back, Fore
from requests.adapters import HTTPAdapter, Retry
Expand Down
2 changes: 1 addition & 1 deletion autogpt/commands/web_selenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

from autogpt.commands.command import command
from autogpt.logs import logger
from autogpt.memory.vector import MemoryItem, NoMemory, get_memory
from autogpt.memory.vector import MemoryItem, get_memory
from autogpt.processing.html import extract_hyperlinks, format_hyperlinks
from autogpt.url_utils.validators import validate_url

Expand Down
4 changes: 0 additions & 4 deletions autogpt/llm/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,11 @@ class ModelInfo:
class ChatModelInfo(ModelInfo):
"""Struct for chat model information."""

pass


@dataclass
class TextModelInfo(ModelInfo):
"""Struct for text completion model information."""

pass


@dataclass
class EmbeddingModelInfo(ModelInfo):
Expand Down
2 changes: 0 additions & 2 deletions autogpt/llm/chat.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import time
from random import shuffle
from typing import TYPE_CHECKING

if TYPE_CHECKING:
Expand All @@ -13,7 +12,6 @@
from autogpt.llm.utils import count_message_tokens, create_chat_completion
from autogpt.log_cycle.log_cycle import CURRENT_CONTEXT_FILE_NAME
from autogpt.logs import logger
from autogpt.memory.vector import MemoryItem, get_memory

cfg = Config()

Expand Down
1 change: 0 additions & 1 deletion autogpt/memory/vector/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from typing import Any, overload

import numpy as np
import numpy.typing as npt
import openai

from autogpt.config import Config
Expand Down
7 changes: 0 additions & 7 deletions autogpt/models/base_open_ai_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def on_planning(
prompt (PromptGenerator): The prompt generator.
messages (List[str]): The list of messages.
"""
pass

def can_handle_post_planning(self) -> bool:
"""This method is called to check that the plugin can
Expand Down Expand Up @@ -116,7 +115,6 @@ def on_instruction(self, messages: List[Message]) -> Optional[str]:
Returns:
Optional[str]: The resulting message.
"""
pass

def can_handle_post_instruction(self) -> bool:
"""This method is called to check that the plugin can
Expand Down Expand Up @@ -196,7 +194,6 @@ def handle_chat_completion(
Returns:
str: The resulting response.
"""
pass

def can_handle_text_embedding(self, text: str) -> bool:
"""This method is called to check that the plugin can
Expand All @@ -214,7 +211,6 @@ def handle_text_embedding(self, text: str) -> list:
Returns:
list: The text embedding.
"""
pass

def can_handle_user_input(self, user_input: str) -> bool:
"""This method is called to check that the plugin can
Expand All @@ -237,8 +233,6 @@ def user_input(self, user_input: str) -> str:
str: The user input.
"""

pass

def can_handle_report(self) -> bool:
"""This method is called to check that the plugin can
handle the report method.
Expand All @@ -253,4 +247,3 @@ def report(self, message: str) -> None:
Args:
message (str): The message to report.
"""
pass
2 changes: 1 addition & 1 deletion autogpt/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import zipfile
from pathlib import Path
from typing import List, Optional, Tuple
from typing import List
from urllib.parse import urlparse
from zipimport import zipimporter

Expand Down
2 changes: 0 additions & 2 deletions autogpt/singleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,3 @@ class AbstractSingleton(abc.ABC, metaclass=Singleton):
"""
Abstract singleton class for ensuring only one instance of a class.
"""

pass
2 changes: 0 additions & 2 deletions autogpt/speech/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def _setup(self) -> None:
"""
Setup the voices, API key, etc.
"""
pass

@abc.abstractmethod
def _speech(self, text: str, voice_index: int = 0) -> bool:
Expand All @@ -47,4 +46,3 @@ def _speech(self, text: str, voice_index: int = 0) -> bool:
Args:
text (str): The text to play.
"""
pass
1 change: 0 additions & 1 deletion autogpt/speech/brian.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class BrianSpeech(VoiceBase):

def _setup(self) -> None:
"""Setup the voices, API key, etc."""
pass

def _speech(self, text: str, _: int = 0) -> bool:
"""Speak text using Brian with the streamelements API
Expand Down
9 changes: 1 addition & 8 deletions autogpt/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,8 @@
from colorama import Fore, Style
from git.repo import Repo

from autogpt.logs import logger

# Use readline if available (for clean_input)
try:
import readline
except ImportError:
pass

from autogpt.config import Config
from autogpt.logs import logger


def batch(iterable, max_batch_length: int, overlap: int = 0):
Expand Down
1 change: 0 additions & 1 deletion tests/integration/challenges/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from _pytest.config import Config
from _pytest.config.argparsing import Parser
from _pytest.fixtures import FixtureRequest
from _pytest.monkeypatch import MonkeyPatch


def pytest_addoption(parser: Parser) -> None:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import typing

import pytest

from autogpt.commands.file_operations import read_file, write_to_file
from autogpt.commands.file_operations import read_file
from autogpt.config import Config
from tests.integration.challenges.utils import run_interaction_loop
from tests.utils import requires_api_key
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/challenges/utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import contextlib
import random
from functools import wraps
from typing import Any, Callable, Dict, Generator, Optional, Tuple
from typing import Any, Callable, Dict, Generator, Tuple

import pytest

Expand Down
1 change: 0 additions & 1 deletion tests/integration/memory/conftest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import numpy
import pytest

from autogpt.memory.vector.memory_item import MemoryItem
Expand Down
6 changes: 1 addition & 5 deletions tests/integration/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
import pytest

from autogpt.config.ai_config import AIConfig
from autogpt.setup import (
generate_aiconfig_automatic,
generate_aiconfig_manual,
prompt_user,
)
from autogpt.setup import generate_aiconfig_automatic, prompt_user
from tests.utils import requires_api_key


Expand Down
1 change: 0 additions & 1 deletion tests/test_audio_text_read_audio.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Date: 2023-5-13
# Author: Generated by GoCodeo.
import json
from io import BytesIO
from unittest.mock import MagicMock, patch

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from unittest.mock import patch

import pytest
from openai import InvalidRequestError

from autogpt.configurator import create_config

Expand Down
1 change: 0 additions & 1 deletion tests/test_image_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from PIL import Image

from autogpt.commands.image_gen import generate_image, generate_image_with_sd_webui
from autogpt.config import Config
from tests.utils import requires_api_key


Expand Down
2 changes: 0 additions & 2 deletions tests/test_text_file_parsers.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import json
import tempfile
from functools import partial
from unittest import TestCase
from xml.etree import ElementTree

import docx
import yaml
from bs4 import BeautifulSoup
from PyPDF2 import PdfWriter

from autogpt.commands.file_operations_utils import is_file_binary_fn, read_textual_file
from autogpt.logs import logger
Expand Down
5 changes: 1 addition & 4 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import os
from unittest.mock import Mock, patch
from unittest.mock import patch

import pytest
import requests
from colorama import Fore
from git import Repo

from autogpt.utils import (
clean_input,
get_bulletin_from_web,
get_current_git_branch,
get_latest_bulletin,
Expand Down
10 changes: 1 addition & 9 deletions tests/unit/models/test_base_open_api_plugin.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
from typing import Any, Dict, List, Optional, Tuple

import pytest

from autogpt.models.base_open_ai_plugin import (
BaseOpenAIPlugin,
Message,
PromptGenerator,
)
from autogpt.models.base_open_ai_plugin import BaseOpenAIPlugin


class DummyPlugin(BaseOpenAIPlugin):
"""A dummy plugin for testing purposes."""

pass


@pytest.fixture
def dummy_plugin():
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_browse_scrape_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

# Dependencies:
# pip install pytest-mock
import pytest

from autogpt.commands.web_requests import scrape_links

Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_json_parser.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from unittest import TestCase

from autogpt.json_utils.json_fix_llm import fix_and_parse_json
from tests.utils import skip_in_ci


class TestParseJson(TestCase):
Expand Down
3 changes: 0 additions & 3 deletions tests/unit/test_json_utils_llm.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
# Generated by CodiumAI
import pytest
from loguru import logger

from autogpt.json_utils.json_fix_llm import (
fix_and_parse_json,
fix_json_using_multiple_techniques,
)
from tests.utils import requires_api_key

"""
Code Analysis
Expand Down
1 change: 0 additions & 1 deletion tests/unit/test_plugins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import pytest

from autogpt.config import Config
from autogpt.plugins import denylist_allowlist_check, inspect_zip_for_modules

PLUGINS_TEST_DIR = "tests/unit/data/test_plugins"
Expand Down
1 change: 0 additions & 1 deletion tests/vcr/vcr_filter.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import json
import os
import re
from typing import Any, Dict, List

Expand Down

0 comments on commit ee9f10a

Please sign in to comment.