Skip to content

Commit

Permalink
Exclude remove_trailing_spaces task
Browse files Browse the repository at this point in the history
With the new `Array.add_line` method in `atoml`, it is possible to
control the array formatting and avoid trailing whitespaces when
creating them.

Therefore it is better to avoid removing the trailing whitespaces since
they might be intentional.
  • Loading branch information
abravalheri committed Nov 1, 2021
1 parent 920f93c commit 8e34ae7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Expand Up @@ -62,12 +62,12 @@ exclude =
# `pip install ini2toml[PDF]` like:
# PDF = ReportLab; RXP
full =
configupdater>=3,<4
configupdater>=3.0.1,<4
atoml>=1.1.0,<2
lite =
tomli-w>=0.4.0,<2
all =
configupdater>=3,<4
configupdater>=3.0.1,<4
atoml>=1.1.0,<2
tomli-w>=0.4.0,<2

Expand Down
8 changes: 6 additions & 2 deletions src/ini2toml/drivers/full_toml.py
Expand Up @@ -73,15 +73,19 @@ def _collapse_commented_list(obj: CommentedList, root=False) -> Array:
values = entry.value_or([])

if multiline:
out.add_line(*[collapse(v) for v in values], comment=entry.comment)
collapsed_values = [collapse(v) for v in values]
if collapsed_values or entry.comment:
out.add_line(*collapsed_values, comment=entry.comment)
else:
out.add_line(indent="") # Empty line
else:
for value in values:
cast(list, out).append(collapse(value))
if entry.has_comment():
cast(Item, out).comment(entry.comment)

if multiline:
out.add_line(indent="")
out.add_line(indent="") # New line before closing brackets

return out

Expand Down
8 changes: 1 addition & 7 deletions src/ini2toml/plugins/profile_independent_tasks.py
Expand Up @@ -8,11 +8,10 @@
NEWLINES = re.compile(r"\n+", re.M)
TABLE_START = re.compile(r"^\[(.*)\]", re.M)
EMPTY_TABLES = re.compile(r"^\[(.*)\]\n+\[(\1\.(?:.*))\]", re.M)
TRAILING_SPACES = re.compile(r"[ \t]+$", re.M)


def activate(translator: Translator):
tasks = [remove_trailing_spaces, normalise_newlines, remove_empty_table_headers]
tasks = [normalise_newlines, remove_empty_table_headers]
for task in tasks:
translator.augment_profiles(post_process(task), active_by_default=True)

Expand All @@ -25,11 +24,6 @@ def _augmentation(profile: Profile):
return _augmentation


def remove_trailing_spaces(text: str) -> str:
"""Remove trailing spaces"""
return TRAILING_SPACES.sub("", text)


def normalise_newlines(text: str) -> str:
"""Make sure every table is preceded by an empty newline, but remove them elsewhere
in the output TOML document.
Expand Down
5 changes: 2 additions & 3 deletions tests/plugins/test_setuptools_pep621.py
Expand Up @@ -2,7 +2,6 @@

import pytest

from ini2toml.plugins import profile_independent_tasks as tasks
from ini2toml.plugins.setuptools_pep621 import SetuptoolsPEP621, activate, isdirective
from ini2toml.translator import Translator

Expand Down Expand Up @@ -154,7 +153,7 @@ def test_move_entry_points_and_apply_value_processing(plugin, parse, convert):
doc = plugin.apply_value_processing(doc)
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
print(doc)
text = tasks.remove_trailing_spaces(convert(doc)).strip()
text = convert(doc).strip()
assert text == expected_apply_value_processing.strip()


Expand Down Expand Up @@ -338,7 +337,7 @@ def test_fix_setup_requires(plugin, parse, convert):
doc.pop("metadata", None)
print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
print(doc)
text = tasks.remove_trailing_spaces(convert(doc)).strip()
text = convert(doc).strip()
assert text == expected_fix_setup_requires.strip()


Expand Down

0 comments on commit 8e34ae7

Please sign in to comment.