Skip to content

Commit

Permalink
FEAT: remove empty tables from pyproject.toml (#185)
Browse files Browse the repository at this point in the history
* FIX: do not abort setup.cfg check if no `pyproject.toml`
  • Loading branch information
redeboer authored Oct 3, 2023
1 parent 6b9c58c commit eb1a9c2
Showing 1 changed file with 26 additions and 2 deletions.
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)
executor.finalize()


Expand Down Expand Up @@ -244,6 +244,30 @@ def __fix_long_description_in_setup_cfg() -> None:
raise PrecommitError(msg)


def _remove_empty_tables() -> None:
if not CONFIG_PATH.pyproject.exists():
return
pyproject = load_pyproject()
if __recursive_remove_empty_tables(pyproject):
write_pyproject(pyproject)
msg = f"Removed empty tables from {CONFIG_PATH.pyproject}"
raise PrecommitError(msg)


def __recursive_remove_empty_tables(table: Union[Container, Table]) -> bool:
updated = False
items = list(table.items())
for key, value in items:
if not isinstance(value, Table):
continue
if len(value) == 0:
del table[key]
updated = True
else:
updated |= __recursive_remove_empty_tables(value)
return updated


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

0 comments on commit eb1a9c2

Please sign in to comment.