Skip to content

Commit

Permalink
FIX: downgrade setuptools for lower versions of Python
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Oct 3, 2023
1 parent 25ffb58 commit 7ee40a5
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/repoma/check_dev_files/setup_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import textwrap
from collections import defaultdict
from configparser import RawConfigParser
from typing import Dict, List, Tuple, Union
from typing import Dict, List, Optional, Tuple, Union

import tomlkit
from ini2toml.api import Translator
Expand All @@ -18,7 +18,7 @@
from repoma.utilities import CONFIG_PATH
from repoma.utilities.executor import Executor
from repoma.utilities.precommit import remove_precommit_hook
from repoma.utilities.project_info import get_pypi_name
from repoma.utilities.project_info import get_pypi_name, get_supported_python_versions
from repoma.utilities.pyproject import (
get_sub_table,
load_pyproject,
Expand Down Expand Up @@ -50,6 +50,8 @@ def _convert_to_pyproject() -> None:
extras_require = _get_recursive_optional_dependencies()
if extras_require:
_update_optional_dependencies(pyproject, extras_require)
if "3.6" in get_supported_python_versions(pyproject):
__downgrade_setuptools(pyproject)
write_pyproject(pyproject)
os.remove(setup_cfg)
if os.path.exists("setup.py"):
Expand All @@ -59,6 +61,25 @@ def _convert_to_pyproject() -> None:
raise PrecommitError(msg)


def __downgrade_setuptools(pyproject: TOMLDocument) -> None:
if "3.6" in get_supported_python_versions(pyproject):
return
build_system: Optional[Table] = pyproject.get("build-system")
if build_system is None:
return
requirements: Optional[Array] = build_system.get("requires")
if requirements is None:
return
for idx, package in enumerate(requirements):
package, *_ = package.split("=")
package, *_ = package.split(">")
package, *_ = package.split("<")
if package == "setuptools":
requirements[idx] = "setuptools>=58.0"
break
build_system["requires"] = requirements


def _get_recursive_optional_dependencies() -> Dict[str, List[Tuple[str, str]]]:
if not CONFIG_PATH.setup_cfg.exists():
return {}
Expand Down

0 comments on commit 7ee40a5

Please sign in to comment.