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

Follow-up on CI & lint stuff #65

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Run ruff-format
7880ea89fa9aed1e443696bb6042f90613ee5bf1
22 changes: 9 additions & 13 deletions cotainr/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,14 @@

# Error early on too old Python version
if sys.version_info < _minimum_dependency_version["python"]:
required_python = ".".required_python(
map(str, _minimum_dependency_version["python"])
)
sys.exit(
(
"\x1b[38;5;160m" # start of red colored text
"Cotainr requires Python>=%s\n"
"You are running Python==%s\n"
"from '%s'\n"
"ABORTING!"
"\x1b[0m" # end of red colored text
)
% (
".".join(map(str, _minimum_dependency_version["python"])),
sys.version,
sys.executable,
)
"\x1b[38;5;160m" # start of red colored text
f"Cotainr requires Python>={required_python}\n"
f"You are running Python=={sys.version}\n"
f"from '{sys.executable}'\n"
"ABORTING!"
"\x1b[0m" # end of red colored text
)
15 changes: 6 additions & 9 deletions cotainr/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,21 @@
Main CLI entrypoint.
"""

from abc import ABC, abstractmethod
import argparse
from datetime import datetime
import logging
from pathlib import Path
import platform
import re
import shutil
import subprocess
import sys
import time
from abc import ABC, abstractmethod
from datetime import datetime
from pathlib import Path

from . import container
from . import pack
from . import tracing
from . import util
from . import _minimum_dependency_version as _min_dep_ver
from . import __version__ as _cotainr_version
from . import _minimum_dependency_version as _min_dep_ver
from . import container, pack, tracing, util

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -504,7 +501,7 @@ def __init__(self, *, args=None):

def _setup_cotainr_cli_logging(self, *, log_settings):
"""
Setup logging for the cotainr main CLI.
Set up logging for the cotainr main CLI.

Setting up the logging for the cotainr main CLI includes:
- Defining log levels based on CLI verbosity arguments.
Expand Down
5 changes: 2 additions & 3 deletions cotainr/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@
import json
import logging
import os
from pathlib import Path
import shlex
import subprocess
import sys
from pathlib import Path
from tempfile import TemporaryDirectory

from . import __version__ as _cotainr_version
from . import tracing
from . import util
from . import tracing, util

logger = logging.getLogger(__name__)

Expand Down
6 changes: 2 additions & 4 deletions cotainr/pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
"""

import logging
from pathlib import Path
import random
import re
import subprocess
import sys
import time
import urllib.error
import urllib.request
from pathlib import Path

from . import tracing

Expand Down Expand Up @@ -392,9 +392,7 @@ def filter(self, record):
return True

class NoEmptyLinesFilter(logging.Filter):
"""
Remove any empty lines.
"""
"""Remove any empty lines."""

def filter(self, record):
return record.msg.strip() != ""
Expand Down
9 changes: 5 additions & 4 deletions cotainr/tests/cli/test_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,26 @@
"""

import argparse
from pathlib import Path
import re
import shlex
from pathlib import Path

import pytest

from cotainr.cli import Build, CotainrCLI

from ..container.patches import (
patch_save_singularity_sandbox_context,
patch_disable_singularity_sandbox_subprocess_runner,
patch_disable_add_metadata,
patch_disable_singularity_sandbox_subprocess_runner,
patch_save_singularity_sandbox_context,
)
from ..pack.patches import (
patch_disable_conda_install_bootstrap_conda,
patch_disable_conda_install_display_miniforge_license_for_acceptance,
patch_disable_conda_install_download_miniforge_installer,
)
from ..tracing.patches import patch_disable_console_spinner
from ..util.patches import patch_system_with_actual_file, patch_empty_system
from ..util.patches import patch_empty_system, patch_system_with_actual_file


class TestConstructor:
Expand Down
3 changes: 2 additions & 1 deletion cotainr/tests/cli/test_cotainr_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from cotainr.cli import CotainrCLI
from cotainr.tracing import LogSettings

from .data import (
data_cotainr_critical_color_log_messages,
data_cotainr_debug_color_log_messages,
Expand All @@ -25,7 +26,7 @@
patch_disable_cotainrcli_init,
patch_disables_cotainrcli_setup_cotainr_cli_logging,
)
from .stubs import StubValidSubcommand, StubInvalidSubcommand, StubLogSettingsSubcommand
from .stubs import StubInvalidSubcommand, StubLogSettingsSubcommand, StubValidSubcommand


class TestConstructor:
Expand Down
1 change: 1 addition & 0 deletions cotainr/tests/cli/test_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest

from cotainr.cli import CotainrCLI, Info

from ..util.patches import patch_empty_system, patch_system_with_actual_file


Expand Down
1 change: 1 addition & 0 deletions cotainr/tests/cli/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"""

import cotainr.cli

from .stubs import StubDummyCLI


Expand Down
4 changes: 2 additions & 2 deletions cotainr/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
"""

import contextlib
import logging
import importlib
import io
import logging
import os
from pathlib import Path
import shlex
import subprocess
import sys
import urllib.error
import urllib.request
from pathlib import Path

import pytest

Expand Down
3 changes: 2 additions & 1 deletion cotainr/tests/container/test_singularity_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@

from cotainr.container import SingularitySandbox
from cotainr.tracing import LogDispatcher, LogSettings
from .data import data_cached_alpine_sif

from ..util.patches import patch_disable_stream_subprocess
from .data import data_cached_alpine_sif


class TestConstructor:
Expand Down
19 changes: 9 additions & 10 deletions cotainr/tests/pack/test_conda_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@
from cotainr.container import SingularitySandbox
from cotainr.pack import CondaInstall
from cotainr.tracing import LogSettings

from ..container.data import data_cached_ubuntu_sif
from ..container.patches import patch_disable_singularity_sandbox_subprocess_runner
from .patches import (
patch_disable_conda_install_bootstrap_conda,
patch_disable_conda_install_download_miniforge_installer,
)
from .stubs import StubEmptyLicensePopen, StubShowLicensePopen
from ..container.data import data_cached_ubuntu_sif
from ..container.patches import patch_disable_singularity_sandbox_subprocess_runner


class TestConstructor:
Expand Down Expand Up @@ -164,14 +165,12 @@ def test_all_unneeded_removed(self, data_cached_ubuntu_sif):
with SingularitySandbox(base_image=data_cached_ubuntu_sif) as sandbox:
CondaInstall(sandbox=sandbox, license_accepted=True)
process = sandbox.run_command_in_container(cmd="conda clean -d -a")
clean_msg = "\n".join(
[
"There are no unused tarball(s) to remove.",
"There are no index cache(s) to remove.",
"There are no unused package(s) to remove.",
"There are no tempfile(s) to remove.",
"There are no logfile(s) to remove.",
]
clean_msg = (
"There are no unused tarball(s) to remove.\n"
"There are no index cache(s) to remove.\n"
"There are no unused package(s) to remove.\n"
"There are no tempfile(s) to remove.\n"
"There are no logfile(s) to remove."
)
assert process.stdout.strip() == clean_msg

Expand Down
5 changes: 3 additions & 2 deletions cotainr/tests/test__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

"""

from pathlib import Path
import subprocess
import sys
from pathlib import Path

import pytest

from .cli.patches import patch_disable_main
import cotainr

from .cli.patches import patch_disable_main


class Test__main__:
def test_programmatic_import_run(self, patch_disable_main):
Expand Down
3 changes: 2 additions & 1 deletion cotainr/tests/test_end_to_end.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@

import pytest

from cotainr.cli import CotainrCLI
from cotainr import __version__ as _cotainr_version
from cotainr.cli import CotainrCLI

from .container.data import data_cached_ubuntu_sif


Expand Down
1 change: 1 addition & 0 deletions cotainr/tests/tracing/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import pytest

import cotainr.tracing

from .stubs import FixedNumberOfSpinsEvent


Expand Down
1 change: 1 addition & 0 deletions cotainr/tests/tracing/test_console_spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import pytest

from cotainr.tracing import ConsoleSpinner, StreamWriteProxy, console_lock

from .patches import patch_fix_number_of_message_spins
from .stubs import RaiseOnEnterContext

Expand Down
1 change: 1 addition & 0 deletions cotainr/tests/tracing/test_message_spinner.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest

from cotainr.tracing import MessageSpinner

from .stubs import FixedNumberOfSpinsEvent


Expand Down
6 changes: 4 additions & 2 deletions cotainr/tests/util/test_get_systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@
"""

import pytest

import cotainr.util

from .patches import (
patch_empty_system,
patch_system_with_actual_file,
patch_system_with_non_existing_file,
patch_system_with_badly_formatted_file,
patch_system_with_non_existing_file,
)
import cotainr.util


class TestGetSystems:
Expand Down
2 changes: 1 addition & 1 deletion cotainr/tests/util/test_stream_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import pytest

from cotainr.tracing import LogDispatcher, LogSettings
from cotainr.util import stream_subprocess, _print_and_capture_stream
from cotainr.util import _print_and_capture_stream, stream_subprocess


class TestStreamSubprocess:
Expand Down
Loading
Loading