Skip to content

Commit

Permalink
MAINT: remove Python 3.6 copy_config() function
Browse files Browse the repository at this point in the history
  • Loading branch information
redeboer committed Dec 3, 2023
1 parent 133cbd3 commit f0dbd9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/repoma/check_dev_files/setup_cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import textwrap
from collections import defaultdict
from configparser import RawConfigParser
from copy import deepcopy
from typing import Dict, List, Tuple, Union

import tomlkit
Expand All @@ -18,7 +19,6 @@
from repoma.errors import PrecommitError
from repoma.format_setup_cfg import write_formatted_setup_cfg
from repoma.utilities import CONFIG_PATH
from repoma.utilities.cfg import copy_config
from repoma.utilities.executor import Executor
from repoma.utilities.precommit import remove_precommit_hook
from repoma.utilities.project_info import (
Expand Down Expand Up @@ -197,7 +197,7 @@ def __update_author_data_in_setup_cfg() -> None:
if not CONFIG_PATH.setup_cfg.exists():
return
old_cfg = open_setup_cfg()
new_cfg = copy_config(old_cfg)
new_cfg = deepcopy(old_cfg)
new_cfg.set("metadata", "author", "Common Partial Wave Analysis")
new_cfg.set("metadata", "author_email", "Common Partial Wave Analysis")
new_cfg.set("metadata", "author_email", "compwa-admin@ep1.rub.de")
Expand Down Expand Up @@ -236,7 +236,7 @@ def __fix_long_description_in_setup_cfg() -> None:
if not has_setup_cfg_build_system():
return
old_cfg = open_setup_cfg()
new_cfg = copy_config(old_cfg)
new_cfg = deepcopy(old_cfg)
new_cfg.set("metadata", "long_description", "file: README.md")
new_cfg.set("metadata", "long_description_content_type", "text/markdown")
if new_cfg != old_cfg:
Expand Down
16 changes: 3 additions & 13 deletions src/repoma/utilities/cfg.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import io
import re
from configparser import ConfigParser
from copy import deepcopy
from pathlib import Path
from typing import Callable, Iterable, List, Optional, Tuple, Union

Expand All @@ -11,17 +12,6 @@
from . import CONFIG_PATH, read, write


def copy_config(cfg: ConfigParser) -> ConfigParser:
# can't use deepcopy in Python 3.6
# https://stackoverflow.com/a/24343297
stream = io.StringIO()
cfg.write(stream)
stream.seek(0)
cfg_copy = ConfigParser()
cfg_copy.read_file(stream)
return cfg_copy


def extract_config_section(
extract_from: Union[Path, str],
extract_to: Union[Path, str],
Expand All @@ -42,8 +32,8 @@ def extract_config_section(
def __split_config(
cfg: ConfigParser, extracted_sections: List[str]
) -> Tuple[ConfigParser, ConfigParser]:
old_config = copy_config(cfg)
extracted_config = copy_config(cfg)
old_config = deepcopy(cfg)
extracted_config = deepcopy(cfg)
for section in cfg.sections():
if section in extracted_sections:
old_config.remove_section(section)
Expand Down

0 comments on commit f0dbd9b

Please sign in to comment.