From 1c202db2530836c15bb9fcaa6721e07d9fbe09d1 Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:15:48 +0200 Subject: [PATCH 1/2] FIX: do not abort setup.cfg check if no `pyproject.toml` --- src/repoma/check_dev_files/setup_cfg.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/repoma/check_dev_files/setup_cfg.py b/src/repoma/check_dev_files/setup_cfg.py index 5510f5b8..15ab0867 100644 --- a/src/repoma/check_dev_files/setup_cfg.py +++ b/src/repoma/check_dev_files/setup_cfg.py @@ -37,8 +37,6 @@ 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: From a47bab4d3c91f594a258844cf85e9adfe273c81e Mon Sep 17 00:00:00 2001 From: Remco de Boer <29308176+redeboer@users.noreply.github.com> Date: Tue, 3 Oct 2023 21:29:52 +0200 Subject: [PATCH 2/2] FEAT: remove empty tables from `pyproject.toml` --- src/repoma/check_dev_files/setup_cfg.py | 26 +++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/repoma/check_dev_files/setup_cfg.py b/src/repoma/check_dev_files/setup_cfg.py index 15ab0867..684a680e 100644 --- a/src/repoma/check_dev_files/setup_cfg.py +++ b/src/repoma/check_dev_files/setup_cfg.py @@ -42,6 +42,8 @@ def main(ignore_author: bool) -> None: if not ignore_author: executor(_update_author_data) executor(_fix_long_description) + if CONFIG_PATH.pyproject.exists(): + executor(_remove_empty_tables) executor.finalize() @@ -242,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