Compare commits
4 Commits
aa4d5a3585
...
60816dda3f
Author | SHA1 | Date | |
---|---|---|---|
60816dda3f | |||
7639e0738e | |||
46f8cdcc24 | |||
388eadd4a0 |
@ -12,6 +12,15 @@ from termcolor import cprint
|
||||
|
||||
from incorporealcms.config import Config
|
||||
|
||||
# dynamically generate version number
|
||||
try:
|
||||
# packaged/pip install -e . value
|
||||
from ._version import version as __version__
|
||||
except ImportError:
|
||||
# local clone value
|
||||
from setuptools_scm import get_version
|
||||
__version__ = get_version(root='..', relative_to=__file__)
|
||||
|
||||
|
||||
def init_instance(instance_path: str, extra_config: dict = None):
|
||||
"""Create the instance context, with allowances for customizing path and test settings."""
|
||||
|
@ -62,7 +62,7 @@ def parse_md(path: str):
|
||||
entry = input_file.read()
|
||||
logger.debug("path '%s' read", path)
|
||||
md = init_md()
|
||||
content = Markup(md.convert(entry))
|
||||
content = Markup(md.convert(entry)) # nosec B704
|
||||
except (OSError, FileNotFoundError):
|
||||
logger.exception("path '%s' could not be opened!", path)
|
||||
raise
|
||||
@ -131,7 +131,7 @@ def generate_parent_navs(path):
|
||||
try:
|
||||
with open(path, 'r') as entry_file:
|
||||
entry = entry_file.read()
|
||||
_ = Markup(md.convert(entry))
|
||||
_ = Markup(md.convert(entry)) # nosec B704
|
||||
page_name = (" ".join(md.Meta.get('title')) if md.Meta.get('title')
|
||||
else request_path_to_breadcrumb_display(request_path))
|
||||
return generate_parent_navs(parent_resource_path) + [(page_name, request_path)]
|
||||
|
@ -4,7 +4,7 @@ SPDX-FileCopyrightText: © 2022 Brian S. Stephan <bss@incorporeal.org>
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
import re
|
||||
from xml.etree.ElementTree import SubElement # nosec B405 - not parsing untrusted XML here
|
||||
from xml.etree.ElementTree import SubElement # nosec B405
|
||||
|
||||
import markdown
|
||||
|
||||
|
@ -11,14 +11,14 @@ import tempfile
|
||||
|
||||
from termcolor import cprint
|
||||
|
||||
from incorporealcms import init_instance
|
||||
from incorporealcms import __version__, init_instance
|
||||
from incorporealcms.markdown import handle_markdown_file_path
|
||||
|
||||
|
||||
class StaticSiteGenerator(object):
|
||||
"""Generate static site output based on the instance's content."""
|
||||
|
||||
def __init__(self, instance_dir: str, output_dir: str):
|
||||
def __init__(self, instance_dir: str, output_dir: str, extra_config=None):
|
||||
"""Create the object to run various operations to generate the static site.
|
||||
|
||||
Args:
|
||||
@ -32,7 +32,7 @@ class StaticSiteGenerator(object):
|
||||
output_dir = os.path.abspath(output_dir)
|
||||
|
||||
# initialize configuration with the path to the instance
|
||||
init_instance(instance_dir)
|
||||
init_instance(instance_dir, extra_config)
|
||||
|
||||
def build(self):
|
||||
"""Build the whole static site."""
|
||||
@ -176,6 +176,7 @@ def build():
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
cprint(f"incorporealcms-build v{__version__}", 'green')
|
||||
# check output path before doing work
|
||||
if not os.path.isdir(args.output_dir):
|
||||
# if it doesn't exist, great, we'll just move the temporary dir later;
|
||||
|
@ -43,7 +43,7 @@ click==8.1.8
|
||||
# typer
|
||||
colorama==0.4.6
|
||||
# via tox
|
||||
coverage[toml]==7.6.12
|
||||
coverage[toml]==7.7.0
|
||||
# via pytest-cov
|
||||
cryptography==44.0.2
|
||||
# via
|
||||
@ -112,7 +112,7 @@ jeepney==0.9.0
|
||||
# via
|
||||
# keyring
|
||||
# secretstorage
|
||||
jinja2==3.1.3
|
||||
jinja2==3.1.6
|
||||
# via
|
||||
# incorporeal-cms (pyproject.toml)
|
||||
# reuse
|
||||
@ -123,13 +123,13 @@ keyring==25.6.0
|
||||
# via twine
|
||||
license-expression==30.4.1
|
||||
# via reuse
|
||||
lxml==5.2.1
|
||||
lxml==5.3.1
|
||||
# via feedgen
|
||||
markdown==3.6
|
||||
markdown==3.7
|
||||
# via incorporeal-cms (pyproject.toml)
|
||||
markdown-it-py==3.0.0
|
||||
# via rich
|
||||
markupsafe==2.1.5
|
||||
markupsafe==3.0.2
|
||||
# via jinja2
|
||||
marshmallow==3.26.1
|
||||
# via safety
|
||||
@ -252,7 +252,7 @@ setuptools-scm==8.2.0
|
||||
# via incorporeal-cms (pyproject.toml)
|
||||
shellingham==1.5.4
|
||||
# via typer
|
||||
six==1.16.0
|
||||
six==1.17.0
|
||||
# via python-dateutil
|
||||
snowballstemmer==2.2.0
|
||||
# via pydocstyle
|
||||
|
@ -6,17 +6,17 @@
|
||||
#
|
||||
feedgen==1.0.0
|
||||
# via incorporeal-cms (pyproject.toml)
|
||||
jinja2==3.1.3
|
||||
jinja2==3.1.6
|
||||
# via incorporeal-cms (pyproject.toml)
|
||||
lxml==5.2.1
|
||||
lxml==5.3.1
|
||||
# via feedgen
|
||||
markdown==3.6
|
||||
markdown==3.7
|
||||
# via incorporeal-cms (pyproject.toml)
|
||||
markupsafe==2.1.5
|
||||
markupsafe==3.0.2
|
||||
# via jinja2
|
||||
python-dateutil==2.9.0.post0
|
||||
# via feedgen
|
||||
six==1.16.0
|
||||
six==1.17.0
|
||||
# via python-dateutil
|
||||
termcolor==2.5.0
|
||||
# via incorporeal-cms (pyproject.toml)
|
||||
|
@ -37,10 +37,10 @@ def test_invalid_graphviz_is_not_rendered():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
ssg = StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(src_dir, 'pages'))
|
||||
os.chdir(os.path.join(src_dir, 'broken'))
|
||||
|
||||
with pytest.raises(ValueError):
|
||||
ssg.build_file_in_destination(os.path.join(HERE, 'instance', 'pages'), '', 'test-invalid-graphviz.md',
|
||||
ssg.build_file_in_destination(os.path.join(HERE, 'instance', 'broken'), '', 'test-invalid-graphviz.md',
|
||||
tmpdir, True)
|
||||
os.chdir(HERE)
|
||||
|
||||
|
30
tests/test_commands.py
Normal file
30
tests/test_commands.py
Normal file
@ -0,0 +1,30 @@
|
||||
"""Test command line invocations.
|
||||
|
||||
SPDX-FileCopyrightText: © 2023 Brian S. Stephan <bss@incorporeal.org>
|
||||
SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
"""
|
||||
import os
|
||||
import tempfile
|
||||
from subprocess import run
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
||||
def test_build():
|
||||
"""Test some of the output of the core builder command."""
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
result = run(['incorporealcms-build', os.path.join(HERE, 'instance'), tmpdir],
|
||||
capture_output=True, encoding='utf8')
|
||||
assert "creating temporary directory" in result.stdout
|
||||
assert "copying file" in result.stdout
|
||||
assert "creating symlink" in result.stdout
|
||||
assert "creating directory" in result.stdout
|
||||
assert "renaming" in result.stdout
|
||||
|
||||
|
||||
def test_build_error():
|
||||
"""Test some of the output of the core builder command."""
|
||||
result = run(['incorporealcms-build', os.path.join(HERE, 'instance'), os.path.join(HERE, 'test_markdown.py')],
|
||||
capture_output=True, encoding='utf8')
|
||||
assert "specified output path" in result.stderr
|
||||
assert "exists as a file!" in result.stderr
|
Loading…
x
Reference in New Issue
Block a user