Skip to content

Commit

Permalink
Add isort to the pre-commit configuration and apply it to the whole p…
Browse files Browse the repository at this point in the history
…roject (#595)

* Apply isort to the entire repository
* Fix missing import issues in text_to_entries
* Fix imports in migration files
  • Loading branch information
sabaimran authored Dec 28, 2023
1 parent 738f050 commit 79913d4
Show file tree
Hide file tree
Showing 87 changed files with 271 additions and 371 deletions.
7 changes: 7 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ repos:
- id: check-toml
- id: check-yaml

- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
args: ["--profile", "black", "--filter-files"]

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.0.0
hooks:
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
https://docs.djangoproject.com/en/4.2/ref/settings/
"""

from pathlib import Path
import os
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
from django.urls import path

urlpatterns = [
path("admin/", admin.site.urls),
Expand Down
35 changes: 14 additions & 21 deletions src/khoj/configure.py
Original file line number Diff line number Diff line change
@@ -1,44 +1,37 @@
# Standard Packages
import logging
import json
import logging
import os
from enum import Enum
from typing import Optional
import requests
import os

# External Packages
import openai
import requests
import schedule
from starlette.middleware.sessions import SessionMiddleware
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.requests import HTTPConnection

from starlette.authentication import (
AuthCredentials,
AuthenticationBackend,
SimpleUser,
UnauthenticatedUser,
)
from starlette.middleware.authentication import AuthenticationMiddleware
from starlette.middleware.sessions import SessionMiddleware
from starlette.requests import HTTPConnection

# Internal Packages
from khoj.database.models import KhojUser, Subscription
from khoj.database.adapters import (
ConversationAdapters,
SubscriptionState,
aget_user_subscription_state,
get_all_users,
get_or_create_search_models,
aget_user_subscription_state,
SubscriptionState,
)
from khoj.database.models import KhojUser, Subscription
from khoj.processor.embeddings import CrossEncoderModel, EmbeddingsModel
from khoj.routers.indexer import configure_content, load_content, configure_search
from khoj.routers.indexer import configure_content, configure_search, load_content
from khoj.utils import constants, state
from khoj.utils.config import (
SearchType,
)
from khoj.utils.config import SearchType
from khoj.utils.fs_syncer import collect_files
from khoj.utils.rawconfig import FullConfig


logger = logging.getLogger(__name__)


Expand All @@ -52,7 +45,7 @@ class UserAuthenticationBackend(AuthenticationBackend):
def __init__(
self,
):
from khoj.database.models import KhojUser, KhojApiUser
from khoj.database.models import KhojApiUser, KhojUser

self.khojuser_manager = KhojUser.objects
self.khojapiuser_manager = KhojApiUser.objects
Expand Down Expand Up @@ -190,10 +183,10 @@ def configure_routes(app):
# Import APIs here to setup search types before while configuring server
from khoj.routers.api import api
from khoj.routers.api_beta import api_beta
from khoj.routers.web_client import web_client
from khoj.routers.indexer import indexer
from khoj.routers.auth import auth_router
from khoj.routers.indexer import indexer
from khoj.routers.subscription import subscription_router
from khoj.routers.web_client import web_client

app.include_router(api, prefix="/api")
app.include_router(api_beta, prefix="/api/beta")
Expand Down
10 changes: 4 additions & 6 deletions src/khoj/database/adapters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import random
import secrets
import sys
from datetime import date, datetime, timezone, timedelta
from typing import List, Optional, Type
from datetime import date, datetime, timedelta, timezone
from enum import Enum
from typing import List, Optional, Type

from asgiref.sync import sync_to_async
from django.contrib.sessions.backends.db import SessionStore
Expand All @@ -22,20 +22,18 @@
GithubConfig,
GithubRepoConfig,
GoogleUser,
TextToImageModelConfig,
KhojApiUser,
KhojUser,
NotionConfig,
OfflineChatProcessorConversationConfig,
OpenAIProcessorConversationConfig,
ReflectiveQuestion,
SearchModelConfig,
SpeechToTextModelOptions,
Subscription,
TextToImageModelConfig,
UserConversationConfig,
UserSearchModelConfig,
OpenAIProcessorConversationConfig,
OfflineChatProcessorConversationConfig,
ReflectiveQuestion,
)
from khoj.search_filter.date_filter import DateFilter
from khoj.search_filter.file_filter import FileFilter
Expand Down
15 changes: 8 additions & 7 deletions src/khoj/database/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,23 @@
from django.contrib.auth.admin import UserAdmin
from django.http import HttpResponse

# Register your models here.

from khoj.database.models import (
KhojUser,
ChatModelOptions,
OpenAIProcessorConversationConfig,
Conversation,
KhojUser,
OfflineChatProcessorConversationConfig,
OpenAIProcessorConversationConfig,
ReflectiveQuestion,
SearchModelConfig,
SpeechToTextModelOptions,
Subscription,
ReflectiveQuestion,
UserSearchModelConfig,
TextToImageModelConfig,
Conversation,
UserSearchModelConfig,
)

# Register your models here.


admin.site.register(KhojUser, UserAdmin)

admin.site.register(ChatModelOptions)
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0001_khojuser.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import django.contrib.auth.models
import django.contrib.auth.validators
from django.db import migrations, models
import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0002_googleuser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.4 on 2023-09-18 23:24

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
7 changes: 4 additions & 3 deletions src/khoj/database/migrations/0004_content_types_and_more.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# Generated by Django 4.2.5 on 2023-10-11 22:24

from django.conf import settings
from django.db import migrations, models
import uuid

import django.db.models.deletion
import pgvector.django
import uuid
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
3 changes: 2 additions & 1 deletion src/khoj/database/migrations/0005_embeddings_corpus_id.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# Generated by Django 4.2.5 on 2023-10-13 02:39

from django.db import migrations, models
import uuid

from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0006_embeddingsdates.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 4.2.5 on 2023-10-13 19:28

from django.db import migrations, models
import django.db.models.deletion
from django.db import migrations, models


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0007_add_conversation.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.5 on 2023-10-18 05:31

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0009_khojapiuser.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.5 on 2023-10-26 17:02

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.4 on 2023-11-01 17:41

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
4 changes: 2 additions & 2 deletions src/khoj/database/migrations/0011_merge_20231102_0138.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.5 on 2023-11-02 01:38

from django.db import migrations
from typing import Any, List

from typing import List, Any
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0013_subscription.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.5 on 2023-11-09 01:27

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.5 on 2023-11-11 05:39

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0020_reflectivequestion.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.7 on 2023-11-20 01:13

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/migrations/0023_usersearchmodelconfig.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Generated by Django 4.2.7 on 2023-12-19 15:44

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by Django 4.2.7 on 2023-12-20 07:27

from django.db import migrations
import pgvector.django
from django.db import migrations


class Migration(migrations.Migration):
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/database/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid

from django.db import models
from django.contrib.auth.models import AbstractUser
from django.db import models
from pgvector.django import VectorField


Expand Down
6 changes: 3 additions & 3 deletions src/khoj/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
isort:skip_file
"""

# Standard Packages

from contextlib import redirect_stdout
import io
import os
Expand All @@ -18,7 +18,7 @@
warnings.filterwarnings("ignore", message=r"snapshot_download.py has been made private", category=FutureWarning)
warnings.filterwarnings("ignore", message=r"legacy way to download files from the HF hub,", category=FutureWarning)

# External Packages

import uvicorn
import django
from fastapi import FastAPI
Expand Down Expand Up @@ -69,7 +69,7 @@
# Set Locale
locale.setlocale(locale.LC_ALL, "")

# Internal Packages. We do this after setting up Django so that Django features are accessible to the app.
# We import these packages after setting up Django so that Django features are accessible to the app.
from khoj.configure import configure_routes, initialize_server, configure_middleware
from khoj.utils import state
from khoj.utils.cli import cli
Expand Down
2 changes: 1 addition & 1 deletion src/khoj/migrations/migrate_offline_chat_default_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
...
"""
import logging

from packaging import version

from khoj.utils.yaml import load_config_from_file, save_config_to_file


logger = logging.getLogger(__name__)


Expand Down
2 changes: 1 addition & 1 deletion src/khoj/migrations/migrate_offline_chat_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
...
"""
import logging

from packaging import version

from khoj.utils.yaml import load_config_from_file, save_config_to_file


logger = logging.getLogger(__name__)


Expand Down
3 changes: 2 additions & 1 deletion src/khoj/migrations/migrate_offline_model.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import logging
import os

from packaging import version

from khoj.utils.yaml import load_config_from_file, save_config_to_file
Expand Down
Loading

0 comments on commit 79913d4

Please sign in to comment.