Skip to content

Commit 65727a5

Browse files
authored
Remove experimental feature for automatic formatting (#108)
2 parents d55badb + 6895583 commit 65727a5

File tree

4 files changed

+8
-70
lines changed

4 files changed

+8
-70
lines changed

CHANGELOG.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
Changelog
33
=========
44

5+
Version 0.16
6+
============
7+
8+
* Removed experimental auto-formatting feature, :pr:`108`.
9+
This includes removing the ``experimental`` extra group for optional dependencies.
10+
Users that are interested in auto-formatting the output are suggested to run
11+
``pyproject-fmt`` as an additional step, after ``ini2toml``.
12+
513
Version 0.15
614
============
715

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@ all = [
4040
"tomlkit>=0.10.0,<2",
4141
"tomli-w>=0.4.0,<2",
4242
]
43-
experimental = [
44-
"pyproject-fmt>=0.4.0,<2"
45-
]
4643
testing = [
4744
"isort",
4845
"setuptools",

src/ini2toml/cli.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,6 @@ def critical_logging():
8383
),
8484
}
8585

86-
try:
87-
import pyproject_fmt # noqa
88-
89-
META["auto_format"] = dict(
90-
flags=("-F", "--auto-format"),
91-
action="store_true",
92-
help="**EXPERIMENTAL** - format output with `pyproject-fmt`\n"
93-
"(note that auto-formatting is intrusive and may cause loss of comments).",
94-
)
95-
96-
def apply_auto_formatting(text: str) -> str:
97-
try:
98-
from pyproject_fmt import Config, format_pyproject
99-
100-
return format_pyproject(Config(Path("pyproject.toml"), text))
101-
except Exception as ex: # pragma: no cover
102-
_logger.debug(f"pyproject-fmt failed: {ex}", exc_info=True)
103-
_logger.warning("Auto-formatting failed, falling back to original text")
104-
return text
105-
106-
except ImportError: # pragma: no cover
107-
108-
def apply_auto_formatting(text: str) -> str:
109-
return text
110-
11186

11287
def __meta__(
11388
profiles: Sequence[Profile], augmentations: Sequence[ProfileAugmentation]
@@ -200,8 +175,6 @@ def run(args: Sequence[str] = ()):
200175
out = translator.translate(
201176
params.input_file.read(), params.profile, params.active_augmentations
202177
)
203-
if getattr(params, "auto_format", False):
204-
out = apply_auto_formatting(out)
205178
params.output_file.write(out)
206179

207180

tests/test_cli.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import logging
22
import sys
3-
from inspect import cleandoc
43
from unittest.mock import MagicMock
54

65
import pytest
@@ -121,42 +120,3 @@ def test_help(capsys):
121120
expected = " ".join(x.strip() for x in expected_profile_desc.splitlines())
122121
print(out)
123122
assert expected in text
124-
125-
126-
@pytest.mark.skipif(
127-
sys.version_info < (3, 7),
128-
reason="pyproject-fmt is only available on Python 3.7+",
129-
)
130-
def test_auto_formatting(tmp_path, capsys):
131-
setupcfg = """
132-
[metadata]
133-
version = 42
134-
name = myproj
135-
"""
136-
normal_output = """
137-
requires = ["setuptools>=61.2"]
138-
"""
139-
expected = """
140-
requires = [
141-
"setuptools>=61.2",
142-
]
143-
"""
144-
145-
# Check if the underlying function works
146-
formatted = cli.apply_auto_formatting(cleandoc(expected))
147-
assert formatted.strip() == cleandoc(expected).strip()
148-
149-
(tmp_path / "setup.cfg").write_text(cleandoc(setupcfg), encoding="utf-8")
150-
assert (tmp_path / "setup.cfg").exists()
151-
152-
# Check the output when formatting in off
153-
cli.run([str(tmp_path / "setup.cfg")])
154-
out, _ = capsys.readouterr()
155-
assert cleandoc(normal_output) in out
156-
assert cleandoc(expected) not in out
157-
158-
# Check the output when formatting in on
159-
cli.run(["-F", str(tmp_path / "setup.cfg")])
160-
out, _ = capsys.readouterr()
161-
assert cleandoc(normal_output) not in out
162-
assert cleandoc(expected) in out

0 commit comments

Comments
 (0)