Skip to content

Commit

Permalink
Fix Robotidy crashing if configuration file does not exist (#527)
Browse files Browse the repository at this point in the history
Fix to make source paths optional without the configuration file


Co-authored-by: Mateusz Nojek <[email protected]>
  • Loading branch information
bhirsz and mnojek authored Apr 26, 2023
1 parent a8ca849 commit 381b2f1
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 15 deletions.
17 changes: 17 additions & 0 deletions docs/releasenotes/4.2.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Robotidy 4.2.1
================

Fix release for breaking changes in the Robotidy 4.2.0.

You can install the latest available version by running::

pip install --upgrade robotframework-tidy

or to install exactly this version::

pip install robotframework-tidy==4.2.1

Robotidy now handles missing configuration file (#526)
-------------------------------------------------------

It is now possible to run Robotidy without providing configuring file, which was crashing the tool before.
2 changes: 2 additions & 0 deletions robotidy/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def get_sources(self, sources: Tuple[str, ...]) -> Optional[Tuple[str, ...]]:
return sources
src = Path(".").resolve()
config_path = files.find_source_config_file(src, self.default.ignore_git_dir)
if not config_path:
return None
config = files.read_pyproject_config(config_path)
if not config or "src" not in config:
return None
Expand Down
2 changes: 1 addition & 1 deletion robotidy/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "4.2.0"
__version__ = "4.2.1"
16 changes: 15 additions & 1 deletion tests/utest/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
from pathlib import Path
from unittest.mock import MagicMock, Mock, patch
from unittest.mock import patch

import pytest
from click import FileError, NoSuchOption
Expand All @@ -19,6 +19,16 @@ def test_data_dir():
return Path(__file__).parent / "testdata"


@pytest.fixture
def temporary_cwd(tmpdir):
prev_cwd = Path.cwd()
os.chdir(tmpdir)
try:
yield
finally:
os.chdir(prev_cwd)


class TestCli:
@pytest.mark.parametrize(
"name, similar",
Expand Down Expand Up @@ -220,6 +230,10 @@ def test_list_transformers_filter_enabled(self, flag):
assert "NormalizeNewLines" in result.output
assert "SmartSortKeywords" not in result.output

def test_no_config(self, temporary_cwd):
"""Execute Robotidy in temporary directory to ensure it supports running without default configuration file."""
run_tidy(["--list"])

@pytest.mark.parametrize("flag", ["--list", "-l"])
def test_list_transformers_filter_disabled(self, flag):
# --transform X should not have X in output, even if it is default transformer
Expand Down
13 changes: 0 additions & 13 deletions tests/utest/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,11 @@

from robotidy.app import Robotidy
from robotidy.config import FormattingConfig, MainConfig, RawConfig
from robotidy.skip import SkipConfig
from robotidy.transformers import TransformConfigMap
from robotidy.utils import ROBOT_VERSION, decorate_diff_with_color, split_args_from_name_or_path


@pytest.fixture
def app():
skip_config = SkipConfig()
formatting_config = FormattingConfig(
space_count=4,
indent=4,
continuation_indent=None,
line_sep="auto",
start_line=None,
separator="space",
end_line=None,
line_length=120,
)
config = RawConfig(
src=(".",),
target_version=ROBOT_VERSION.major,
Expand Down

0 comments on commit 381b2f1

Please sign in to comment.