Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: remove empty tables from pyproject.toml #185

Merged
merged 2 commits into from
Oct 3, 2023
Merged
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
28 changes: 26 additions & 2 deletions src/repoma/check_dev_files/setup_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@
def main(ignore_author: bool) -> None:
if CONFIG_PATH.setup_cfg.exists():
_convert_to_pyproject()
if not CONFIG_PATH.pyproject.exists():
return
executor = Executor()
executor(_check_required_options)
if not ignore_author:
executor(_update_author_data)
executor(_fix_long_description)
if CONFIG_PATH.pyproject.exists():
executor(_remove_empty_tables)

Check warning on line 46 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L46

Added line #L46 was not covered by tests
executor.finalize()


Expand Down Expand Up @@ -244,6 +244,30 @@
raise PrecommitError(msg)


def _remove_empty_tables() -> None:
if not CONFIG_PATH.pyproject.exists():
return
pyproject = load_pyproject()

Check warning on line 250 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L249-L250

Added lines #L249 - L250 were not covered by tests
if __recursive_remove_empty_tables(pyproject):
write_pyproject(pyproject)
msg = f"Removed empty tables from {CONFIG_PATH.pyproject}"
raise PrecommitError(msg)

Check warning on line 254 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L252-L254

Added lines #L252 - L254 were not covered by tests


def __recursive_remove_empty_tables(table: Union[Container, Table]) -> bool:
updated = False
items = list(table.items())

Check warning on line 259 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L258-L259

Added lines #L258 - L259 were not covered by tests
for key, value in items:
if not isinstance(value, Table):
continue

Check warning on line 262 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L262

Added line #L262 was not covered by tests
if len(value) == 0:
del table[key]
updated = True

Check warning on line 265 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L264-L265

Added lines #L264 - L265 were not covered by tests
else:
updated |= __recursive_remove_empty_tables(value)
return updated

Check warning on line 268 in src/repoma/check_dev_files/setup_cfg.py

View check run for this annotation

Codecov / codecov/patch

src/repoma/check_dev_files/setup_cfg.py#L267-L268

Added lines #L267 - L268 were not covered by tests


def has_pyproject_build_system() -> bool:
if not CONFIG_PATH.pyproject.exists():
return False
Expand Down
Loading