Skip to content

Commit 057ed32

Browse files
authored
After running sinol-make doc remove log files (#140)
* Remove compilation logs in `doc` command * Add tests * Move logs to .cache * Change tests * Bump version
1 parent 4ef4c37 commit 057ed32

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/sinol_make/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from sinol_make import util, oiejq
1010

1111

12-
__version__ = "1.5.11"
12+
__version__ = "1.5.12"
1313

1414

1515
def configure_parsers():

src/sinol_make/commands/doc/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
import subprocess
55

66
from sinol_make import util
7+
from sinol_make.helpers import paths
78
from sinol_make.interfaces.BaseCommand import BaseCommand
89

910

1011
class Command(BaseCommand):
1112
"""
1213
Class for `doc` command.
1314
"""
15+
LOG_PATTERNS = ['*~', '*.aux', '*.log', '*.dvi', '*.err', '*.inf']
1416

1517
def get_name(self):
1618
return "doc"
@@ -32,6 +34,14 @@ def compile_file(self, file_path):
3234
print(util.info(f'Compilation successful for file {os.path.basename(file_path)}.'))
3335
return True
3436

37+
def move_logs(self):
38+
output_dir = paths.get_cache_path('doc_logs')
39+
os.makedirs(output_dir, exist_ok=True)
40+
for pattern in self.LOG_PATTERNS:
41+
for file in glob.glob(os.path.join(os.getcwd(), 'doc', pattern)):
42+
os.rename(file, os.path.join(output_dir, os.path.basename(file)))
43+
print(util.info(f'Compilation log files can be found in {os.path.relpath(output_dir, os.getcwd())}'))
44+
3545
def configure_subparser(self, subparser: argparse.ArgumentParser):
3646
parser = subparser.add_parser(
3747
self.get_name(),
@@ -63,6 +73,7 @@ def run(self, args: argparse.Namespace):
6373
failed.append(file)
6474
os.chdir(original_cwd)
6575

76+
self.move_logs()
6677
if failed:
6778
for failed_file in failed:
6879
print(util.error(f'Failed to compile {failed_file}'))

tests/commands/doc/test_integration.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import os
2+
import glob
13
import pytest
24

35
from sinol_make import configure_parsers
46
from sinol_make.commands.doc import Command
7+
from sinol_make.helpers import paths
58
from tests.fixtures import create_package
69
from tests import util
710

@@ -18,6 +21,9 @@ def test_simple(capsys, create_package):
1821
out = capsys.readouterr().out
1922
assert "Compilation was successful for all files." in out
2023

24+
for pattern in command.LOG_PATTERNS:
25+
assert glob.glob(os.path.join(os.getcwd(), 'doc', pattern)) == []
26+
2127

2228
@pytest.mark.parametrize("create_package", [util.get_doc_package_path()], indirect=True)
2329
def test_argument(capsys, create_package):
@@ -30,3 +36,10 @@ def test_argument(capsys, create_package):
3036
command.run(args)
3137
out = capsys.readouterr().out
3238
assert "Compilation was successful for all files." in out
39+
40+
logs_exist = False
41+
logs_dir = paths.get_cache_path('doc_logs')
42+
for pattern in command.LOG_PATTERNS:
43+
assert glob.glob(os.path.join(os.getcwd(), 'doc', pattern)) == []
44+
logs_exist = logs_exist | (glob.glob(os.path.join(logs_dir, pattern)) != [])
45+
assert logs_exist

0 commit comments

Comments
 (0)