Skip to content

Commit

Permalink
After running sinol-make doc remove log files (#140)
Browse files Browse the repository at this point in the history
* Remove compilation logs in `doc` command

* Add tests

* Move logs to .cache

* Change tests

* Bump version
  • Loading branch information
MasloMaslane authored Oct 9, 2023
1 parent 4ef4c37 commit 057ed32
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/sinol_make/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sinol_make import util, oiejq


__version__ = "1.5.11"
__version__ = "1.5.12"


def configure_parsers():
Expand Down
11 changes: 11 additions & 0 deletions src/sinol_make/commands/doc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@
import subprocess

from sinol_make import util
from sinol_make.helpers import paths
from sinol_make.interfaces.BaseCommand import BaseCommand


class Command(BaseCommand):
"""
Class for `doc` command.
"""
LOG_PATTERNS = ['*~', '*.aux', '*.log', '*.dvi', '*.err', '*.inf']

def get_name(self):
return "doc"
Expand All @@ -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(),
Expand Down Expand Up @@ -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}'))
Expand Down
13 changes: 13 additions & 0 deletions tests/commands/doc/test_integration.py
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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):
Expand All @@ -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

0 comments on commit 057ed32

Please sign in to comment.