From 91e58d1b081c431bf4e33dd3393b573cc39cca0c Mon Sep 17 00:00:00 2001 From: Jerakin Date: Wed, 21 Feb 2024 11:24:17 +0100 Subject: [PATCH 01/24] refactor: pyproject.toml --- pyproject.toml | 47 +++++++++++++++++++++++++++++++++++++++++++++++ requirements.txt | 26 -------------------------- 2 files changed, 47 insertions(+), 26 deletions(-) create mode 100644 pyproject.toml delete mode 100644 requirements.txt diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..981f4dc --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,47 @@ +[project] +requires-python = ">= 3.8" +name = "wikmd" +description = "A file-based wiki that aims for simplicity." +authors = [ + { name = "linbreux" } +] + +version = "1.9.0" + +dependencies=[ + "Flask==3.0.2", + "GitPython==3.1.42", + "itsdangerous==2.1.2", + "Jinja2==3.1.3", + "Markdown==3.5.2", + "MarkupSafe==2.1.5", + "PyYAML==6.0.1", + "Werkzeug==3.0.1", + "Whoosh==2.7.4", + "beautifulsoup4==4.12.3", + "click==8.1.7", + "gitdb==4.0.11", + "idna==3.6", + "pandoc-eqnos==2.5.0", + "pandoc-fignos==2.4.0", + "pandoc-secnos==2.2.2", + "pandoc-tablenos==2.3.0", + "pandoc-xnos==2.5.0", + "pandocfilters==1.5.1", + "pypandoc==1.13", + "requests==2.31.0", + "smmap==5.0.1", + "lxml==5.1.0", + "watchdog==2.1.9", + "cachelib==0.12.0", + "psutil==5.9.8", +] + +[project.optional-dependencies] +dev = [ + "pytest", +] + +[build-system] +requires = ["setuptools>=61.0"] +build-backend = "setuptools.build_meta" diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 7b25c49..0000000 --- a/requirements.txt +++ /dev/null @@ -1,26 +0,0 @@ -Flask==3.0.2 -GitPython==3.1.42 -itsdangerous==2.1.2 -Jinja2==3.1.3 -Markdown==3.5.2 -MarkupSafe==2.1.5 -PyYAML==6.0.1 -Werkzeug==3.0.1 -Whoosh==2.7.4 -beautifulsoup4==4.12.3 -click==8.1.7 -gitdb==4.0.11 -idna==3.6 -pandoc-eqnos==2.5.0 -pandoc-fignos==2.4.0 -pandoc-secnos==2.2.2 -pandoc-tablenos==2.3.0 -pandoc-xnos==2.5.0 -pandocfilters==1.5.1 -pypandoc==1.13 -requests==2.31.0 -smmap==5.0.1 -lxml==5.1.0 -watchdog==2.1.9 -cachelib==0.12.0 -psutil==5.9.8 From d8d3a657327588c0e128c8414450dd12b5224c2d Mon Sep 17 00:00:00 2001 From: Jerakin Date: Wed, 21 Feb 2024 11:36:56 +0100 Subject: [PATCH 02/24] refactor: moved all files --- .gitignore | 18 +- README.md | 2 +- plugins/draw/drawings/.gitignore | 1 - __init__.py => src/wikmd/__init__.py | 0 cache.py => src/wikmd/cache.py | 0 config.py => src/wikmd/config.py | 1 + git_manager.py => src/wikmd/git_manager.py | 12 +- .../wikmd/image_manager.py | 2 +- .../wikmd/knowledge_graph.py | 2 +- {plugins => src/wikmd/plugins}/__init__.py | 0 .../wikmd/plugins}/alerts/__init__.py | 0 .../wikmd/plugins}/alerts/alerts.py | 6 +- .../wikmd/plugins}/draw/__init__.py | 0 .../wikmd/plugins}/draw/default_draw | 0 {plugins => src/wikmd/plugins}/draw/draw.py | 12 +- .../wikmd/plugins/draw/drawings}/.gitignore | 0 .../wikmd/plugins}/embed-pages/__init__.py | 0 .../wikmd/plugins}/embed-pages/embed-pages.py | 6 +- .../wikmd/plugins}/load_plugins.py | 5 +- .../wikmd/plugins}/mermaid/__init__.py | 0 .../wikmd/plugins}/mermaid/mermaid.py | 6 +- search.py => src/wikmd/search.py | 4 +- .../wikmd/static}/css/codemirror.custom.css | 0 .../static}/css/codemirror.custom.dark.css | 0 .../wikmd/static}/css/filepond.dark.css | 0 .../wikmd/static}/css/wiki.colors.css | 0 {static => src/wikmd/static}/css/wiki.css | 0 .../wikmd/static}/css/wiki.dark.css | 0 {static => src/wikmd/static}/favicon.ico | Bin .../wikmd/static}/images/contrast-2-fill.svg | 0 .../wikmd/static}/images/file-copy-white.svg | 0 .../wikmd/static}/images/file-copy.svg | 0 .../wikmd/static}/images/graph_5.svg | 0 .../wikmd/static}/images/knowledge-graph.png | Bin .../wikmd/static}/images/readme-img.png | Bin {static => src/wikmd/static}/images/wiki.gif | Bin {static => src/wikmd/static}/images/wiki.png | Bin {static => src/wikmd/static}/images/wiki2.gif | Bin {static => src/wikmd/static}/js/.empty | 0 {static => src/wikmd/static}/js/copypaste.js | 4 +- {static => src/wikmd/static}/js/drawio.js | 0 {templates => src/wikmd/templates}/base.html | 14 +- .../wikmd/templates}/content.html | 2 +- {templates => src/wikmd/templates}/index.html | 2 +- .../wikmd/templates}/knowledge-graph.html | 2 +- .../wikmd/templates}/list_files.html | 2 +- {templates => src/wikmd/templates}/login.html | 2 +- {templates => src/wikmd/templates}/new.html | 6 +- .../wikmd/templates}/search.html | 4 +- utils.py => src/wikmd/utils.py | 0 .../wikmd/web_dependencies.py | 0 wiki.py => src/wikmd/wiki.py | 75 +++--- .../wikmd/wikmd-config.yaml | 0 tests/test_basics.py | 5 +- tests/test_plugins.py | 6 +- tests/test_search.py | 4 +- wiki/Features.md | 109 -------- wiki/How to use the wiki.md | 94 ------- wiki/Markdown cheatsheet.md | 243 ------------------ wiki/Using the version control system.md | 30 --- wiki/homepage.md | 42 --- 61 files changed, 102 insertions(+), 621 deletions(-) delete mode 100644 plugins/draw/drawings/.gitignore rename __init__.py => src/wikmd/__init__.py (100%) rename cache.py => src/wikmd/cache.py (100%) rename config.py => src/wikmd/config.py (99%) rename git_manager.py => src/wikmd/git_manager.py (97%) rename image_manager.py => src/wikmd/image_manager.py (99%) rename knowledge_graph.py => src/wikmd/knowledge_graph.py (98%) rename {plugins => src/wikmd/plugins}/__init__.py (100%) rename {plugins => src/wikmd/plugins}/alerts/__init__.py (100%) rename {plugins => src/wikmd/plugins}/alerts/alerts.py (97%) rename {plugins => src/wikmd/plugins}/draw/__init__.py (100%) rename {plugins => src/wikmd/plugins}/draw/default_draw (100%) rename {plugins => src/wikmd/plugins}/draw/draw.py (91%) rename {wiki/img => src/wikmd/plugins/draw/drawings}/.gitignore (100%) rename {plugins => src/wikmd/plugins}/embed-pages/__init__.py (100%) rename {plugins => src/wikmd/plugins}/embed-pages/embed-pages.py (96%) rename {plugins => src/wikmd/plugins}/load_plugins.py (80%) rename {plugins => src/wikmd/plugins}/mermaid/__init__.py (100%) rename {plugins => src/wikmd/plugins}/mermaid/mermaid.py (90%) rename search.py => src/wikmd/search.py (97%) rename {static => src/wikmd/static}/css/codemirror.custom.css (100%) rename {static => src/wikmd/static}/css/codemirror.custom.dark.css (100%) rename {static => src/wikmd/static}/css/filepond.dark.css (100%) rename {static => src/wikmd/static}/css/wiki.colors.css (100%) rename {static => src/wikmd/static}/css/wiki.css (100%) rename {static => src/wikmd/static}/css/wiki.dark.css (100%) rename {static => src/wikmd/static}/favicon.ico (100%) rename {static => src/wikmd/static}/images/contrast-2-fill.svg (100%) rename {static => src/wikmd/static}/images/file-copy-white.svg (100%) rename {static => src/wikmd/static}/images/file-copy.svg (100%) rename {static => src/wikmd/static}/images/graph_5.svg (100%) rename {static => src/wikmd/static}/images/knowledge-graph.png (100%) rename {static => src/wikmd/static}/images/readme-img.png (100%) rename {static => src/wikmd/static}/images/wiki.gif (100%) rename {static => src/wikmd/static}/images/wiki.png (100%) rename {static => src/wikmd/static}/images/wiki2.gif (100%) rename {static => src/wikmd/static}/js/.empty (100%) rename {static => src/wikmd/static}/js/copypaste.js (88%) rename {static => src/wikmd/static}/js/drawio.js (100%) rename {templates => src/wikmd/templates}/base.html (93%) rename {templates => src/wikmd/templates}/content.html (98%) rename {templates => src/wikmd/templates}/index.html (97%) rename {templates => src/wikmd/templates}/knowledge-graph.html (98%) rename {templates => src/wikmd/templates}/list_files.html (91%) rename {templates => src/wikmd/templates}/login.html (95%) rename {templates => src/wikmd/templates}/new.html (95%) rename {templates => src/wikmd/templates}/search.html (89%) rename utils.py => src/wikmd/utils.py (100%) rename web_dependencies.py => src/wikmd/web_dependencies.py (100%) rename wiki.py => src/wikmd/wiki.py (89%) rename wikmd-config.yaml => src/wikmd/wikmd-config.yaml (100%) delete mode 100644 wiki/Features.md delete mode 100644 wiki/How to use the wiki.md delete mode 100644 wiki/Markdown cheatsheet.md delete mode 100644 wiki/Using the version control system.md delete mode 100644 wiki/homepage.md diff --git a/.gitignore b/.gitignore index a793919..f116b63 100644 --- a/.gitignore +++ b/.gitignore @@ -97,14 +97,14 @@ dmypy.json cython_debug/ # Personal wiki pages -wiki/* -wiki/src/* - -!wiki/Features.md -!wiki/How to use the wiki.md -!wiki/Markdown cheatsheet.md -!wiki/Using the version control system.md -!wiki/homepage.md -!wiki/src +/wiki/* + + +!src/wiki/Features.md +!src/wiki/How to use the wiki.md +!src/wiki/Markdown cheatsheet.md +!src/wiki/Using the version control system.md +!src/wiki/homepage.md +!src/wiki/src temp/* diff --git a/README.md b/README.md index fc58c08..bd9ec81 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ It’s a file-based wiki that aims to simplicity. Instead of storing the data in To view the documents in the browser, the document is converted to html. -![preview](static/images/readme-img.png) +![preview](src/wikmd/static/images/readme-img.png) ## Features diff --git a/plugins/draw/drawings/.gitignore b/plugins/draw/drawings/.gitignore deleted file mode 100644 index f59ec20..0000000 --- a/plugins/draw/drawings/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* \ No newline at end of file diff --git a/__init__.py b/src/wikmd/__init__.py similarity index 100% rename from __init__.py rename to src/wikmd/__init__.py diff --git a/cache.py b/src/wikmd/cache.py similarity index 100% rename from cache.py rename to src/wikmd/cache.py diff --git a/config.py b/src/wikmd/config.py similarity index 99% rename from config.py rename to src/wikmd/config.py index 83b4363..0d50e53 100644 --- a/config.py +++ b/src/wikmd/config.py @@ -1,4 +1,5 @@ import os + import yaml WIKMD_CONFIG_FILE = "wikmd-config.yaml" diff --git a/git_manager.py b/src/wikmd/git_manager.py similarity index 97% rename from git_manager.py rename to src/wikmd/git_manager.py index 2590e27..6c5488a 100644 --- a/git_manager.py +++ b/src/wikmd/git_manager.py @@ -1,13 +1,11 @@ -import os import datetime - +import os from typing import Optional -from flask import Flask -from git import Repo, InvalidGitRepositoryError, GitCommandError, NoSuchPathError - -from config import WikmdConfig -from utils import move_all_files +from flask import Flask +from git import GitCommandError, InvalidGitRepositoryError, NoSuchPathError, Repo +from wikmd.config import WikmdConfig +from wikmd.utils import move_all_files TEMP_DIR = "temp" diff --git a/image_manager.py b/src/wikmd/image_manager.py similarity index 99% rename from image_manager.py rename to src/wikmd/image_manager.py index 10aa385..c00df30 100644 --- a/image_manager.py +++ b/src/wikmd/image_manager.py @@ -5,7 +5,7 @@ from base64 import b32encode from hashlib import sha1 -from werkzeug.utils import secure_filename, safe_join +from werkzeug.utils import safe_join, secure_filename class ImageManager: diff --git a/knowledge_graph.py b/src/wikmd/knowledge_graph.py similarity index 98% rename from knowledge_graph.py rename to src/wikmd/knowledge_graph.py index af24e1d..4b6d9ce 100644 --- a/knowledge_graph.py +++ b/src/wikmd/knowledge_graph.py @@ -2,7 +2,7 @@ import re from urllib.parse import unquote -from config import WikmdConfig +from wikmd.config import WikmdConfig cfg = WikmdConfig() diff --git a/plugins/__init__.py b/src/wikmd/plugins/__init__.py similarity index 100% rename from plugins/__init__.py rename to src/wikmd/plugins/__init__.py diff --git a/plugins/alerts/__init__.py b/src/wikmd/plugins/alerts/__init__.py similarity index 100% rename from plugins/alerts/__init__.py rename to src/wikmd/plugins/alerts/__init__.py diff --git a/plugins/alerts/alerts.py b/src/wikmd/plugins/alerts/alerts.py similarity index 97% rename from plugins/alerts/alerts.py rename to src/wikmd/plugins/alerts/alerts.py index b978503..0cbfff4 100644 --- a/plugins/alerts/alerts.py +++ b/src/wikmd/plugins/alerts/alerts.py @@ -1,9 +1,9 @@ -import uuid import os import re -import shutil + from flask import Flask -from config import WikmdConfig +from wikmd.config import WikmdConfig + class Plugin: def __init__(self, flask_app: Flask, config: WikmdConfig, web_dep ): diff --git a/plugins/draw/__init__.py b/src/wikmd/plugins/draw/__init__.py similarity index 100% rename from plugins/draw/__init__.py rename to src/wikmd/plugins/draw/__init__.py diff --git a/plugins/draw/default_draw b/src/wikmd/plugins/draw/default_draw similarity index 100% rename from plugins/draw/default_draw rename to src/wikmd/plugins/draw/default_draw diff --git a/plugins/draw/draw.py b/src/wikmd/plugins/draw/draw.py similarity index 91% rename from plugins/draw/draw.py rename to src/wikmd/plugins/draw/draw.py index 49b8372..b2e6f1d 100644 --- a/plugins/draw/draw.py +++ b/src/wikmd/plugins/draw/draw.py @@ -1,9 +1,11 @@ -import uuid import os import re import shutil +import uuid + from flask import Flask -from config import WikmdConfig +from wikmd.config import WikmdConfig + class Plugin: def import_head(self): @@ -45,7 +47,7 @@ def communicate_plugin(self, request): self.flask_app.logger.info(f"Plug/{self.name} - changing drawing {id}") # look for folder - location = os.path.join(os.path.dirname(__file__),"drawings", id) + location = os.path.join(os.path.dirname(__file__), "drawings", id) if os.path.exists(location): file = open(location, "w") file.write(image) @@ -58,7 +60,7 @@ def look_for_existing_drawid(self, drawid: str) -> str: look for a drawId in the wiki/draw folder and return the file as a string """ try: - file = open(os.path.join(self.this_location,"drawings",drawid),"r") + file = open(os.path.join(self.this_location, "drawings", drawid), "r") return file.read() except Exception: print("Did not find the file") @@ -68,7 +70,7 @@ def create_draw_file(self, filename: str) -> None: """ Copy the default drawing to a new one with this filename """ - path_to_file = os.path.join(self.this_location,"drawings",filename) + path_to_file = os.path.join(self.this_location, "drawings", filename) shutil.copyfile(os.path.join(self.this_location, "default_draw"), path_to_file) s = open(path_to_file,"r") result = re.sub("id=\"\"","id=\"" + filename + "\"",s.read()) diff --git a/wiki/img/.gitignore b/src/wikmd/plugins/draw/drawings/.gitignore similarity index 100% rename from wiki/img/.gitignore rename to src/wikmd/plugins/draw/drawings/.gitignore diff --git a/plugins/embed-pages/__init__.py b/src/wikmd/plugins/embed-pages/__init__.py similarity index 100% rename from plugins/embed-pages/__init__.py rename to src/wikmd/plugins/embed-pages/__init__.py diff --git a/plugins/embed-pages/embed-pages.py b/src/wikmd/plugins/embed-pages/embed-pages.py similarity index 96% rename from plugins/embed-pages/embed-pages.py rename to src/wikmd/plugins/embed-pages/embed-pages.py index b4e2ae0..3af63a5 100644 --- a/plugins/embed-pages/embed-pages.py +++ b/src/wikmd/plugins/embed-pages/embed-pages.py @@ -1,9 +1,9 @@ -import uuid import os import re -import shutil + from flask import Flask -from config import WikmdConfig +from wikmd.config import WikmdConfig + class Plugin: def __init__(self, flask_app: Flask, config: WikmdConfig, web_dep): diff --git a/plugins/load_plugins.py b/src/wikmd/plugins/load_plugins.py similarity index 80% rename from plugins/load_plugins.py rename to src/wikmd/plugins/load_plugins.py index a8376d7..80ac3bd 100644 --- a/plugins/load_plugins.py +++ b/src/wikmd/plugins/load_plugins.py @@ -1,6 +1,7 @@ import importlib + from flask import Flask -from config import WikmdConfig +from wikmd.config import WikmdConfig class PluginLoader(): @@ -14,7 +15,7 @@ def __init__(self, flask_app: Flask, config: WikmdConfig, web_deps= None, plugin if plugins != []: # create a list of plugins self._plugins = [ - importlib.import_module(f"plugins.{plugin}.{plugin}",".").Plugin(flask_app, config, web_deps) for plugin in plugins + importlib.import_module(f"wikmd.plugins.{plugin}.{plugin}",".").Plugin(flask_app, config, web_deps) for plugin in plugins ] else: self._plugins = [] diff --git a/plugins/mermaid/__init__.py b/src/wikmd/plugins/mermaid/__init__.py similarity index 100% rename from plugins/mermaid/__init__.py rename to src/wikmd/plugins/mermaid/__init__.py diff --git a/plugins/mermaid/mermaid.py b/src/wikmd/plugins/mermaid/mermaid.py similarity index 90% rename from plugins/mermaid/mermaid.py rename to src/wikmd/plugins/mermaid/mermaid.py index cf82130..f92dd91 100644 --- a/plugins/mermaid/mermaid.py +++ b/src/wikmd/plugins/mermaid/mermaid.py @@ -1,10 +1,6 @@ -import uuid import os -import re -import shutil from flask import Flask -from config import WikmdConfig -from web_dependencies import WEB_DEPENDENCIES +from wikmd.config import WikmdConfig injected_script = """ - + {% endblock %} diff --git a/templates/index.html b/src/wikmd/templates/index.html similarity index 97% rename from templates/index.html rename to src/wikmd/templates/index.html index 0f64059..6004e7f 100644 --- a/templates/index.html +++ b/src/wikmd/templates/index.html @@ -1,4 +1,4 @@ -{% extends 'base.html'%} +{% extends 'base.html' %} {%block content%} diff --git a/templates/knowledge-graph.html b/src/wikmd/templates/knowledge-graph.html similarity index 98% rename from templates/knowledge-graph.html rename to src/wikmd/templates/knowledge-graph.html index c55e8ef..3e1aca2 100644 --- a/templates/knowledge-graph.html +++ b/src/wikmd/templates/knowledge-graph.html @@ -1,4 +1,4 @@ -{% extends 'base.html'%} +{% extends 'base.html' %} {%block head%} diff --git a/templates/list_files.html b/src/wikmd/templates/list_files.html similarity index 91% rename from templates/list_files.html rename to src/wikmd/templates/list_files.html index 4c541b5..d26d899 100644 --- a/templates/list_files.html +++ b/src/wikmd/templates/list_files.html @@ -4,7 +4,7 @@ Sort ({% if system.listsortMTime %}last modified{% else %}a-z{% endif%})

{{ folder }} ALL FILES