remove os.chdir usage, rely on absolute and relative paths more
os.chdir was getting confusing and hurting the log output, and potentially the cause of a couple bugs left to fix, so this removes it, but it means we need to pass around the pages/ absolute path into the markdown parser, because it relies on knowing both the absolute path now (to open files), and also the path relative to the pages dir in order to know where to stop reading parent files/how to generate proper URL-like references to other files. probably this should be refactored at some point to inherit the pages/ path from the SSG somehow, rather than passing it through a bunch of methods, but this seems to work for now fixes #22 Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
SPDX-FileCopyrightText: © 2025 Brian S. Stephan <bss@incorporeal.org>
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
|
||||
import incorporealcms.ssg as ssg
|
||||
from incorporealcms import init_instance
|
||||
|
||||
logger = logging.getLogger(__file__)
|
||||
|
||||
HERE = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
instance_dir = os.path.join(HERE, 'instance')
|
||||
@@ -20,7 +23,6 @@ def test_file_copy():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'no-title.md', tmpdir,
|
||||
True)
|
||||
assert os.path.exists(os.path.join(tmpdir, 'no-title.md'))
|
||||
@@ -32,7 +34,6 @@ def test_file_copy_no_markdown():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'no-title.md', tmpdir,
|
||||
False)
|
||||
assert os.path.exists(os.path.join(tmpdir, 'no-title.md'))
|
||||
@@ -44,7 +45,6 @@ def test_file_copy_symlink():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'symlink-to-foo.txt', tmpdir)
|
||||
# need to copy the destination for os.path.exists to be happy with this
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'foo.txt', tmpdir)
|
||||
@@ -57,7 +57,6 @@ def test_file_copy_symlink_of_markdown_also_has_html_symlink():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_file_in_destination(os.path.join(instance_dir, 'pages'), '', 'symlink-to-no-title.md', tmpdir,
|
||||
True)
|
||||
# need to copy the destination for os.path.exists to be happy with this
|
||||
@@ -74,7 +73,6 @@ def test_dir_copy():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_subdir_in_destination(os.path.join(instance_dir, 'pages'), '', 'media', tmpdir)
|
||||
assert os.path.exists(os.path.join(tmpdir, 'media'))
|
||||
assert os.path.isdir(os.path.join(tmpdir, 'media'))
|
||||
@@ -85,7 +83,6 @@ def test_dir_copy_symlink():
|
||||
with tempfile.TemporaryDirectory() as tmpdir:
|
||||
src_dir = os.path.join(HERE, 'instance')
|
||||
generator = ssg.StaticSiteGenerator(src_dir, tmpdir)
|
||||
os.chdir(os.path.join(instance_dir, 'pages'))
|
||||
generator.build_subdir_in_destination(os.path.join(instance_dir, 'pages'), '', 'symlink-to-subdir', tmpdir)
|
||||
# need to copy the destination for os.path.exists to be happy with this
|
||||
generator.build_subdir_in_destination(os.path.join(instance_dir, 'pages'), '', 'subdir', tmpdir)
|
||||
|
||||
Reference in New Issue
Block a user