@@ -200,7 +200,9 @@ def get_supported_platform():
200
200
m = macosVersionString .match (plat )
201
201
if m is not None and sys .platform == "darwin" :
202
202
try :
203
- plat = 'macosx-%s-%s' % ('.' .join (_macos_vers ()[:2 ]), m .group (3 ))
203
+ major_minor = '.' .join (_macos_vers ()[:2 ])
204
+ build = m .group (3 )
205
+ plat = f'macosx-{ major_minor } -{ build } '
204
206
except ValueError :
205
207
# not macOS
206
208
pass
@@ -449,12 +451,8 @@ def get_build_platform():
449
451
if sys .platform == "darwin" and not plat .startswith ('macosx-' ):
450
452
try :
451
453
version = _macos_vers ()
452
- machine = os .uname ()[4 ].replace (" " , "_" )
453
- return "macosx-%d.%d-%s" % (
454
- int (version [0 ]),
455
- int (version [1 ]),
456
- _macos_arch (machine ),
457
- )
454
+ machine = _macos_arch (os .uname ()[4 ].replace (" " , "_" ))
455
+ return f"macosx-{ version [0 ]} .{ version [1 ]} -{ machine } "
458
456
except ValueError :
459
457
# if someone is running a non-Mac darwin system, this will fall
460
458
# through to the default implementation
@@ -492,7 +490,7 @@ def compatible_platforms(provided: str | None, required: str | None) -> bool:
492
490
provDarwin = darwinVersionString .match (provided )
493
491
if provDarwin :
494
492
dversion = int (provDarwin .group (1 ))
495
- macosversion = "%s.%s" % ( reqMac .group (1 ), reqMac .group (2 ))
493
+ macosversion = f" { reqMac .group (1 )} . { reqMac .group (2 )} "
496
494
if (
497
495
dversion == 7
498
496
and macosversion >= "10.3"
@@ -875,9 +873,7 @@ def resolve(
875
873
876
874
# Mapping of requirement to set of distributions that required it;
877
875
# useful for reporting info about conflicts.
878
- required_by : collections .defaultdict [Requirement , set [str ]] = (
879
- collections .defaultdict (set )
880
- )
876
+ required_by = collections .defaultdict [Requirement , set [str ]](set )
881
877
882
878
while requirements :
883
879
# process dependencies breadth-first
@@ -1316,7 +1312,7 @@ def __iadd__(self, other: Distribution | Environment) -> Self:
1316
1312
for dist in other [project ]:
1317
1313
self .add (dist )
1318
1314
else :
1319
- raise TypeError ("Can't add %r to environment" % ( other ,) )
1315
+ raise TypeError (f "Can't add { other !r } to environment" )
1320
1316
return self
1321
1317
1322
1318
def __add__ (self , other : Distribution | Environment ) -> Self :
@@ -1699,7 +1695,7 @@ def get_metadata(self, name: str) -> str:
1699
1695
except UnicodeDecodeError as exc :
1700
1696
# Include the path in the error message to simplify
1701
1697
# troubleshooting, and without changing the exception type.
1702
- exc .reason += ' in {} file at path: {}' . format ( name , path )
1698
+ exc .reason += f ' in { name } file at path: { path } '
1703
1699
raise
1704
1700
1705
1701
def get_metadata_lines (self , name : str ) -> Iterator [str ]:
@@ -2018,15 +2014,15 @@ def _zipinfo_name(self, fspath):
2018
2014
return ''
2019
2015
if fspath .startswith (self .zip_pre ):
2020
2016
return fspath [len (self .zip_pre ) :]
2021
- raise AssertionError ("%s is not a subpath of %s" % ( fspath , self .zip_pre ) )
2017
+ raise AssertionError (f" { fspath } is not a subpath of { self .zip_pre } " )
2022
2018
2023
2019
def _parts (self , zip_path ):
2024
2020
# Convert a zipfile subpath into an egg-relative path part list.
2025
2021
# pseudo-fs path
2026
2022
fspath = self .zip_pre + zip_path
2027
2023
if fspath .startswith (self .egg_root + os .sep ):
2028
2024
return fspath [len (self .egg_root ) + 1 :].split (os .sep )
2029
- raise AssertionError ("%s is not a subpath of %s" % ( fspath , self .egg_root ) )
2025
+ raise AssertionError (f" { fspath } is not a subpath of { self .egg_root } " )
2030
2026
2031
2027
@property
2032
2028
def zipinfo (self ):
@@ -2729,15 +2725,16 @@ def __init__(
2729
2725
self .dist = dist
2730
2726
2731
2727
def __str__ (self ) -> str :
2732
- s = "%s = %s" % ( self .name , self .module_name )
2728
+ s = f" { self .name } = { self .module_name } "
2733
2729
if self .attrs :
2734
2730
s += ':' + '.' .join (self .attrs )
2735
2731
if self .extras :
2736
- s += ' [%s]' % ',' .join (self .extras )
2732
+ extras = ',' .join (self .extras )
2733
+ s += f' [{ extras } ]'
2737
2734
return s
2738
2735
2739
2736
def __repr__ (self ) -> str :
2740
- return "EntryPoint.parse(%r)" % str (self )
2737
+ return f "EntryPoint.parse({ str (self )!r } )"
2741
2738
2742
2739
@overload
2743
2740
def load (
@@ -3049,9 +3046,7 @@ def version(self):
3049
3046
version = self ._get_version ()
3050
3047
if version is None :
3051
3048
path = self ._get_metadata_path_for_display (self .PKG_INFO )
3052
- msg = ("Missing 'Version:' header and/or {} file at path: {}" ).format (
3053
- self .PKG_INFO , path
3054
- )
3049
+ msg = f"Missing 'Version:' header and/or { self .PKG_INFO } file at path: { path } "
3055
3050
raise ValueError (msg , self ) from e
3056
3051
3057
3052
return version
@@ -3107,9 +3102,7 @@ def requires(self, extras: Iterable[str] = ()) -> list[Requirement]:
3107
3102
try :
3108
3103
deps .extend (dm [safe_extra (ext )])
3109
3104
except KeyError as e :
3110
- raise UnknownExtra (
3111
- "%s has no such extra feature %r" % (self , ext )
3112
- ) from e
3105
+ raise UnknownExtra (f"{ self } has no such extra feature { ext !r} " ) from e
3113
3106
return deps
3114
3107
3115
3108
def _get_metadata_path_for_display (self , name ):
@@ -3150,19 +3143,15 @@ def activate(self, path: list[str] | None = None, replace: bool = False) -> None
3150
3143
3151
3144
def egg_name (self ):
3152
3145
"""Return what this distribution's standard .egg filename should be"""
3153
- filename = "%s-%s-py%s" % (
3154
- to_filename (self .project_name ),
3155
- to_filename (self .version ),
3156
- self .py_version or PY_MAJOR ,
3157
- )
3146
+ filename = f"{ to_filename (self .project_name )} -{ to_filename (self .version )} -py{ self .py_version or PY_MAJOR } "
3158
3147
3159
3148
if self .platform :
3160
3149
filename += '-' + self .platform
3161
3150
return filename
3162
3151
3163
3152
def __repr__ (self ) -> str :
3164
3153
if self .location :
3165
- return "%s (%s)" % ( self , self .location )
3154
+ return f" { self } ( { self .location } )"
3166
3155
else :
3167
3156
return str (self )
3168
3157
@@ -3172,7 +3161,7 @@ def __str__(self) -> str:
3172
3161
except ValueError :
3173
3162
version = None
3174
3163
version = version or "[unknown version]"
3175
- return "%s %s" % ( self .project_name , version )
3164
+ return f" { self .project_name } { version } "
3176
3165
3177
3166
def __getattr__ (self , attr : str ):
3178
3167
"""Delegate all unrecognized public attributes to .metadata provider"""
@@ -3200,17 +3189,17 @@ def from_filename(
3200
3189
def as_requirement (self ):
3201
3190
"""Return a ``Requirement`` that matches this distribution exactly"""
3202
3191
if isinstance (self .parsed_version , packaging .version .Version ):
3203
- spec = "%s==%s" % ( self .project_name , self .parsed_version )
3192
+ spec = f" { self .project_name } == { self .parsed_version } "
3204
3193
else :
3205
- spec = "%s ===%s" % ( self .project_name , self . parsed_version )
3194
+ spec = f" { self . project_name } ==={ self .parsed_version } "
3206
3195
3207
3196
return Requirement .parse (spec )
3208
3197
3209
3198
def load_entry_point (self , group : str , name : str ) -> _ResolvedEntryPoint :
3210
3199
"""Return the `name` entry point of `group` or raise ImportError"""
3211
3200
ep = self .get_entry_info (group , name )
3212
3201
if ep is None :
3213
- raise ImportError ("Entry point %r not found" % (( group , name ),) )
3202
+ raise ImportError (f "Entry point { ( group , name )!r } not found" )
3214
3203
return ep .load ()
3215
3204
3216
3205
@overload
@@ -3327,8 +3316,8 @@ def check_version_conflict(self):
3327
3316
):
3328
3317
continue
3329
3318
issue_warning (
3330
- "Module %s was already imported from %s, but %s is being added "
3331
- " to sys.path" % ( modname , fn , self . location ) ,
3319
+ f "Module { modname } was already imported from { fn } , "
3320
+ f"but { self . location } is being added to sys.path" ,
3332
3321
)
3333
3322
3334
3323
def has_version (self ) -> bool :
@@ -3512,7 +3501,7 @@ def __hash__(self) -> int:
3512
3501
return self .__hash
3513
3502
3514
3503
def __repr__ (self ) -> str :
3515
- return "Requirement.parse(%r)" % str (self )
3504
+ return f "Requirement.parse({ str (self )!r } )"
3516
3505
3517
3506
@staticmethod
3518
3507
def parse (s : str | Iterable [str ]) -> Requirement :
0 commit comments