diff --git a/src/sinol_make/__init__.py b/src/sinol_make/__init__.py index 03337790..7b8d0316 100644 --- a/src/sinol_make/__init__.py +++ b/src/sinol_make/__init__.py @@ -9,7 +9,7 @@ from sinol_make import util, oiejq -__version__ = "1.5.11" +__version__ = "1.5.12" def configure_parsers(): diff --git a/src/sinol_make/commands/doc/__init__.py b/src/sinol_make/commands/doc/__init__.py index d6fd78fc..b8309115 100644 --- a/src/sinol_make/commands/doc/__init__.py +++ b/src/sinol_make/commands/doc/__init__.py @@ -4,6 +4,7 @@ import subprocess from sinol_make import util +from sinol_make.helpers import paths from sinol_make.interfaces.BaseCommand import BaseCommand @@ -11,6 +12,7 @@ class Command(BaseCommand): """ Class for `doc` command. """ + LOG_PATTERNS = ['*~', '*.aux', '*.log', '*.dvi', '*.err', '*.inf'] def get_name(self): return "doc" @@ -32,6 +34,14 @@ def compile_file(self, file_path): print(util.info(f'Compilation successful for file {os.path.basename(file_path)}.')) return True + def move_logs(self): + output_dir = paths.get_cache_path('doc_logs') + os.makedirs(output_dir, exist_ok=True) + for pattern in self.LOG_PATTERNS: + for file in glob.glob(os.path.join(os.getcwd(), 'doc', pattern)): + os.rename(file, os.path.join(output_dir, os.path.basename(file))) + print(util.info(f'Compilation log files can be found in {os.path.relpath(output_dir, os.getcwd())}')) + def configure_subparser(self, subparser: argparse.ArgumentParser): parser = subparser.add_parser( self.get_name(), @@ -63,6 +73,7 @@ def run(self, args: argparse.Namespace): failed.append(file) os.chdir(original_cwd) + self.move_logs() if failed: for failed_file in failed: print(util.error(f'Failed to compile {failed_file}')) diff --git a/tests/commands/doc/test_integration.py b/tests/commands/doc/test_integration.py index 5ef28e16..e3e9d2e5 100644 --- a/tests/commands/doc/test_integration.py +++ b/tests/commands/doc/test_integration.py @@ -1,7 +1,10 @@ +import os +import glob import pytest from sinol_make import configure_parsers from sinol_make.commands.doc import Command +from sinol_make.helpers import paths from tests.fixtures import create_package from tests import util @@ -18,6 +21,9 @@ def test_simple(capsys, create_package): out = capsys.readouterr().out assert "Compilation was successful for all files." in out + for pattern in command.LOG_PATTERNS: + assert glob.glob(os.path.join(os.getcwd(), 'doc', pattern)) == [] + @pytest.mark.parametrize("create_package", [util.get_doc_package_path()], indirect=True) def test_argument(capsys, create_package): @@ -30,3 +36,10 @@ def test_argument(capsys, create_package): command.run(args) out = capsys.readouterr().out assert "Compilation was successful for all files." in out + + logs_exist = False + logs_dir = paths.get_cache_path('doc_logs') + for pattern in command.LOG_PATTERNS: + assert glob.glob(os.path.join(os.getcwd(), 'doc', pattern)) == [] + logs_exist = logs_exist | (glob.glob(os.path.join(logs_dir, pattern)) != []) + assert logs_exist