♻️ 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:
1 parent
c6e1ed5f73
commit
884f2008f4
7 files changed
+20
-26
No files matched your search
@@ -7,4 +7,6 @@ include versioneer.py
|
||||
include src/octoprint/_version.py
|
||||
include requirements.txt
|
||||
include *.md
|
||||
exclude CODE_OF_CONDUCT.md
|
||||
exclude SECURITY.md
|
||||
exclude CONTRIBUTING.md
|
||||
@@ -25,7 +25,7 @@ import octoprint_setuptools # noqa: F401,E402
|
||||
PYTHON_REQUIRES = ">=3.7, <4"
|
||||
|
||||
# Requirements for setup.py
|
||||
SETUP_REQUIRES = ["markdown>=3.2.2,<4"]
|
||||
SETUP_REQUIRES = []
|
||||
|
||||
# Requirements for our application
|
||||
bundled_plugins = [
|
||||
@@ -117,13 +117,15 @@ def read_file_contents(path):
|
||||
return f.read()
|
||||
|
||||
|
||||
def md_to_html_build_py_factory(files, baseclass):
|
||||
class md_to_html_build_py(baseclass):
|
||||
def copy_files_build_py_factory(files, baseclass):
|
||||
class copy_files_build_py(baseclass):
|
||||
files = {}
|
||||
|
||||
def run(self):
|
||||
print("RUNNING md_to_html_build_py")
|
||||
print("RUNNING copy_files_build_py")
|
||||
if not self.dry_run:
|
||||
import shutil
|
||||
|
||||
for directory, files in self.files.items():
|
||||
target_dir = os.path.join(self.build_lib, directory)
|
||||
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])
|
||||
else:
|
||||
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)
|
||||
|
||||
return type(md_to_html_build_py)(
|
||||
md_to_html_build_py.__name__, (md_to_html_build_py,), {"files": files}
|
||||
return type(copy_files_build_py)(
|
||||
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": [
|
||||
"AUTHORS.md",
|
||||
|
||||
@@ -1555,18 +1555,10 @@ class Server:
|
||||
|
||||
loaders = [app.jinja_loader, app.jinja_env.prefix_loader]
|
||||
if octoprint.util.is_running_from_source():
|
||||
from markdown import markdown
|
||||
|
||||
root = os.path.abspath(os.path.join(os.path.dirname(__file__), "../../.."))
|
||||
allowed = ["AUTHORS.md", "SUPPORTERS.md", "THIRDPARTYLICENSES.md"]
|
||||
files = {
|
||||
"_data/" + name + ".html": os.path.join(root, name) for name in allowed
|
||||
}
|
||||
loaders.append(
|
||||
octoprint.util.jinja.SelectedFilesWithConversionLoader(
|
||||
files, conversion=markdown
|
||||
)
|
||||
)
|
||||
files = {"_data/" + name: os.path.join(root, name) for name in allowed}
|
||||
loaders.append(octoprint.util.jinja.SelectedFilesWithConversionLoader(files))
|
||||
|
||||
# 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."
|
||||
|
||||
@@ -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 %}
|
||||
@@ -289,8 +289,8 @@ class MarkdownFilter:
|
||||
app.jinja_env.filters.setdefault("markdown", self)
|
||||
|
||||
def __call__(self, stream):
|
||||
from jinja2 import Markup
|
||||
from markdown import Markdown
|
||||
from markupsafe import Markup
|
||||
|
||||
# Markdown is not thread safe
|
||||
markdown = Markdown(**self._markdown_options)
|
||||
|
||||
Reference in new issue
Block a user