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

fix: actually show chosen styles in log output #477

Merged
merged 2 commits into from
Mar 28, 2022
Merged
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
3 changes: 1 addition & 2 deletions src/nitpick/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from autorepr import autorepr
from loguru import logger
from marshmallow_polyfield import PolyField
from more_itertools import peekable
from more_itertools.more import always_iterable
from pluggy import PluginManager
from tomlkit.items import KeyType, SingleKey
Expand Down Expand Up @@ -182,7 +181,7 @@ def merge_styles(self, offline: bool) -> Iterator[Fuss]:

style = StyleManager(self, offline, config.cache)
base = config.file.expanduser().resolve().as_uri() if config.file else None
style_errors = list(style.find_initial_styles(peekable(always_iterable(config.styles)), base))
style_errors = list(style.find_initial_styles(list(always_iterable(config.styles)), base))
andreoliwa marked this conversation as resolved.
Show resolved Hide resolved
if style_errors:
raise QuitComplainingError(style_errors)

Expand Down
5 changes: 3 additions & 2 deletions src/nitpick/style/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,12 @@ def find_initial_styles(self, configured_styles: Sequence[str], base: str | None

"""
project_root = self.project.root
base_url = furl(base or project_root.resolve().as_uri())

if configured_styles:
chosen_styles = configured_styles
logger.info(f"Using styles configured in {PYPROJECT_TOML}: {chosen_styles}")
config_file = base_url.path.segments[-1] if base else PYPROJECT_TOML
andreoliwa marked this conversation as resolved.
Show resolved Hide resolved
logger.info(f"Using styles configured in {config_file}: {', '.join(chosen_styles)}")
else:
paths = glob_files(project_root, [NITPICK_STYLE_TOML])
if paths:
Expand All @@ -107,7 +109,6 @@ def find_initial_styles(self, configured_styles: Sequence[str], base: str | None
log_message = "Using default remote Nitpick style"
logger.info(f"{log_message}: {chosen_styles[0]}")

base_url = furl(base or project_root.resolve().as_uri())
yield from self.include_multiple_styles(
self._style_fetcher_manager.normalize_url(ref, base_url) for ref in chosen_styles
)
Expand Down
13 changes: 9 additions & 4 deletions tests/test_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from nitpick.core import Nitpick
from nitpick.exceptions import QuitComplainingError
from nitpick.project import Configuration, confirm_project_root, find_main_python_file
from nitpick.style import StyleManager
from nitpick.violations import ProjectViolations
from tests.helpers import ProjectMock

Expand Down Expand Up @@ -124,8 +125,10 @@ def test_django_project_structure(tmp_path):
def test_when_no_config_file_the_default_style_is_requested(tmp_path, caplog):
"""There is a root dir (setup.py), but no config file."""
project = ProjectMock(tmp_path, pyproject_toml=False, setup_py=True).api_check(offline=True)
style_url = StyleManager.get_default_style_url()
assert project.nitpick_instance.project.read_configuration() == Configuration(None, [], "")
assert "Config file: none found" in caplog.text
assert "Config file: none found {}" in caplog.messages
assert f"Using default remote Nitpick style: {style_url} {{}}" in caplog.messages


@pytest.mark.parametrize("config_file", [DOT_NITPICK_TOML, PYPROJECT_TOML])
Expand All @@ -142,7 +145,8 @@ def test_has_one_config_file(tmp_path, config_file, caplog):
).api_check(offline=True)
path = project.root_dir / config_file
assert project.nitpick_instance.project.read_configuration() == Configuration(path, ["local.toml"], "forever")
assert f"Config file: reading from {path}" in caplog.text
assert f"Config file: reading from {path} {{}}" in caplog.messages
assert f"Using styles configured in {config_file}: local.toml {{}}" in caplog.messages


def test_has_multiple_config_files(tmp_path, caplog):
Expand All @@ -168,8 +172,9 @@ def test_has_multiple_config_files(tmp_path, caplog):
assert project.nitpick_instance.project.read_configuration() == Configuration(
project.root_dir / DOT_NITPICK_TOML, ["local_nit.toml"], "never"
)
assert f"Config file: reading from {project.root_dir / DOT_NITPICK_TOML}" in caplog.text
assert f"Config file: ignoring existing {project.root_dir / PYPROJECT_TOML}" in caplog.text
assert f"Config file: reading from {project.root_dir / DOT_NITPICK_TOML} {{}}" in caplog.messages
assert f"Config file: ignoring existing {project.root_dir / PYPROJECT_TOML} {{}}" in caplog.messages
assert f"Using styles configured in {DOT_NITPICK_TOML}: local_nit.toml {{}}" in caplog.messages


@pytest.mark.parametrize(
Expand Down