11#!/usr/bin/env python3
22
3+ import json
34import re
45import sys
56import urllib .request
6- import json
77from datetime import datetime
88
9+
910def parse_nightly_version (nightly_version ):
1011 """
1112 Parse NIGHTLY_VERSION (e.g., 'dev20251004') to date string (e.g., '2025-10-04').
@@ -16,21 +17,22 @@ def parse_nightly_version(nightly_version):
1617 Returns:
1718 Date string in format 'YYYY-MM-DD'
1819 """
19- match = re .match (r' dev(\d{4})(\d{2})(\d{2})' , nightly_version )
20+ match = re .match (r" dev(\d{4})(\d{2})(\d{2})" , nightly_version )
2021 if not match :
2122 raise ValueError (f"Invalid NIGHTLY_VERSION format: { nightly_version } " )
2223
2324 year , month , day = match .groups ()
2425 return f"{ year } -{ month } -{ day } "
2526
27+
2628def get_torch_nightly_version ():
2729 """
2830 Read NIGHTLY_VERSION from torch_pin.py.
2931
3032 Returns:
3133 NIGHTLY_VERSION string
3234 """
33- with open (' torch_pin.py' , 'r' ) as f :
35+ with open (" torch_pin.py" , "r" ) as f :
3436 content = f .read ()
3537
3638 match = re .search (r'NIGHTLY_VERSION\s*=\s*["\']([^"\']+)["\']' , content )
@@ -39,6 +41,7 @@ def get_torch_nightly_version():
3941
4042 return match .group (1 )
4143
44+
4245def get_commit_hash_for_nightly (date_str ):
4346 """
4447 Fetch commit hash from PyTorch nightly branch for a given date.
@@ -54,8 +57,8 @@ def get_commit_hash_for_nightly(date_str):
5457 url = api_url + params
5558
5659 req = urllib .request .Request (url )
57- req .add_header (' Accept' , ' application/vnd.github.v3+json' )
58- req .add_header (' User-Agent' , ' ExecuTorch-Bot' )
60+ req .add_header (" Accept" , " application/vnd.github.v3+json" )
61+ req .add_header (" User-Agent" , " ExecuTorch-Bot" )
5962
6063 try :
6164 with urllib .request .urlopen (req ) as response :
@@ -68,13 +71,16 @@ def get_commit_hash_for_nightly(date_str):
6871 target_title = f"{ date_str } nightly release"
6972
7073 for commit in commits :
71- commit_msg = commit .get (' commit' , {}).get (' message' , '' )
74+ commit_msg = commit .get (" commit" , {}).get (" message" , "" )
7275 # Check if the first line of commit message matches
73- first_line = commit_msg .split (' \n ' )[0 ].strip ()
76+ first_line = commit_msg .split (" \n " )[0 ].strip ()
7477 if first_line == target_title or first_line .startswith (f"{ date_str } nightly" ):
75- return commit ['sha' ]
78+ return commit ["sha" ]
79+
80+ raise ValueError (
81+ f"Could not find commit with title matching '{ target_title } ' in nightly branch"
82+ )
7683
77- raise ValueError (f"Could not find commit with title matching '{ target_title } ' in nightly branch" )
7884
7985def update_pytorch_pin (commit_hash ):
8086 """
@@ -83,11 +89,12 @@ def update_pytorch_pin(commit_hash):
8389 Args:
8490 commit_hash: Commit hash to write
8591 """
86- pin_file = ' .ci/docker/ci_commit_pins/pytorch.txt'
87- with open (pin_file , 'w' ) as f :
92+ pin_file = " .ci/docker/ci_commit_pins/pytorch.txt"
93+ with open (pin_file , "w" ) as f :
8894 f .write (f"{ commit_hash } \n " )
8995 print (f"Updated { pin_file } with commit hash: { commit_hash } " )
9096
97+
9198def main ():
9299 try :
93100 # Read NIGHTLY_VERSION from torch_pin.py
@@ -111,5 +118,6 @@ def main():
111118 print (f"Error: { e } " , file = sys .stderr )
112119 sys .exit (1 )
113120
114- if __name__ == '__main__' :
121+
122+ if __name__ == "__main__" :
115123 main ()
0 commit comments