Skip to content

Commit 7ae88a4

Browse files
authored
Fix config not loaded when using --config (#139)
1 parent 5c50daa commit 7ae88a4

File tree

4 files changed

+7
-10
lines changed

4 files changed

+7
-10
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
### Fixes
1616
- Renamed short version of ``--lineseparator`` to ``-ls`` to avoid collision with ``--list\-l``
1717
- Description for disabled transformers can be now displayed & disabled transformers are in ``--list`` output [#114](https://github.com/MarketSquare/robotframework-tidy/issues/114)
18+
- Robotidy should now correctly load configuration files from path when using ``--config`` [#138](https://github.com/MarketSquare/robotframework-tidy/issues/138)
1819

1920
### Other
2021
- Removed ``'--describe-transformer`` and ``--list-transformers`` aliases for ``--list`` and ``--desc``

robotidy/cli.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def find_and_read_config(src_paths: Iterable[str]) -> Dict[str, Any]:
121121
project_root = find_project_root(src_paths)
122122
config_path = project_root / 'robotidy.toml'
123123
if config_path.is_file():
124-
return read_robotidy_config(str(config_path))
124+
return read_pyproject_config(str(config_path))
125125
pyproject_path = project_root / 'pyproject.toml'
126126
if pyproject_path.is_file():
127127
return read_pyproject_config(str(pyproject_path))
@@ -140,21 +140,16 @@ def load_toml_file(path: str) -> Dict[str, Any]:
140140

141141

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

148148

149-
def read_robotidy_config(path: str) -> Dict[str, Any]:
150-
config = load_toml_file(path)
151-
return {k.replace('--', '').replace('-', '_'): v for k, v in config.items()}
152-
153-
154149
def read_config(ctx: click.Context, param: click.Parameter, value: Optional[str]) -> Optional[str]:
155150
# if --config was not used, try to find pyproject.toml or robotidy.toml file
156151
if value:
157-
config = read_robotidy_config(value)
152+
config = read_pyproject_config(value)
158153
else:
159154
config = find_and_read_config(ctx.params.get("src", ()))
160155
if not config:

tests/utest/test_cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
from .utils import run_tidy, save_tmp_model
99
from robotidy.cli import (
1010
find_project_root,
11-
read_robotidy_config,
1211
read_pyproject_config,
1312
read_config
1413
)
@@ -79,6 +78,7 @@ def test_find_project_root_from_src(self):
7978
assert path == Path(Path(__file__).parent, 'testdata')
8079

8180
def test_read_robotidy_config(self):
81+
""" robotidy.toml follows the same format as pyproject starting from 1.2.0 """
8282
expected_config = {
8383
'overwrite': False,
8484
'diff': False,
@@ -89,7 +89,7 @@ def test_read_robotidy_config(self):
8989
]
9090
}
9191
config_path = str(Path(Path(__file__).parent, 'testdata', 'robotidy.toml'))
92-
config = read_robotidy_config(config_path)
92+
config = read_pyproject_config(config_path)
9393
assert config == expected_config
9494

9595
def test_read_pyproject_config(self):

tests/utest/testdata/robotidy.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
[tool.robotidy]
12
overwrite = false
23
diff = false
34
spacecount = 4

0 commit comments

Comments
 (0)