From 96f2db33d2a78c52c09452686a5c483495b2df33 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 5 Oct 2023 16:38:15 +0200 Subject: [PATCH 1/5] Remove compilation logs in `doc` command --- src/sinol_make/commands/doc/__init__.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/sinol_make/commands/doc/__init__.py b/src/sinol_make/commands/doc/__init__.py index d6fd78fc..8d149c61 100644 --- a/src/sinol_make/commands/doc/__init__.py +++ b/src/sinol_make/commands/doc/__init__.py @@ -11,6 +11,7 @@ class Command(BaseCommand): """ Class for `doc` command. """ + LOG_PATTERNS = ['*~', '*.aux', '*.log', '*.dvi', '*.err', '*.inf'] def get_name(self): return "doc" @@ -32,6 +33,11 @@ def compile_file(self, file_path): print(util.info(f'Compilation successful for file {os.path.basename(file_path)}.')) return True + def delete_logs(self): + for pattern in self.LOG_PATTERNS: + for file in glob.glob(os.path.join(os.getcwd(), 'doc', pattern)): + os.remove(file) + def configure_subparser(self, subparser: argparse.ArgumentParser): parser = subparser.add_parser( self.get_name(), @@ -39,6 +45,7 @@ def configure_subparser(self, subparser: argparse.ArgumentParser): description='Compiles latex files to pdf. By default compiles all files in the `doc` directory.\n' 'You can also specify files to compile.') parser.add_argument('files', type=str, nargs='*', help='files to compile') + parser.add_argument('-l', '--logs', action='store_true', help="don't delete logs after compilation") def run(self, args: argparse.Namespace): util.exit_if_not_package() @@ -68,4 +75,6 @@ def run(self, args: argparse.Namespace): print(util.error(f'Failed to compile {failed_file}')) util.exit_with_error('Compilation failed.') else: + if not args.logs: + self.delete_logs() print(util.info('Compilation was successful for all files.')) From 7ff9150bacb1f7c909383fe416b2a5757bf704c1 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Thu, 5 Oct 2023 16:38:45 +0200 Subject: [PATCH 2/5] Add tests --- tests/commands/doc/test_integration.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/commands/doc/test_integration.py b/tests/commands/doc/test_integration.py index 5ef28e16..22fb0eb9 100644 --- a/tests/commands/doc/test_integration.py +++ b/tests/commands/doc/test_integration.py @@ -1,3 +1,5 @@ +import os +import glob import pytest from sinol_make import configure_parsers @@ -18,6 +20,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 +35,21 @@ def test_argument(capsys, create_package): command.run(args) 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_logs_flag(create_package): + """ + Test --logs flag. + """ + parser = configure_parsers() + args = parser.parse_args(["doc", "--logs"]) + command = Command() + command.run(args) + + for pattern in command.LOG_PATTERNS: + for file in glob.glob(os.path.join(os.getcwd(), 'doc', pattern)): + assert os.path.exists(file) From f9b945efbaa080f45ed5ac64dddcd8464c0c5310 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 9 Oct 2023 16:31:10 +0200 Subject: [PATCH 3/5] Move logs to .cache --- src/sinol_make/commands/doc/__init__.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/sinol_make/commands/doc/__init__.py b/src/sinol_make/commands/doc/__init__.py index 8d149c61..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 @@ -33,10 +34,13 @@ def compile_file(self, file_path): print(util.info(f'Compilation successful for file {os.path.basename(file_path)}.')) return True - def delete_logs(self): + 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.remove(file) + 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( @@ -45,7 +49,6 @@ def configure_subparser(self, subparser: argparse.ArgumentParser): description='Compiles latex files to pdf. By default compiles all files in the `doc` directory.\n' 'You can also specify files to compile.') parser.add_argument('files', type=str, nargs='*', help='files to compile') - parser.add_argument('-l', '--logs', action='store_true', help="don't delete logs after compilation") def run(self, args: argparse.Namespace): util.exit_if_not_package() @@ -70,11 +73,10 @@ 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}')) util.exit_with_error('Compilation failed.') else: - if not args.logs: - self.delete_logs() print(util.info('Compilation was successful for all files.')) From 4368b63daa5677cbc6b9a2af311df5c42271a097 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 9 Oct 2023 16:31:16 +0200 Subject: [PATCH 4/5] Change tests --- tests/commands/doc/test_integration.py | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/commands/doc/test_integration.py b/tests/commands/doc/test_integration.py index 22fb0eb9..e3e9d2e5 100644 --- a/tests/commands/doc/test_integration.py +++ b/tests/commands/doc/test_integration.py @@ -4,6 +4,7 @@ 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 @@ -36,20 +37,9 @@ def test_argument(capsys, create_package): 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)) == [] - - -@pytest.mark.parametrize("create_package", [util.get_doc_package_path()], indirect=True) -def test_logs_flag(create_package): - """ - Test --logs flag. - """ - parser = configure_parsers() - args = parser.parse_args(["doc", "--logs"]) - command = Command() - command.run(args) - - for pattern in command.LOG_PATTERNS: - for file in glob.glob(os.path.join(os.getcwd(), 'doc', pattern)): - assert os.path.exists(file) + logs_exist = logs_exist | (glob.glob(os.path.join(logs_dir, pattern)) != []) + assert logs_exist From 08cbd90d48de9012b8c05f639b8b3e41fc275a32 Mon Sep 17 00:00:00 2001 From: Mateusz Masiarz Date: Mon, 9 Oct 2023 19:11:09 +0200 Subject: [PATCH 5/5] Bump version --- src/sinol_make/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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():