@@ -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"
@@ -1316,7 +1314,7 @@ def __iadd__(self, other: Distribution | Environment) -> Self:
1316
1314
for dist in other [project ]:
1317
1315
self .add (dist )
1318
1316
else :
1319
- raise TypeError ("Can't add %r to environment" % ( other ,) )
1317
+ raise TypeError (f "Can't add { other !r } to environment" )
1320
1318
return self
1321
1319
1322
1320
def __add__ (self , other : Distribution | Environment ) -> Self :
@@ -1699,7 +1697,7 @@ def get_metadata(self, name: str) -> str:
1699
1697
except UnicodeDecodeError as exc :
1700
1698
# Include the path in the error message to simplify
1701
1699
# troubleshooting, and without changing the exception type.
1702
- exc .reason += ' in {} file at path: {}' . format ( name , path )
1700
+ exc .reason += f ' in { name } file at path: { path } '
1703
1701
raise
1704
1702
1705
1703
def get_metadata_lines (self , name : str ) -> Iterator [str ]:
@@ -2018,15 +2016,15 @@ def _zipinfo_name(self, fspath):
2018
2016
return ''
2019
2017
if fspath .startswith (self .zip_pre ):
2020
2018
return fspath [len (self .zip_pre ) :]
2021
- raise AssertionError ("%s is not a subpath of %s" % ( fspath , self .zip_pre ) )
2019
+ raise AssertionError (f" { fspath } is not a subpath of { self .zip_pre } " )
2022
2020
2023
2021
def _parts (self , zip_path ):
2024
2022
# Convert a zipfile subpath into an egg-relative path part list.
2025
2023
# pseudo-fs path
2026
2024
fspath = self .zip_pre + zip_path
2027
2025
if fspath .startswith (self .egg_root + os .sep ):
2028
2026
return fspath [len (self .egg_root ) + 1 :].split (os .sep )
2029
- raise AssertionError ("%s is not a subpath of %s" % ( fspath , self .egg_root ) )
2027
+ raise AssertionError (f" { fspath } is not a subpath of { self .egg_root } " )
2030
2028
2031
2029
@property
2032
2030
def zipinfo (self ):
@@ -2729,15 +2727,16 @@ def __init__(
2729
2727
self .dist = dist
2730
2728
2731
2729
def __str__ (self ) -> str :
2732
- s = "%s = %s" % ( self .name , self .module_name )
2730
+ s = f" { self .name } = { self .module_name } "
2733
2731
if self .attrs :
2734
2732
s += ':' + '.' .join (self .attrs )
2735
2733
if self .extras :
2736
- s += ' [%s]' % ',' .join (self .extras )
2734
+ extras = ',' .join (self .extras )
2735
+ s += f' [{ extras } ]'
2737
2736
return s
2738
2737
2739
2738
def __repr__ (self ) -> str :
2740
- return "EntryPoint.parse(%r)" % str (self )
2739
+ return f "EntryPoint.parse({ str (self )!r } )"
2741
2740
2742
2741
@overload
2743
2742
def load (
@@ -3049,9 +3048,7 @@ def version(self):
3049
3048
version = self ._get_version ()
3050
3049
if version is None :
3051
3050
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
- )
3051
+ msg = f"Missing 'Version:' header and/or { self .PKG_INFO } file at path: { path } "
3055
3052
raise ValueError (msg , self ) from e
3056
3053
3057
3054
return version
@@ -3107,9 +3104,7 @@ def requires(self, extras: Iterable[str] = ()) -> list[Requirement]:
3107
3104
try :
3108
3105
deps .extend (dm [safe_extra (ext )])
3109
3106
except KeyError as e :
3110
- raise UnknownExtra (
3111
- "%s has no such extra feature %r" % (self , ext )
3112
- ) from e
3107
+ raise UnknownExtra (f"{ self } has no such extra feature { ext !r} " ) from e
3113
3108
return deps
3114
3109
3115
3110
def _get_metadata_path_for_display (self , name ):
@@ -3150,19 +3145,15 @@ def activate(self, path: list[str] | None = None, replace: bool = False) -> None
3150
3145
3151
3146
def egg_name (self ):
3152
3147
"""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
- )
3148
+ filename = f"{ to_filename (self .project_name )} -{ to_filename (self .version )} -py{ self .py_version or PY_MAJOR } "
3158
3149
3159
3150
if self .platform :
3160
3151
filename += '-' + self .platform
3161
3152
return filename
3162
3153
3163
3154
def __repr__ (self ) -> str :
3164
3155
if self .location :
3165
- return "%s (%s)" % ( self , self .location )
3156
+ return f" { self } ( { self .location } )"
3166
3157
else :
3167
3158
return str (self )
3168
3159
@@ -3172,7 +3163,7 @@ def __str__(self) -> str:
3172
3163
except ValueError :
3173
3164
version = None
3174
3165
version = version or "[unknown version]"
3175
- return "%s %s" % ( self .project_name , version )
3166
+ return f" { self .project_name } { version } "
3176
3167
3177
3168
def __getattr__ (self , attr : str ):
3178
3169
"""Delegate all unrecognized public attributes to .metadata provider"""
@@ -3200,17 +3191,17 @@ def from_filename(
3200
3191
def as_requirement (self ):
3201
3192
"""Return a ``Requirement`` that matches this distribution exactly"""
3202
3193
if isinstance (self .parsed_version , packaging .version .Version ):
3203
- spec = "%s==%s" % ( self .project_name , self .parsed_version )
3194
+ spec = f" { self .project_name } == { self .parsed_version } "
3204
3195
else :
3205
- spec = "%s ===%s" % ( self .project_name , self . parsed_version )
3196
+ spec = f" { self . project_name } ==={ self .parsed_version } "
3206
3197
3207
3198
return Requirement .parse (spec )
3208
3199
3209
3200
def load_entry_point (self , group : str , name : str ) -> _ResolvedEntryPoint :
3210
3201
"""Return the `name` entry point of `group` or raise ImportError"""
3211
3202
ep = self .get_entry_info (group , name )
3212
3203
if ep is None :
3213
- raise ImportError ("Entry point %r not found" % (( group , name ),) )
3204
+ raise ImportError (f "Entry point { ( group , name )!r } not found" )
3214
3205
return ep .load ()
3215
3206
3216
3207
@overload
@@ -3327,8 +3318,8 @@ def check_version_conflict(self):
3327
3318
):
3328
3319
continue
3329
3320
issue_warning (
3330
- "Module %s was already imported from %s, but %s is being added "
3331
- " to sys.path" % ( modname , fn , self . location ) ,
3321
+ f "Module { modname } was already imported from { fn } , "
3322
+ f"but { self . location } is being added to sys.path" ,
3332
3323
)
3333
3324
3334
3325
def has_version (self ) -> bool :
@@ -3512,7 +3503,7 @@ def __hash__(self) -> int:
3512
3503
return self .__hash
3513
3504
3514
3505
def __repr__ (self ) -> str :
3515
- return "Requirement.parse(%r)" % str (self )
3506
+ return f "Requirement.parse({ str (self )!r } )"
3516
3507
3517
3508
@staticmethod
3518
3509
def parse (s : str | Iterable [str ]) -> Requirement :
0 commit comments