Use the src/ layout to fix packaging Khoj for PyPi

- Why
  The khoj pypi packages should be installed in `khoj' directory.
  Previously it was being installed into `src' directory, which is a
  generic top level directory name that is discouraged from being used

- Changes
 - move src/* to src/khoj/*
 - update `setup.py' to `find_packages' in `src' instead of project root
 - rename imports to form `from khoj.*' in complete project
 - update `constants.web_directory' path to use `khoj' directory
 - rename root logger to `khoj' in `main.py'
 - fix image_search tests to use the newly rename `khoj' logger
 - update config, docs, workflows to reference new path `src/khoj'
This commit is contained in:
Debanjum Singh Solanky
2023-02-14 14:50:51 -06:00
parent cc31cd070d
commit 25a749ca1d
104 changed files with 209 additions and 208 deletions

View File

@@ -4,13 +4,13 @@ from pathlib import Path
import pytest
# Internal Packages
from src.search_type import image_search, text_search
from src.utils.helpers import resolve_absolute_path
from src.utils.rawconfig import ContentConfig, TextContentConfig, ImageContentConfig, SearchConfig, TextSearchConfig, ImageSearchConfig
from src.processor.org_mode.org_to_jsonl import OrgToJsonl
from src.search_filter.date_filter import DateFilter
from src.search_filter.word_filter import WordFilter
from src.search_filter.file_filter import FileFilter
from khoj.search_type import image_search, text_search
from khoj.utils.helpers import resolve_absolute_path
from khoj.utils.rawconfig import ContentConfig, TextContentConfig, ImageContentConfig, SearchConfig, TextSearchConfig, ImageSearchConfig
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
from khoj.search_filter.date_filter import DateFilter
from khoj.search_filter.word_filter import WordFilter
from khoj.search_filter.file_filter import FileFilter
@pytest.fixture(scope='session')

View File

@@ -28,7 +28,7 @@
;; Khoj Package for Semantic Search
(use-package khoj
:after org
:straight (khoj :type git :host github :repo "debanjum/khoj" :files (:defaults "src/interface/emacs/khoj.el"))
:straight (khoj :type git :host github :repo "debanjum/khoj" :files (:defaults "src/khoj/interface/emacs/khoj.el"))
:bind ("C-c s" . 'khoj))
```
- With [Quelpa](https://github.com/quelpa/quelpa#installation)

View File

@@ -6,8 +6,8 @@
*Allow natural language search on user content like notes, images,
transactions using transformer ML models*
User can interface with Khoj via [Web](./src/interface/web/index.html),
[Emacs](./src/interface/emacs/khoj.el) or the API. All search is done
User can interface with Khoj via [Web](./src/khoj/interface/web/index.html),
[Emacs](./src/khoj/interface/emacs/khoj.el) or the API. All search is done
locally[\*](https://github.com/debanjum/khoj#miscellaneous)
## Demo
@@ -47,8 +47,8 @@ just generating embeddings*
- [Update Index](http://localhost:8000/api/update?t=ledger)
- [Configure Application](https://localhost:8000/ui)
- **Khoj via Emacs**
- [Install](https://github.com/debanjum/khoj/tree/master/src/interface/emacs#installation)
[khoj.el](./src/interface/emacs/khoj.el)
- [Install](https://github.com/debanjum/khoj/tree/master/src/khoj/interface/emacs#installation)
[khoj.el](./src/khoj/interface/emacs/khoj.el)
- Run `M-x khoj <user-query>`
## Run Unit tests
@@ -118,7 +118,7 @@ docker-compose build --pull
images, transactions etc specified in config YAML
``` shell
python3 -m src.main -c=config/khoj_sample.yml -vv
python3 -m src.khoj.main -c=config/khoj_sample.yml -vv
```
### Upgrade On Local Machine

View File

@@ -2,7 +2,7 @@
import json
# Internal Packages
from src.processor.ledger.beancount_to_jsonl import BeancountToJsonl
from khoj.processor.ledger.beancount_to_jsonl import BeancountToJsonl
def test_no_transactions_in_file(tmp_path):

View File

@@ -2,7 +2,7 @@
import pytest
# Internal Packages
from src.processor.conversation.gpt import converse, understand, message_to_prompt
from khoj.processor.conversation.gpt import converse, understand, message_to_prompt
# Initialize variables for tests

View File

@@ -3,8 +3,8 @@ from pathlib import Path
from random import random
# Internal Packages
from src.utils.cli import cli
from src.utils.helpers import resolve_absolute_path
from khoj.utils.cli import cli
from khoj.utils.helpers import resolve_absolute_path
# Test

View File

@@ -8,13 +8,13 @@ from urllib.parse import quote
from fastapi.testclient import TestClient
# Internal Packages
from src.main import app
from src.utils.state import model, config
from src.search_type import text_search, image_search
from src.utils.rawconfig import ContentConfig, SearchConfig
from src.processor.org_mode.org_to_jsonl import OrgToJsonl
from src.search_filter.word_filter import WordFilter
from src.search_filter.file_filter import FileFilter
from khoj.main import app
from khoj.utils.state import model, config
from khoj.search_type import text_search, image_search
from khoj.utils.rawconfig import ContentConfig, SearchConfig
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
from khoj.search_filter.word_filter import WordFilter
from khoj.search_filter.file_filter import FileFilter
# Arrange

View File

@@ -4,8 +4,8 @@ from datetime import datetime
from math import inf
# Application Packages
from src.search_filter.date_filter import DateFilter
from src.utils.rawconfig import Entry
from khoj.search_filter.date_filter import DateFilter
from khoj.utils.rawconfig import Entry
def test_date_filter():

View File

@@ -1,6 +1,6 @@
# Application Packages
from src.search_filter.file_filter import FileFilter
from src.utils.rawconfig import Entry
from khoj.search_filter.file_filter import FileFilter
from khoj.utils.rawconfig import Entry
def test_no_file_filter():

View File

@@ -1,4 +1,4 @@
from src.utils import helpers
from khoj.utils import helpers
def test_get_from_null_dict():
# null handling

View File

@@ -4,11 +4,11 @@ from pathlib import Path
from PIL import Image
# Internal Packages
from src.utils.state import model
from src.utils.constants import web_directory
from src.search_type import image_search
from src.utils.helpers import resolve_absolute_path
from src.utils.rawconfig import ContentConfig, SearchConfig
from khoj.utils.state import model
from khoj.utils.constants import web_directory
from khoj.search_type import image_search
from khoj.utils.helpers import resolve_absolute_path
from khoj.utils.rawconfig import ContentConfig, SearchConfig
# Test
@@ -91,7 +91,7 @@ def test_image_search_query_truncated(content_config: ContentConfig, search_conf
# Act
try:
with caplog.at_level(logging.INFO, logger="src.search_type.image_search"):
with caplog.at_level(logging.INFO, logger="khoj.search_type.image_search"):
image_search.query(
query,
count = 1,
@@ -114,7 +114,7 @@ def test_image_search_by_filepath(content_config: ContentConfig, search_config:
expected_image_path = f"{image_directory.joinpath('kitten_park.jpg')}"
# Act
with caplog.at_level(logging.INFO, logger="src.search_type.image_search"):
with caplog.at_level(logging.INFO, logger="khoj.search_type.image_search"):
hits = image_search.query(
query,
count = 1,

View File

@@ -2,7 +2,7 @@
import json
# Internal Packages
from src.processor.markdown.markdown_to_jsonl import MarkdownToJsonl
from khoj.processor.markdown.markdown_to_jsonl import MarkdownToJsonl
def test_markdown_file_with_no_headings_to_jsonl(tmp_path):

View File

@@ -2,10 +2,10 @@
import json
# Internal Packages
from src.processor.org_mode.org_to_jsonl import OrgToJsonl
from src.processor.text_to_jsonl import TextToJsonl
from src.utils.helpers import is_none_or_empty
from src.utils.rawconfig import Entry
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
from khoj.processor.text_to_jsonl import TextToJsonl
from khoj.utils.helpers import is_none_or_empty
from khoj.utils.rawconfig import Entry
def test_configure_heading_entry_to_jsonl(tmp_path):

View File

@@ -2,7 +2,7 @@
import datetime
# Internal Packages
from src.processor.org_mode import orgnode
from khoj.processor.org_mode import orgnode
# Test

View File

@@ -6,10 +6,10 @@ from pathlib import Path
import pytest
# Internal Packages
from src.utils.state import model
from src.search_type import text_search
from src.utils.rawconfig import ContentConfig, SearchConfig, TextContentConfig
from src.processor.org_mode.org_to_jsonl import OrgToJsonl
from khoj.utils.state import model
from khoj.search_type import text_search
from khoj.utils.rawconfig import ContentConfig, SearchConfig, TextContentConfig
from khoj.processor.org_mode.org_to_jsonl import OrgToJsonl
# Test

View File

@@ -1,6 +1,6 @@
# Application Packages
from src.search_filter.word_filter import WordFilter
from src.utils.rawconfig import Entry
from khoj.search_filter.word_filter import WordFilter
from khoj.utils.rawconfig import Entry
def test_no_word_filter():