Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After running sinol-make doc remove log files #140

Merged
merged 5 commits into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading