@@ -106,18 +106,20 @@ def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int:
106106 try :
107107 with urllib .request .urlopen (request ) as response :
108108 if response .status == 200 :
109- content = response .read ().decode ("utf-8" )
109+ content = response .read ().decode ("utf-8" ). rstrip ()
110110 etag = response .headers ["etag" ].strip ('"' )
111111 if etag != data .get ("etag" , "" ):
112112 JSON_SCHEMAS [kind ]["etag" ] = etag
113113 changed += 1
114114 with open (f"{ path } " , "w" , encoding = "utf-8" ) as f_out :
115115 _logger .info ("Schema %s was updated" , kind )
116116 f_out .write (content )
117+ f_out .write ("\n " ) # prettier/editors
117118 f_out .truncate ()
118119 os .fsync (f_out .fileno ())
119120 # unload possibly loaded schema
120- del _schema_cache [kind ]
121+ if kind in _schema_cache :
122+ del _schema_cache [kind ]
121123 except (ConnectionError , OSError ) as exc :
122124 if (
123125 isinstance (exc , urllib .error .HTTPError )
@@ -132,6 +134,7 @@ def refresh_schemas(min_age_seconds: int = 3600 * 24) -> int:
132134 with open (store_file , "w" , encoding = "utf-8" ) as f_out :
133135 # formatting should match our .prettierrc.yaml
134136 json .dump (JSON_SCHEMAS , f_out , indent = 2 , sort_keys = True )
137+ f_out .write ("\n " ) # prettier and editors in general
135138 # clear schema cache
136139 get_schema .cache_clear ()
137140 else :
0 commit comments