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 849d50c
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()

Check warning on line 50 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#L43-L50

Added lines #L43 - L50 were not covered by tests
if extras_require:
_update_optional_dependencies(pyproject, extras_require)

Check warning on line 52 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#L52

Added line #L52 was not covered by tests
if "3.6" in get_supported_python_versions(pyproject):
__downgrade_setuptools(pyproject)
write_pyproject(pyproject)
os.remove(setup_cfg)

Check warning on line 56 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#L54-L56

Added lines #L54 - L56 were not covered by tests
if os.path.exists("setup.py"):
Expand All @@ -59,6 +61,25 @@ def _convert_to_pyproject() -> None:
raise PrecommitError(msg)

Check warning on line 61 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#L58-L61

Added lines #L58 - L61 were not covered by tests


def __downgrade_setuptools(pyproject: TOMLDocument) -> None:
if "3.6" not in get_supported_python_versions(pyproject):
return
build_system: Optional[Table] = pyproject.get("build-system")

Check warning on line 67 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#L66-L67

Added lines #L66 - L67 were not covered by tests
if build_system is None:
return
requirements: Optional[Array] = build_system.get("requires")

Check warning on line 70 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#L69-L70

Added lines #L69 - L70 were not covered by tests
if requirements is None:
return

Check warning on line 72 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#L72

Added line #L72 was not covered by tests
for idx, package in enumerate(requirements):
if ">" not in package:
continue
package, *_ = package.split(">")

Check warning on line 76 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#L75-L76

Added lines #L75 - L76 were not covered by tests
if package.strip() == "setuptools":
requirements[idx] = "setuptools>=58.0"
break
build_system["requires"] = requirements

Check warning on line 80 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#L78-L80

Added lines #L78 - L80 were not covered by tests


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 849d50c

Please sign in to comment.