2121from datetime import datetime
2222from glob import glob
2323from urllib .parse import urlparse
24- from urllib .request import urlretrieve
2524
2625import hypothesistooling as tools
2726import hypothesistooling .projects .conjecturerust as cr
2827import hypothesistooling .projects .hypothesispython as hp
2928import hypothesistooling .projects .hypothesisruby as hr
29+ import requests
3030from coverage .config import CoverageConfig
3131from hypothesistooling import installers as install , releasemanagement as rm
3232from hypothesistooling .scripts import pip_tool
@@ -280,13 +280,12 @@ def update_python_versions():
280280 result = subprocess .run (cmd , shell = True , stdout = subprocess .PIPE ).stdout .decode ()
281281 # pyenv reports available versions in chronological order, so we keep the newest
282282 # *unless* our current ends with a digit (is stable) and the candidate does not.
283- digits = tuple ( "0123456789 " )
283+ stable = re . compile ( r".*3\.\d+.\d+$ " )
284284 best = {}
285285 for line in map (str .strip , result .splitlines ()):
286- m = re .match (r"(?:pypy)?3\.(?:[6-9]|\d\d)" , line )
287- if m :
286+ if m := re .match (r"(?:pypy)?3\.(?:[6-9]|\d\d)" , line ):
288287 key = m .group ()
289- if key . endswith ( digits ) or not best .get (key , key ). endswith ( digits ):
288+ if stable . match ( line ) or not stable . match ( best .get (key , line ) ):
290289 best [key ] = line
291290 print (best )
292291 thisfile = pathlib .Path (__file__ )
@@ -309,12 +308,15 @@ def update_python_versions():
309308
310309
311310def update_vendored_files ():
312- for url in [
313- # Turns out that as well as adding new gTLDs, IANA can *terminate* old ones
314- "http://data.iana.org/TLD/tlds-alpha-by-domain.txt" ,
315- ]:
316- fname = urlparse (url ).path .split ("/" )[- 1 ]
317- urlretrieve (url , os .path .join (hp .PYTHON_SRC , "hypothesis" , "vendor" , fname ))
311+ vendor = pathlib .Path (hp .PYTHON_SRC ) / "hypothesis" / "vendor"
312+
313+ # Turns out that as well as adding new gTLDs, IANA can *terminate* old ones
314+ url = "http://data.iana.org/TLD/tlds-alpha-by-domain.txt"
315+ fname = vendor / urlparse (url ).path .split ("/" )[- 1 ]
316+ new = requests .get (url ).content
317+ # If only the timestamp in the header comment has changed, skip the update.
318+ if fname .read_bytes ().splitlines ()[1 :] != new .splitlines ()[1 :]:
319+ fname .write_bytes (new )
318320
319321
320322@task ()
0 commit comments