Skip to content

Commit

Permalink
BREAK: remove setup.cfg support (#312)
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer authored Mar 9, 2024
1 parent 3a55b62 commit 2902350
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 479 deletions.
3 changes: 0 additions & 3 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,3 @@ indent_size = 4

[LICENSE]
indent_size = unset

[setup.cfg]
indent_size = 4
6 changes: 0 additions & 6 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,6 @@
types:
- jupyter

- id: format-setup-cfg
name: Format setup.cfg
entry: format-setup-cfg
language: python
files: ^setup.cfg$

- id: set-nb-cells
name: Add or update default cells in a Jupyter notebook
description: >
Expand Down
1 change: 0 additions & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ The **ComPWA/policy** repository provides the following hooks:
- [`check-dev-files`](./check-dev-files.md)
- {mod}`colab-toc-visible <.colab_toc_visible>`
- {mod}`fix-nbformat-version <.fix_nbformat_version>`
- {mod}`format-setup-cfg <.format_setup_cfg>`
- {mod}`set-nb-cells <.set_nb_cells>`

```{toctree}
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ file = "README.md"
check-dev-files = "compwa_policy.check_dev_files:main"
colab-toc-visible = "compwa_policy.colab_toc_visible:main"
fix-nbformat-version = "compwa_policy.fix_nbformat_version:main"
format-setup-cfg = "compwa_policy.format_setup_cfg:main"
self-check = "compwa_policy.self_check:main"
set-nb-cells = "compwa_policy.set_nb_cells:main"

Expand Down
8 changes: 0 additions & 8 deletions src/compwa_policy/check_dev_files/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
readthedocs,
release_drafter,
ruff,
setup_cfg,
toml,
tox,
update_pip_constraints,
Expand Down Expand Up @@ -96,7 +95,6 @@ def main(argv: Sequence[str] | None = None) -> int:
executor(pyupgrade.main, args.no_ruff)
if not args.no_ruff:
executor(ruff.main, has_notebooks)
executor(setup_cfg.main, args.ignore_author)
if args.pin_requirements != "no":
executor(
update_pip_constraints.main,
Expand Down Expand Up @@ -167,12 +165,6 @@ def _create_argparse() -> ArgumentParser:
action="store_true",
default=False,
)
parser.add_argument(
"--ignore-author",
action="store_true",
default=False,
help="Do not update author info in setup.cfg.",
)
parser.add_argument(
"--no-cspell-update",
action="store_true",
Expand Down
8 changes: 6 additions & 2 deletions src/compwa_policy/check_dev_files/github_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
)
from compwa_policy.utilities.executor import Executor
from compwa_policy.utilities.precommit import load_precommit_config
from compwa_policy.utilities.project_info import PythonVersion, get_pypi_name
from compwa_policy.utilities.project_info import (
PythonVersion,
get_build_system,
get_pypi_name,
)
from compwa_policy.utilities.yaml import create_prettier_round_trip_yaml

if TYPE_CHECKING:
Expand Down Expand Up @@ -67,7 +71,7 @@ def update() -> None:
yaml = create_prettier_round_trip_yaml()
workflow_path = CONFIG_PATH.github_workflow_dir / "cd.yml"
expected_data = yaml.load(COMPWA_POLICY_DIR / workflow_path)
if no_pypi or not CONFIG_PATH.setup_cfg.exists():
if no_pypi or get_build_system() is None:
del expected_data["jobs"]["pypi"]
if no_version_branches:
del expected_data["jobs"]["push"]
Expand Down
60 changes: 2 additions & 58 deletions src/compwa_policy/check_dev_files/ruff.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,11 @@
from __future__ import annotations

import os
from textwrap import dedent
from typing import TYPE_CHECKING, Iterable

from ruamel.yaml import YAML
from tomlkit.items import Array, Table

from compwa_policy.check_dev_files.setup_cfg import (
has_pyproject_build_system,
has_setup_cfg_build_system,
)
from compwa_policy.errors import PrecommitError
from compwa_policy.utilities import CONFIG_PATH, natural_sorting, remove_configs, vscode
from compwa_policy.utilities.executor import Executor
Expand All @@ -23,9 +18,9 @@
update_single_hook_precommit_repo,
)
from compwa_policy.utilities.project_info import (
get_build_system,
get_project_info,
get_supported_python_versions,
open_setup_cfg,
)
from compwa_policy.utilities.pyproject import (
add_dependency,
Expand All @@ -47,7 +42,6 @@ def main(has_notebooks: bool) -> None:
add_badge,
"[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)",
)
executor(_check_setup_cfg)
executor(___uninstall, "radon")
executor(_remove_black)
executor(_remove_flake8)
Expand All @@ -62,38 +56,6 @@ def main(has_notebooks: bool) -> None:
executor.finalize()


def _check_setup_cfg() -> None:
if not has_setup_cfg_build_system():
return
cfg = open_setup_cfg()
extras_require = "options.extras_require"
if not cfg.has_section(extras_require):
msg = f"Please list ruff under a section [{extras_require}] in setup.cfg"
raise PrecommitError(msg)
msg = f"""\
Section [{extras_require}] in setup.cfg should look like this:
[{extras_require}]
...
sty =
...
ruff
...
dev =
...
%(sty)s
...
"""
msg = dedent(msg).strip()
for section in ("dev", "sty"):
if cfg.has_option(extras_require, section):
continue
raise PrecommitError(msg)
lint_section = cfg.get(extras_require, "sty")
if not any("ruff" in line for line in lint_section.split("\n")):
raise PrecommitError(msg)


def _remove_black() -> None:
executor = Executor()
executor(
Expand Down Expand Up @@ -190,27 +152,9 @@ def _remove_pylint() -> None:

def ___uninstall(package: str, ignore: Iterable[str] | None = None) -> None:
ignored_sections = set() if ignore is None else set(ignore)
___uninstall_from_setup_cfg(package, ignored_sections)
___uninstall_from_pyproject_toml(package, ignored_sections)


def ___uninstall_from_setup_cfg(package: str, ignored_sections: set[str]) -> None:
if not os.path.exists(CONFIG_PATH.setup_cfg):
return
cfg = open_setup_cfg()
section = "options.extras_require"
if not cfg.has_section(section):
return
extras_require = cfg[section]
for option in extras_require:
if option in ignored_sections:
continue
if package not in cfg.get(section, option, raw=True):
continue
msg = f'Please remove {package} from the "{section}" section of setup.cfg'
raise PrecommitError(msg)


def ___uninstall_from_pyproject_toml(package: str, ignored_sections: set[str]) -> None: # noqa: C901
if not os.path.exists(CONFIG_PATH.pyproject):
return
Expand Down Expand Up @@ -622,7 +566,7 @@ def _update_precommit_hook(has_notebooks: bool) -> None:


def _update_lint_dependencies() -> None:
if not has_pyproject_build_system():
if get_build_system() is None:
return
pyproject = load_pyproject()
project_info = get_project_info(pyproject)
Expand Down
Loading

0 comments on commit 2902350

Please sign in to comment.