1
1
from __future__ import annotations
2
2
3
+ import functools
3
4
import io
4
5
import itertools
5
6
import numbers
@@ -595,8 +596,8 @@ def _parse_config_files(self, filenames=None): # noqa: C901
595
596
continue
596
597
597
598
val = parser .get (section , opt )
598
- opt = self .warn_dash_deprecation (opt , section )
599
- opt = self .make_option_lowercase (opt , section )
599
+ opt = self ._enforce_underscore (opt , section )
600
+ opt = self ._enforce_option_lowercase (opt , section )
600
601
opt_dict [opt ] = (filename , val )
601
602
602
603
# Make the ConfigParser forget everything (so we retain
@@ -621,64 +622,42 @@ def _parse_config_files(self, filenames=None): # noqa: C901
621
622
except ValueError as e :
622
623
raise DistutilsOptionError (e ) from e
623
624
624
- def warn_dash_deprecation (self , opt : str , section : str ) -> str :
625
- if section in (
626
- 'options.extras_require' ,
627
- 'options.data_files' ,
628
- ):
625
+ def _enforce_underscore (self , opt : str , section : str ) -> str :
626
+ if "-" not in opt or self ._skip_setupcfg_normalization (section ):
629
627
return opt
630
628
631
- underscore_opt = opt .replace ('-' , '_' )
632
- commands = list (
633
- itertools .chain (
634
- distutils .command .__all__ ,
635
- self ._setuptools_commands (),
636
- )
629
+ raise InvalidConfigError (
630
+ f"Invalid dash-separated key { opt !r} in { section !r} (setup.cfg), "
631
+ f"please use the underscore name { opt .replace ('-' , '_' )!r} instead."
632
+ # Warning initially introduced in 3 Mar 2021
637
633
)
638
- if (
639
- not section .startswith ('options' )
640
- and section != 'metadata'
641
- and section not in commands
642
- ):
643
- return underscore_opt
644
-
645
- if '-' in opt :
646
- SetuptoolsDeprecationWarning .emit (
647
- "Invalid dash-separated options" ,
648
- f"""
649
- Usage of dash-separated { opt !r} will not be supported in future
650
- versions. Please use the underscore name { underscore_opt !r} instead.
651
- """ ,
652
- see_docs = "userguide/declarative_config.html" ,
653
- due_date = (2025 , 3 , 3 ),
654
- # Warning initially introduced in 3 Mar 2021
655
- )
656
- return underscore_opt
657
634
658
- def _setuptools_commands (self ):
659
- try :
660
- entry_points = metadata .distribution ('setuptools' ).entry_points
661
- return {ep .name for ep in entry_points } # Avoid newer API for compatibility
662
- except metadata .PackageNotFoundError :
663
- # during bootstrapping, distribution doesn't exist
664
- return []
665
-
666
- def make_option_lowercase (self , opt : str , section : str ) -> str :
667
- if section != 'metadata' or opt .islower ():
635
+ def _enforce_option_lowercase (self , opt : str , section : str ) -> str :
636
+ if opt .islower () or self ._skip_setupcfg_normalization (section ):
668
637
return opt
669
638
670
- lowercase_opt = opt .lower ()
671
- SetuptoolsDeprecationWarning .emit (
672
- "Invalid uppercase configuration" ,
673
- f"""
674
- Usage of uppercase key { opt !r} in { section !r} will not be supported in
675
- future versions. Please use lowercase { lowercase_opt !r} instead.
676
- """ ,
677
- see_docs = "userguide/declarative_config.html" ,
678
- due_date = (2025 , 3 , 3 ),
639
+ raise InvalidConfigError (
640
+ f"Invalid uppercase key { opt !r} in { section !r} (setup.cfg), "
641
+ f"please use lowercase { opt .lower ()!r} instead."
679
642
# Warning initially introduced in 6 Mar 2021
680
643
)
681
- return lowercase_opt
644
+
645
+ def _skip_setupcfg_normalization (self , section : str ) -> bool :
646
+ skip = (
647
+ 'options.extras_require' ,
648
+ 'options.data_files' ,
649
+ 'options.entry_points' ,
650
+ 'options.package_data' ,
651
+ 'options.exclude_package_data' ,
652
+ )
653
+ return section in skip or not self ._is_setuptools_section (section )
654
+
655
+ def _is_setuptools_section (self , section : str ) -> bool :
656
+ return (
657
+ section == "metadata"
658
+ or section .startswith ("options" )
659
+ or section in _setuptools_commands ()
660
+ )
682
661
683
662
# FIXME: 'Distribution._set_command_options' is too complex (14)
684
663
def _set_command_options (self , command_obj , option_dict = None ): # noqa: C901
@@ -1105,6 +1084,18 @@ def run_command(self, command) -> None:
1105
1084
super ().run_command (command )
1106
1085
1107
1086
1087
+ @functools .cache
1088
+ def _setuptools_commands () -> set [str ]:
1089
+ try :
1090
+ # Use older API for importlib.metadata compatibility
1091
+ entry_points = metadata .distribution ('setuptools' ).entry_points
1092
+ eps : Iterable [str ] = (ep .name for ep in entry_points )
1093
+ except metadata .PackageNotFoundError :
1094
+ # during bootstrapping, distribution doesn't exist
1095
+ eps = []
1096
+ return {* distutils .command .__all__ , * eps }
1097
+
1098
+
1108
1099
class DistDeprecationWarning (SetuptoolsDeprecationWarning ):
1109
1100
"""Class for warning about deprecations in dist in
1110
1101
setuptools. Not ignored by default, unlike DeprecationWarning."""
0 commit comments