♻️ Get rid of build-time dep on markdown

We need to process markdown stuff in OctoPrint
now anyhow, might as well just convert
the files previously converted during build on
the go.

That also makes it easier to keep setup.py
Py2 compatible.
This commit is contained in:
Gina Häußge committed 2022-02-01 18:55:51 +01:00
1 parent c6e1ed5f73
commit 884f2008f4
7 files changed
+20 -26

No files matched your search

+2
View File
@@ -7,4 +7,6 @@ include versioneer.py
include src/octoprint/_version.py include src/octoprint/_version.py
include requirements.txt include requirements.txt
include *.md include *.md
exclude CODE_OF_CONDUCT.md
exclude SECURITY.md
exclude CONTRIBUTING.md exclude CONTRIBUTING.md
+12 -12
View File
@@ -25,7 +25,7 @@ import octoprint_setuptools # noqa: F401,E402
PYTHON_REQUIRES = ">=3.7, <4" PYTHON_REQUIRES = ">=3.7, <4"
# Requirements for setup.py # Requirements for setup.py
SETUP_REQUIRES = ["markdown>=3.2.2,<4"] SETUP_REQUIRES = []
# Requirements for our application # Requirements for our application
bundled_plugins = [ bundled_plugins = [
@@ -117,13 +117,15 @@ def read_file_contents(path):
return f.read() return f.read()
def md_to_html_build_py_factory(files, baseclass): def copy_files_build_py_factory(files, baseclass):
class md_to_html_build_py(baseclass): class copy_files_build_py(baseclass):
files = {} files = {}
def run(self): def run(self):
print("RUNNING md_to_html_build_py") print("RUNNING copy_files_build_py")
if not self.dry_run: if not self.dry_run:
import shutil
for directory, files in self.files.items(): for directory, files in self.files.items():
target_dir = os.path.join(self.build_lib, directory) target_dir = os.path.join(self.build_lib, directory)
self.mkpath(target_dir) self.mkpath(target_dir)
@@ -135,17 +137,15 @@ def md_to_html_build_py_factory(files, baseclass):
source, dest = entry[0], os.path.join(target_dir, entry[1]) source, dest = entry[0], os.path.join(target_dir, entry[1])
else: else:
source = entry source = entry
dest = os.path.join(target_dir, source + ".html") dest = os.path.join(target_dir, source)
print("Rendering markdown from {} to {}".format(source, dest)) print("Copying {} to {}".format(source, dest))
shutil.copy2(source, dest)
from markdown import markdownFromFile
markdownFromFile(input=source, output=dest, encoding="utf-8")
baseclass.run(self) baseclass.run(self)
return type(md_to_html_build_py)( return type(copy_files_build_py)(
md_to_html_build_py.__name__, (md_to_html_build_py,), {"files": files} copy_files_build_py.__name__, (copy_files_build_py,), {"files": files}
) )
@@ -178,7 +178,7 @@ def get_cmdclass():
) )
) )
cmdclass["build_py"] = md_to_html_build_py_factory( cmdclass["build_py"] = copy_files_build_py_factory(
{ {
"octoprint/templates/_data": [ "octoprint/templates/_data": [
"AUTHORS.md", "AUTHORS.md",
+2 -10
View File
@@ -1555,18 +1555,10 @@ class Server:
loaders = [app.jinja_loader, app.jinja_env.prefix_loader] loaders = [app.jinja_loader, app.jinja_env.prefix_loader]
if octoprint.util.is_running_from_source(): if octoprint.util.is_running_from_source():
from markdown import markdown
root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../..")) root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))
allowed = ["AUTHORS.md", "SUPPORTERS.md", "THIRDPARTYLICENSES.md"] allowed = ["AUTHORS.md", "SUPPORTERS.md", "THIRDPARTYLICENSES.md"]
files = { files = {"_data/" + name: os.path.join(root, name) for name in allowed}
"_data/" + name + ".html": os.path.join(root, name) for name in allowed loaders.append(octoprint.util.jinja.SelectedFilesWithConversionLoader(files))
}
loaders.append(
octoprint.util.jinja.SelectedFilesWithConversionLoader(
files, conversion=markdown
)
)
# TODO: Remove this in 2.0.0 # TODO: Remove this in 2.0.0
warning_message = "Loading plugin template '{template}' from '{filename}' without plugin prefix, this is deprecated and will soon no longer be supported." warning_message = "Loading plugin template '{template}' from '{filename}' without plugin prefix, this is deprecated and will soon no longer be supported."
@@ -1 +1 @@
{% filter externalize_links %}{% filter offset_html_headers(2) %}{% include "_data/AUTHORS.md.html" ignore missing %}{% endfilter %}{% endfilter %} {% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/AUTHORS.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
@@ -1 +1 @@
{% filter externalize_links %}{% filter offset_html_headers(2) %}{% include "_data/SUPPORTERS.md.html" ignore missing %}{% endfilter %}{% endfilter %} {% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/SUPPORTERS.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
@@ -1 +1 @@
{% filter externalize_links %}{% filter offset_html_headers(2) %}{% include "_data/THIRDPARTYLICENSES.md.html" ignore missing %}{% endfilter %}{% endfilter %} {% filter externalize_links %}{% filter markdown %}{% filter offset_markdown_headers(2) %}{% include "_data/THIRDPARTYLICENSES.md" ignore missing %}{% endfilter %}{% endfilter %}{% endfilter %}
+1 -1
View File
@@ -289,8 +289,8 @@ class MarkdownFilter:
app.jinja_env.filters.setdefault("markdown", self) app.jinja_env.filters.setdefault("markdown", self)
def __call__(self, stream): def __call__(self, stream):
from jinja2 import Markup
from markdown import Markdown from markdown import Markdown
from markupsafe import Markup
# Markdown is not thread safe # Markdown is not thread safe
markdown = Markdown(**self._markdown_options) markdown = Markdown(**self._markdown_options)