Skip to content
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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Fixes
- Renamed short version of ``--lineseparator`` to ``-ls`` to avoid collision with ``--list\-l``
- Description for disabled transformers can be now displayed & disabled transformers are in ``--list`` output [#114](https://github.com/MarketSquare/robotframework-tidy/issues/114)
- Robotidy should now correctly load configuration files from path when using ``--config`` [#138](https://github.com/MarketSquare/robotframework-tidy/issues/138)

### Other
- Removed ``'--describe-transformer`` and ``--list-transformers`` aliases for ``--list`` and ``--desc``
Expand Down
11 changes: 3 additions & 8 deletions robotidy/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def find_and_read_config(src_paths: Iterable[str]) -> Dict[str, Any]:
project_root = find_project_root(src_paths)
config_path = project_root / 'robotidy.toml'
if config_path.is_file():
return read_robotidy_config(str(config_path))
return read_pyproject_config(str(config_path))
pyproject_path = project_root / 'pyproject.toml'
if pyproject_path.is_file():
return read_pyproject_config(str(pyproject_path))
Expand All @@ -140,21 +140,16 @@ def load_toml_file(path: str) -> Dict[str, Any]:


def read_pyproject_config(path: str) -> Dict[str, Any]:
click.echo('Reading pyproject.toml')
click.echo(f'Reading {path}')
config = load_toml_file(path)
config = config.get("tool", {}).get("robotidy", {})
return {k.replace('--', '').replace('-', '_'): v for k, v in config.items()}


def read_robotidy_config(path: str) -> Dict[str, Any]:
config = load_toml_file(path)
return {k.replace('--', '').replace('-', '_'): v for k, v in config.items()}


def read_config(ctx: click.Context, param: click.Parameter, value: Optional[str]) -> Optional[str]:
# if --config was not used, try to find pyproject.toml or robotidy.toml file
if value:
config = read_robotidy_config(value)
config = read_pyproject_config(value)
else:
config = find_and_read_config(ctx.params.get("src", ()))
if not config:
Expand Down
4 changes: 2 additions & 2 deletions tests/utest/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .utils import run_tidy, save_tmp_model
from robotidy.cli import (
find_project_root,
read_robotidy_config,
read_pyproject_config,
read_config
)
Expand Down Expand Up @@ -79,6 +78,7 @@ def test_find_project_root_from_src(self):
assert path == Path(Path(__file__).parent, 'testdata')

def test_read_robotidy_config(self):
""" robotidy.toml follows the same format as pyproject starting from 1.2.0 """
expected_config = {
'overwrite': False,
'diff': False,
Expand All @@ -89,7 +89,7 @@ def test_read_robotidy_config(self):
]
}
config_path = str(Path(Path(__file__).parent, 'testdata', 'robotidy.toml'))
config = read_robotidy_config(config_path)
config = read_pyproject_config(config_path)
assert config == expected_config

def test_read_pyproject_config(self):
Expand Down
1 change: 1 addition & 0 deletions tests/utest/testdata/robotidy.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
[tool.robotidy]
overwrite = false
diff = false
spacecount = 4
Expand Down