88import shutil
99import tempfile
1010import uuid
11- from datetime import datetime
11+ from datetime import datetime , timezone
1212from glob import glob
1313from pathlib import Path
1414from subprocess import CalledProcessError
@@ -31,7 +31,8 @@ def bump_version(version_spec, version_cmd, changelog_path):
3131 parsed = parse_version (version )
3232
3333 if util .SETUP_PY .exists () and not hasattr (parsed , "major" ):
34- raise ValueError (f"Invalid version { version } " )
34+ msg = f"Invalid version { version } "
35+ raise ValueError (msg )
3536
3637 # Bail if tag already exists
3738 tag_name = f"v{ version } "
@@ -72,7 +73,8 @@ def draft_changelog(
7273
7374 tags = util .run ("git --no-pager tag" , quiet = True )
7475 if f"v{ version } " in tags .splitlines ():
75- raise ValueError (f"Tag v{ version } already exists" )
76+ msg = f"Tag v{ version } already exists"
77+ raise ValueError (msg )
7678
7779 current = changelog .extract_current (changelog_path )
7880 util .log (f"\n \n Current Changelog Entry:\n { current } " )
@@ -116,8 +118,10 @@ def draft_changelog(
116118 if str (rel .draft ).lower () == "false" :
117119 continue
118120 created = rel .created_at
119- d_created = datetime .strptime (created , r"%Y-%m-%dT%H:%M:%SZ" )
120- delta = datetime .utcnow () - d_created
121+ d_created = datetime .strptime (created , r"%Y-%m-%dT%H:%M:%SZ" ).astimezone (
122+ tz = timezone .utc
123+ )
124+ delta = datetime .now (tz = timezone .utc ) - d_created
121125 if delta .days > 0 :
122126 gh .repos .delete_release (rel .id )
123127
@@ -254,7 +258,8 @@ def delete_release(auth, release_url, dry_run=False):
254258 match = re .match (pattern , release_url )
255259 match = match or re .match (util .RELEASE_API_PATTERN , release_url )
256260 if not match :
257- raise ValueError (f"Release url is not valid: { release_url } " )
261+ msg = f"Release url is not valid: { release_url } "
262+ raise ValueError (msg )
258263
259264 gh = util .get_gh_object (dry_run = dry_run , owner = match ["owner" ], repo = match ["repo" ], token = auth )
260265 release = util .release_for_url (gh , release_url )
@@ -300,14 +305,16 @@ def extract_release(auth, dist_dir, dry_run, release_url):
300305 if asset .name .endswith (".json" ):
301306 continue
302307 if asset .name not in asset_shas :
303- raise ValueError (f"{ asset .name } was not found in asset_shas file" )
308+ msg = f"{ asset .name } was not found in asset_shas file"
309+ raise ValueError (msg )
304310 if util .compute_sha256 (dist / asset .name ) != asset_shas [asset .name ]:
305- raise ValueError (f"sha for { asset .name } does not match asset_shas file" )
311+ msg = f"sha for { asset .name } does not match asset_shas file"
312+ raise ValueError (msg )
306313
307314 os .chdir (orig_dir )
308315
309316
310- def publish_assets (
317+ def publish_assets ( # noqa
311318 dist_dir ,
312319 npm_token ,
313320 npm_cmd ,
@@ -321,7 +328,7 @@ def publish_assets(
321328 """Publish release asset(s)"""
322329 os .environ ["NPM_REGISTRY" ] = npm_registry
323330 os .environ ["TWINE_REPOSITORY_URL" ] = twine_repository_url
324- twine_token = ""
331+ twine_token = "" # noqa
325332
326333 if len (glob (f"{ dist_dir } /*.tgz" )):
327334 npm .handle_npm_config (npm_token )
@@ -330,10 +337,7 @@ def publish_assets(
330337
331338 res = python_package .split (":" )
332339 python_package_path = res [0 ]
333- if len (res ) == 2 :
334- python_package_name = res [1 ].replace ("-" , "_" )
335- else :
336- python_package_name = ""
340+ python_package_name = res [1 ].replace ("-" , "_" ) if len (res ) == 2 else "" # noqa
337341
338342 if release_url and len (glob (f"{ dist_dir } /*.whl" )):
339343 twine_token = python .get_pypi_token (release_url , python_package_path )
@@ -357,10 +361,7 @@ def publish_assets(
357361 suffix = Path (path ).suffix
358362 if suffix in [".gz" , ".whl" ]:
359363 dist : Union [Type [SDist ], Type [Wheel ]]
360- if suffix == ".gz" :
361- dist = SDist
362- else :
363- dist = Wheel
364+ dist = SDist if suffix == ".gz" else Wheel
364365 pkg = dist (path )
365366 if not python_package_name or python_package_name == pkg .name :
366367 env = os .environ .copy ()
@@ -409,7 +410,7 @@ def publish_release(auth, dry_run, release_url):
409410 util .actions_output ("release_url" , release .html_url )
410411
411412
412- def prep_git (ref , branch , repo , auth , username , url ):
413+ def prep_git (ref , branch , repo , auth , username , url ): # noqa
413414 """Set up git"""
414415 repo = repo or util .get_repo ()
415416
@@ -538,7 +539,8 @@ def forwardport_changelog(auth, ref, branch, repo, username, changelog_path, dry
538539 break
539540
540541 if not prev_header :
541- raise ValueError ("No anchor for previous entry" )
542+ msg = "No anchor for previous entry"
543+ raise ValueError (msg )
542544
543545 # Check out the branch again
544546 util .run (f"git checkout -B { branch } origin/{ branch } " )
0 commit comments