Compare commits

...

4 Commits

Author SHA1 Message Date
60816dda3f
wrap up conversion to SSG
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-03-16 21:49:56 -05:00
7639e0738e
make bandit happy
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-03-16 21:27:24 -05:00
46f8cdcc24
test the build command
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-03-16 21:15:34 -05:00
388eadd4a0
fix some tests
Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
2025-03-16 20:39:27 -05:00
10 changed files with 59 additions and 22 deletions

View File

@ -12,6 +12,15 @@ from termcolor import cprint
from incorporealcms.config import Config 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): def init_instance(instance_path: str, extra_config: dict = None):
"""Create the instance context, with allowances for customizing path and test settings.""" """Create the instance context, with allowances for customizing path and test settings."""

View File

@ -62,7 +62,7 @@ def parse_md(path: str):
entry = input_file.read() entry = input_file.read()
logger.debug("path '%s' read", path) logger.debug("path '%s' read", path)
md = init_md() md = init_md()
content = Markup(md.convert(entry)) content = Markup(md.convert(entry)) # nosec B704
except (OSError, FileNotFoundError): except (OSError, FileNotFoundError):
logger.exception("path '%s' could not be opened!", path) logger.exception("path '%s' could not be opened!", path)
raise raise
@ -131,7 +131,7 @@ def generate_parent_navs(path):
try: try:
with open(path, 'r') as entry_file: with open(path, 'r') as entry_file:
entry = entry_file.read() 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') page_name = (" ".join(md.Meta.get('title')) if md.Meta.get('title')
else request_path_to_breadcrumb_display(request_path)) else request_path_to_breadcrumb_display(request_path))
return generate_parent_navs(parent_resource_path) + [(page_name, request_path)] return generate_parent_navs(parent_resource_path) + [(page_name, request_path)]

View File

@ -4,7 +4,7 @@ SPDX-FileCopyrightText: © 2022 Brian S. Stephan <bss@incorporeal.org>
SPDX-License-Identifier: AGPL-3.0-or-later SPDX-License-Identifier: AGPL-3.0-or-later
""" """
import re 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 import markdown

View File

@ -11,14 +11,14 @@ import tempfile
from termcolor import cprint from termcolor import cprint
from incorporealcms import init_instance from incorporealcms import __version__, init_instance
from incorporealcms.markdown import handle_markdown_file_path from incorporealcms.markdown import handle_markdown_file_path
class StaticSiteGenerator(object): class StaticSiteGenerator(object):
"""Generate static site output based on the instance's content.""" """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. """Create the object to run various operations to generate the static site.
Args: Args:
@ -32,7 +32,7 @@ class StaticSiteGenerator(object):
output_dir = os.path.abspath(output_dir) output_dir = os.path.abspath(output_dir)
# initialize configuration with the path to the instance # initialize configuration with the path to the instance
init_instance(instance_dir) init_instance(instance_dir, extra_config)
def build(self): def build(self):
"""Build the whole static site.""" """Build the whole static site."""
@ -176,6 +176,7 @@ def build():
) )
args = parser.parse_args() args = parser.parse_args()
cprint(f"incorporealcms-build v{__version__}", 'green')
# check output path before doing work # check output path before doing work
if not os.path.isdir(args.output_dir): if not os.path.isdir(args.output_dir):
# if it doesn't exist, great, we'll just move the temporary dir later; # if it doesn't exist, great, we'll just move the temporary dir later;

View File

@ -43,7 +43,7 @@ click==8.1.8
# typer # typer
colorama==0.4.6 colorama==0.4.6
# via tox # via tox
coverage[toml]==7.6.12 coverage[toml]==7.7.0
# via pytest-cov # via pytest-cov
cryptography==44.0.2 cryptography==44.0.2
# via # via
@ -112,7 +112,7 @@ jeepney==0.9.0
# via # via
# keyring # keyring
# secretstorage # secretstorage
jinja2==3.1.3 jinja2==3.1.6
# via # via
# incorporeal-cms (pyproject.toml) # incorporeal-cms (pyproject.toml)
# reuse # reuse
@ -123,13 +123,13 @@ keyring==25.6.0
# via twine # via twine
license-expression==30.4.1 license-expression==30.4.1
# via reuse # via reuse
lxml==5.2.1 lxml==5.3.1
# via feedgen # via feedgen
markdown==3.6 markdown==3.7
# via incorporeal-cms (pyproject.toml) # via incorporeal-cms (pyproject.toml)
markdown-it-py==3.0.0 markdown-it-py==3.0.0
# via rich # via rich
markupsafe==2.1.5 markupsafe==3.0.2
# via jinja2 # via jinja2
marshmallow==3.26.1 marshmallow==3.26.1
# via safety # via safety
@ -252,7 +252,7 @@ setuptools-scm==8.2.0
# via incorporeal-cms (pyproject.toml) # via incorporeal-cms (pyproject.toml)
shellingham==1.5.4 shellingham==1.5.4
# via typer # via typer
six==1.16.0 six==1.17.0
# via python-dateutil # via python-dateutil
snowballstemmer==2.2.0 snowballstemmer==2.2.0
# via pydocstyle # via pydocstyle

View File

@ -6,17 +6,17 @@
# #
feedgen==1.0.0 feedgen==1.0.0
# via incorporeal-cms (pyproject.toml) # via incorporeal-cms (pyproject.toml)
jinja2==3.1.3 jinja2==3.1.6
# via incorporeal-cms (pyproject.toml) # via incorporeal-cms (pyproject.toml)
lxml==5.2.1 lxml==5.3.1
# via feedgen # via feedgen
markdown==3.6 markdown==3.7
# via incorporeal-cms (pyproject.toml) # via incorporeal-cms (pyproject.toml)
markupsafe==2.1.5 markupsafe==3.0.2
# via jinja2 # via jinja2
python-dateutil==2.9.0.post0 python-dateutil==2.9.0.post0
# via feedgen # via feedgen
six==1.16.0 six==1.17.0
# via python-dateutil # via python-dateutil
termcolor==2.5.0 termcolor==2.5.0
# via incorporeal-cms (pyproject.toml) # via incorporeal-cms (pyproject.toml)

View File

@ -37,10 +37,10 @@ def test_invalid_graphviz_is_not_rendered():
with tempfile.TemporaryDirectory() as tmpdir: with tempfile.TemporaryDirectory() as tmpdir:
src_dir = os.path.join(HERE, 'instance') src_dir = os.path.join(HERE, 'instance')
ssg = StaticSiteGenerator(src_dir, tmpdir) 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): 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) tmpdir, True)
os.chdir(HERE) os.chdir(HERE)

30
tests/test_commands.py Normal file
View 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

View File

@ -74,6 +74,3 @@ source =
[coverage:run] [coverage:run]
branch = True branch = True
omit =
**/_version.py