An open source, non-profit web search engine
Rename django app to mwmbl
Daoud Clarke918eaa8709c0
diff --git a/Dockerfile b/Dockerfileindex f57bce7..4283a14 100644--- a/Dockerfile+++ b/Dockerfile@@ -46,5 +46,8 @@ VOLUME ["/data"]EXPOSE 5000-# Using the mwmbl-tinysearchengine binary/entrypoint which comes packaged with mwmbl-CMD ["/venv/bin/mwmbl-tinysearchengine", "--num-pages", "10240000", "--background", "--data", "/app/storage"]+ENV DJANGO_SETTINGS_MODULE=mwmbl.settings_dev++# WORKDIR "/venv/lib/python3.10/site-packages/mwmbl/"+# CMD ["/venv/bin/python", "-m", "uvicorn", "app.asgi:application"]+CMD ["/venv/bin/mwmbl-tinysearchengine"]diff --git a/analyse/analyse_crawled_domains.py b/analyse/analyse_crawled_domains.pyindex 371cbb6..5e87abb 100644--- a/analyse/analyse_crawled_domains.py+++ b/analyse/analyse_crawled_domains.py@@ -7,8 +7,8 @@ import jsonfrom collections import defaultdict, Counterfrom urllib.parse import urlparse-from mwmbl.crawler.batch import HashedBatch-from mwmbl.indexer.paths import CRAWL_GLOB, MWMBL_DATA_DIR+from mwmbl.crawler import HashedBatch+from mwmbl.indexer import CRAWL_GLOB, MWMBL_DATA_DIR# TODO: remove this line - temporary overridediff --git a/analyse/export_top_domains.py b/analyse/export_top_domains.pyindex 9f4d495..b9b4479 100644--- a/analyse/export_top_domains.py+++ b/analyse/export_top_domains.py@@ -1,6 +1,6 @@import json-from mwmbl.indexer.paths import TOP_DOMAINS_JSON_PATH+from mwmbl.indexer import TOP_DOMAINS_JSON_PATHfrom mwmbl.hn_top_domains_filtered import DOMAINSdiff --git a/analyse/export_urls.py b/analyse/export_urls.pyindex a042260..39ba98e 100644--- a/analyse/export_urls.py+++ b/analyse/export_urls.py@@ -3,7 +3,7 @@ Export the list of unique URLs to a SQLite file for analysis/evaluation."""import sqlite3-from mwmbl.indexer.paths import URLS_PATH+from mwmbl.indexer import URLS_PATHfrom mwmbl.app import get_config_and_indexdiff --git a/analyse/index_local.py b/analyse/index_local.pyindex 24628a5..334868d 100644--- a/analyse/index_local.py+++ b/analyse/index_local.py@@ -7,16 +7,15 @@ import jsonimport loggingimport osimport sys-from pathlib import Pathfrom datetime import datetimeimport spacy-from mwmbl.crawler.batch import HashedBatch+from mwmbl.crawler import HashedBatchfrom mwmbl.crawler.urls import URLDatabasefrom mwmbl.database import Database-from mwmbl.indexer.index_batches import index_batches-from mwmbl.tinysearchengine.indexer import TinyIndex, Document+from mwmbl.indexer import index_batches+from mwmbl.tinysearchengine import TinyIndex, DocumentLOCAL_BATCHES_PATH = f'{os.environ["HOME"]}/data/mwmbl/file/**/*.json.gz'NUM_BATCHES = 10000diff --git a/analyse/index_url_count.py b/analyse/index_url_count.pyindex f0c7ac2..dcb7245 100644--- a/analyse/index_url_count.py+++ b/analyse/index_url_count.py@@ -1,7 +1,7 @@"""Count unique URLs in the index."""-from mwmbl.tinysearchengine.indexer import TinyIndex, Document+from mwmbl.tinysearchengine import TinyIndex, Documentdef run():diff --git a/analyse/inspect_index.py b/analyse/inspect_index.pyindex 20b0619..c48ad22 100644--- a/analyse/inspect_index.py+++ b/analyse/inspect_index.py@@ -5,9 +5,9 @@ import numpy as npimport spacyfrom analyse.index_local import EVALUATE_INDEX_PATH-from mwmbl.indexer.index import tokenize_document-from mwmbl.indexer.paths import INDEX_PATH-from mwmbl.tinysearchengine.indexer import TinyIndex, Document+from mwmbl.indexer import tokenize_document+from mwmbl.indexer import INDEX_PATH+from mwmbl.tinysearchengine import TinyIndex, Documentlogging.basicConfig(stream=sys.stdout, level=logging.DEBUG)diff --git a/analyse/record_historical_batches.py b/analyse/record_historical_batches.pyindex 4d8ccd3..c482e49 100644--- a/analyse/record_historical_batches.py+++ b/analyse/record_historical_batches.py@@ -4,12 +4,10 @@ See how many unique URLs and root domains we have crawled.import globimport gzipimport json-from collections import defaultdict, Counter-from urllib.parse import urlparseimport requests-from mwmbl.indexer.paths import CRAWL_GLOB+from mwmbl.indexer import CRAWL_GLOBAPI_ENDPOINT = "http://95.216.215.29/batches/historical"diff --git a/analyse/search.py b/analyse/search.pyindex 4ffbd54..4bc3b72 100644--- a/analyse/search.py+++ b/analyse/search.py@@ -2,9 +2,9 @@ import loggingimport sysfrom itertools import islice-from mwmbl.indexer.paths import INDEX_PATH+from mwmbl.indexer import INDEX_PATHfrom mwmbl.tinysearchengine.completer import Completer-from mwmbl.tinysearchengine.indexer import TinyIndex, Document+from mwmbl.tinysearchengine import TinyIndex, Documentfrom mwmbl.tinysearchengine.rank import HeuristicRankerlogging.basicConfig(stream=sys.stdout, level=logging.DEBUG)diff --git a/analyse/send_batch.py b/analyse/send_batch.pyindex 9191834..6d52d41 100644--- a/analyse/send_batch.py+++ b/analyse/send_batch.py@@ -3,7 +3,7 @@ Send a batch to a running instance."""import requests-from mwmbl.crawler.batch import Batch, Item, ItemContent+from mwmbl.crawler import Batch, Item, ItemContentURL = 'http://localhost:5000/crawler/batches/'diff --git a/analyse/update_urls.py b/analyse/update_urls.pyindex 0655df7..f26c804 100644--- a/analyse/update_urls.py+++ b/analyse/update_urls.py@@ -4,7 +4,7 @@ from datetime import datetimefrom pathlib import Pathfrom queue import Queue-from mwmbl.indexer.update_urls import record_urls_in_database+from mwmbl.indexer import record_urls_in_databasedef run_update_urls_on_fixed_batches():diff --git a/app/__init__.py b/app/__init__.pydeleted file mode 100644index e69de29..0000000diff --git a/app/api.py b/mwmbl/api.pysimilarity index 100%rename from app/api.pyrename to mwmbl/api.pydiff --git a/app/apps.py b/mwmbl/apps.pysimilarity index 96%rename from app/apps.pyrename to mwmbl/apps.pyindex 166aaff..bfc21a5 100644--- a/app/apps.py+++ b/mwmbl/apps.py@@ -4,7 +4,7 @@ from pathlib import Pathfrom django.apps import AppConfigfrom django.conf import settings-from app.api import queued_batches+from mwmbl.api import queued_batchesfrom mwmbl import backgroundfrom mwmbl.indexer.paths import INDEX_NAMEfrom mwmbl.indexer.update_urls import update_urls_continuously@@ -13,7 +13,7 @@ from mwmbl.url_queue import update_queue_continuouslyclass MwmblConfig(AppConfig):- name = "app"+ name = "mwmbl"verbose_name = "Mwmbl Application"def ready(self):diff --git a/app/asgi.py b/mwmbl/asgi.pysimilarity index 82%rename from app/asgi.pyrename to mwmbl/asgi.pyindex c8d5aaa..73088a9 100644--- a/app/asgi.py+++ b/mwmbl/asgi.py@@ -11,6 +11,6 @@ import osfrom django.core.asgi import get_asgi_application-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mwmbl.settings_dev')application = get_asgi_application()diff --git a/mwmbl/crawler/app.py b/mwmbl/crawler/app.pyindex bda2dc8..a4f0524 100644--- a/mwmbl/crawler/app.py+++ b/mwmbl/crawler/app.py@@ -10,7 +10,7 @@ from uuid import uuid4import boto3import justextimport requests-from fastapi import HTTPException, APIRouter+from fastapi import HTTPExceptionfrom justext.core import html_to_dom, ParagraphMaker, classify_paragraphs, revise_paragraph_classification, \LENGTH_LOW_DEFAULT, STOPWORDS_LOW_DEFAULT, MAX_LINK_DENSITY_DEFAULT, NO_HEADINGS_DEFAULT, LENGTH_HIGH_DEFAULT, \STOPWORDS_HIGH_DEFAULT, MAX_HEADING_DISTANCE_DEFAULT, DEFAULT_ENCODING, DEFAULT_ENC_ERRORS, preprocessordiff --git a/mwmbl/crawler/urls.py b/mwmbl/crawler/urls.pyindex cefe19e..7c83edf 100644--- a/mwmbl/crawler/urls.py+++ b/mwmbl/crawler/urls.py@@ -1,16 +1,13 @@"""Database storing info on URLs"""-import randomfrom dataclasses import dataclass-from datetime import datetime, timedelta+from datetime import datetimefrom enum import Enumfrom logging import getLoggerfrom psycopg2.extras import execute_values-from mwmbl.hn_top_domains_filtered import DOMAINS-from mwmbl.settings import CORE_DOMAINS# Client has one hour to crawl a URL that has been assigned to them, or it will be reassignedfrom mwmbl.utils import batchdiff --git a/mwmbl/indexer/batch_cache.py b/mwmbl/indexer/batch_cache.pyindex e7af6db..01d8cc9 100644--- a/mwmbl/indexer/batch_cache.py+++ b/mwmbl/indexer/batch_cache.py@@ -9,7 +9,6 @@ import osfrom logging import getLoggerfrom multiprocessing.pool import ThreadPoolfrom pathlib import Path-from tempfile import NamedTemporaryFilefrom urllib.parse import urlparsefrom pydantic import ValidationErrordiff --git a/mwmbl/indexer/index.py b/mwmbl/indexer/index.pyindex 4edcb8a..fb61405 100644--- a/mwmbl/indexer/index.py+++ b/mwmbl/indexer/index.py@@ -1,13 +1,10 @@"""Create a search index"""-from collections import Counterfrom typing import Iterablefrom urllib.parse import unquote-import pandas as pd--from mwmbl.tinysearchengine.indexer import Document, TokenizedDocument, TinyIndex+from mwmbl.tinysearchengine.indexer import TokenizedDocumentfrom mwmbl.tokenizer import tokenize, get_bigramsDEFAULT_SCORE = 0diff --git a/mwmbl/indexer/update_urls.py b/mwmbl/indexer/update_urls.pyindex 3819777..8a1b973 100644--- a/mwmbl/indexer/update_urls.py+++ b/mwmbl/indexer/update_urls.py@@ -1,13 +1,10 @@-import os-import pickle-import refrom collections import defaultdictfrom datetime import datetime, timezone, timedeltafrom logging import getLoggerfrom multiprocessing import Queuefrom pathlib import Pathfrom time import sleep-from typing import Iterable, Collection+from typing import Collectionfrom urllib.parse import urlparsefrom requests_cache import CachedSessiondiff --git a/mwmbl/main.py b/mwmbl/main.pynew file mode 100644index 0000000..0281edc--- /dev/null+++ b/mwmbl/main.py@@ -0,0 +1,9 @@+import uvicorn+++def run():+ uvicorn.run("mwmbl.asgi:application", host="0.0.0.0", port=8000)+++if __name__ == "__main__":+ run()diff --git a/mwmbl/platform/user.py b/mwmbl/platform/user.pyindex a3006c4..bbdcb0e 100644--- a/mwmbl/platform/user.py+++ b/mwmbl/platform/user.py@@ -7,7 +7,7 @@ import requestsfrom fastapi import APIRouter, Responsefrom pydantic import BaseModel-from mwmbl.tinysearchengine.indexer import TinyIndex, Document, DocumentState+from mwmbl.tinysearchengine.indexer import TinyIndex, Documentfrom mwmbl.tokenizer import tokenizediff --git a/app/settings_common.py b/mwmbl/settings_common.pysimilarity index 96%rename from app/settings_common.pyrename to mwmbl/settings_common.pyindex 2753dc6..b08b62c 100644--- a/app/settings_common.py+++ b/mwmbl/settings_common.py@@ -1,5 +1,5 @@"""-Django settings for app project.+Django settings for mwmbl project.Generated by 'django-admin startproject' using Django 4.2.4.@@ -37,7 +37,7 @@ INSTALLED_APPS = ['django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles',- 'app',+ 'mwmbl',]MIDDLEWARE = [@@ -50,7 +50,7 @@ MIDDLEWARE = ['django.middleware.clickjacking.XFrameOptionsMiddleware',]-ROOT_URLCONF = 'app.urls'+ROOT_URLCONF = 'mwmbl.urls'TEMPLATES = [{@@ -68,7 +68,7 @@ TEMPLATES = [},]-WSGI_APPLICATION = 'app.wsgi.application'+WSGI_APPLICATION = 'mwmbl.wsgi.application'# Databasediff --git a/app/settings_dev.py b/mwmbl/settings_dev.pysimilarity index 67%rename from app/settings_dev.pyrename to mwmbl/settings_dev.pyindex bb8e33f..fe07890 100644--- a/app/settings_dev.py+++ b/mwmbl/settings_dev.py@@ -1,4 +1,4 @@-from app.settings_common import *+from mwmbl.settings_common import *DATA_PATH = "./devdata"RUN_BACKGROUND_PROCESSES = Falsediff --git a/app/settings_prod.py b/mwmbl/settings_prod.pysimilarity index 69%rename from app/settings_prod.pyrename to mwmbl/settings_prod.pyindex 37c9cf3..f7c50ee 100644--- a/app/settings_prod.py+++ b/mwmbl/settings_prod.py@@ -1,4 +1,4 @@-from app.settings_common import *+from mwmbl.settings_common import *DATA_PATH = "/app/storage"RUN_BACKGROUND_PROCESSES = Truediff --git a/mwmbl/tinysearchengine/rank.py b/mwmbl/tinysearchengine/rank.pyindex 81109fd..7f331b8 100644--- a/mwmbl/tinysearchengine/rank.py+++ b/mwmbl/tinysearchengine/rank.py@@ -6,7 +6,6 @@ from operator import itemgetterfrom urllib.parse import urlparsefrom mwmbl.format import format_result_with_pattern, get_query_regex-from mwmbl.platform.user import MAX_CURATED_SCOREfrom mwmbl.tokenizer import tokenize, get_bigramsfrom mwmbl.tinysearchengine.completer import Completerfrom mwmbl.hn_top_domains_filtered import DOMAINSdiff --git a/mwmbl/url_queue.py b/mwmbl/url_queue.pyindex ab0f1bc..8151550 100644--- a/mwmbl/url_queue.py+++ b/mwmbl/url_queue.py@@ -1,6 +1,5 @@import timefrom collections import defaultdict-from dataclasses import dataclassfrom datetime import datetime, timedeltafrom logging import getLoggerfrom multiprocessing import Queuediff --git a/app/urls.py b/mwmbl/urls.pysimilarity index 96%rename from app/urls.pyrename to mwmbl/urls.pyindex 440a2f4..ff67f2d 100644--- a/app/urls.py+++ b/mwmbl/urls.py@@ -17,7 +17,7 @@ Including another URLconffrom django.contrib import adminfrom django.urls import path-from app.api import api+from mwmbl.api import apiurlpatterns = [path('admin/', admin.site.urls),diff --git a/app/wsgi.py b/mwmbl/wsgi.pysimilarity index 82%rename from app/wsgi.pyrename to mwmbl/wsgi.pyindex ef30895..ebdf0ff 100644--- a/app/wsgi.py+++ b/mwmbl/wsgi.py@@ -11,6 +11,6 @@ import osfrom django.core.wsgi import get_wsgi_application-os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'app.settings')+os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mwmbl.settings_dev')application = get_wsgi_application()diff --git a/test/test_completer.py b/test/test_completer.pyindex b1fb49e..8867f26 100644--- a/test/test_completer.py+++ b/test/test_completer.py@@ -1,5 +1,3 @@-import mwmbl.tinysearchengine.completer-import pytestimport pandas as pddef mockCompleterData(mocker, data):@@ -16,7 +14,7 @@ def test_correctCompletions(mocker):[3, 'buildings', 1]]mockCompleterData(mocker, testdata)- completer = mwmbl.tinysearchengine.completer.Completer()+ completer = app.tinysearchengine.completer.Completer()completion = completer.complete('build')assert ['build', 'builder', 'buildings'] == completion@@ -29,7 +27,7 @@ def test_correctSortOrder(mocker):[3, 'buildings', 3]]mockCompleterData(mocker, testdata)- completer = mwmbl.tinysearchengine.completer.Completer()+ completer = app.tinysearchengine.completer.Completer()completion = completer.complete('build')assert ['build', 'buildings', 'builder'] == completion@@ -42,7 +40,7 @@ def test_noCompletions(mocker):[3, 'buildings', 1]]mockCompleterData(mocker, testdata)- completer = mwmbl.tinysearchengine.completer.Completer()+ completer = app.tinysearchengine.completer.Completer()completion = completer.complete('test')assert [] == completion@@ -55,7 +53,7 @@ def test_singleCompletions(mocker):[3, 'buildings', 1]]mockCompleterData(mocker, testdata)- completer = mwmbl.tinysearchengine.completer.Completer()+ completer = app.tinysearchengine.completer.Completer()completion = completer.complete('announce')assert ['announce'] == completion@@ -68,7 +66,7 @@ def test_idempotencyWithSameScoreCompletions(mocker):[3, 'buildings', 1]]mockCompleterData(mocker, testdata)- completer = mwmbl.tinysearchengine.completer.Completer()+ completer = app.tinysearchengine.completer.Completer()for i in range(3):print(f"iteration: {i}")completion = completer.complete('build')diff --git a/test/test_indexer.py b/test/test_indexer.pyindex dd25b18..cf714c0 100644--- a/test/test_indexer.py+++ b/test/test_indexer.py@@ -1,9 +1,9 @@from pathlib import Pathfrom tempfile import TemporaryDirectory-from mwmbl.tinysearchengine.indexer import Document, TinyIndex, _binary_search_fitting_size, astuple, _trim_items_to_page, _get_page_data, _pad_to_page_size-from zstandard import ZstdDecompressor, ZstdCompressor, ZstdError-import json+from mwmbl.tinysearchengine import Document, TinyIndex, _binary_search_fitting_size, astuple, _trim_items_to_page, _get_page_data, _pad_to_page_size+from zstandard import ZstdCompressor+def test_create_index():num_pages = 10diff --git a/test/test_update_urls.py b/test/test_update_urls.pyindex 8f205f8..089caea 100644--- a/test/test_update_urls.py+++ b/test/test_update_urls.py@@ -1,4 +1,4 @@-from mwmbl.indexer.update_urls import process_link+from mwmbl.indexer import process_linkdef test_process_link_normal():