@@ -20,26 +20,27 @@ def check_fls(app, env):
20
20
"""Main checking function for FLS validation"""
21
21
# First make sure all guidelines have correctly formatted FLS IDs
22
22
check_fls_exists_and_valid_format (app , env )
23
+ offline_mode = env .config .offline
23
24
24
25
# Gather all FLS paragraph IDs from the specification and get the raw JSON
25
- fls_ids , raw_json_data = gather_fls_paragraph_ids (fls_paragraph_ids_url )
26
-
26
+ fls_ids , raw_json_data = gather_fls_paragraph_ids (app , fls_paragraph_ids_url )
27
27
# Error out if we couldn't get the raw JSON data
28
28
if not raw_json_data :
29
29
error_message = f"Failed to retrieve or parse the FLS specification from { fls_paragraph_ids_url } "
30
30
logger .error (error_message )
31
31
raise FLSValidationError (error_message )
32
-
33
- # Check for differences against lock file
34
- has_differences , differences = check_fls_lock_consistency (app , env , raw_json_data )
35
- if has_differences :
36
- error_message = "The FLS specification has changed since the lock file was created:\n "
37
- for diff in differences :
38
- error_message += f" - { diff } \n "
39
- error_message += "\n Please manually inspect FLS spec items whose checksums have changed as corresponding guidelines may need to account for these changes."
40
- logger .error (error_message )
41
- raise FLSValidationError (error_message )
42
-
32
+
33
+ if not offline_mode : # in offline_mode we ignore checking against the lock file
34
+ # Check for differences against lock file
35
+ has_differences , differences = check_fls_lock_consistency (app , env , raw_json_data )
36
+ if has_differences :
37
+ error_message = "The FLS specification has changed since the lock file was created:\n "
38
+ for diff in differences :
39
+ error_message += f" - { diff } \n "
40
+ error_message += "\n Please manually inspect FLS spec items whose checksums have changed as corresponding guidelines may need to account for these changes."
41
+ logger .error (error_message )
42
+ raise FLSValidationError (error_message )
43
+
43
44
# Check if all referenced FLS IDs exist
44
45
check_fls_ids_correct (app , env , fls_ids )
45
46
@@ -152,7 +153,7 @@ def check_fls_ids_correct(app, env, fls_ids):
152
153
logger .info ("All FLS references in guidelines are valid" )
153
154
154
155
155
- def gather_fls_paragraph_ids (json_url ):
156
+ def gather_fls_paragraph_ids (app , json_url ):
156
157
"""
157
158
Gather all Ferrocene Language Specification paragraph IDs from the paragraph-ids.json file,
158
159
including both container section IDs and individual paragraph IDs.
@@ -164,25 +165,36 @@ def gather_fls_paragraph_ids(json_url):
164
165
Dictionary mapping paragraph IDs to metadata AND the complete raw JSON data
165
166
"""
166
167
logger .info ("Gathering FLS paragraph IDs from %s" , json_url )
168
+ offline = app .config .offline
169
+ lock_path = app .confdir / 'fls.lock'
167
170
168
171
# Dictionary to store all FLS IDs and their metadata
169
172
all_fls_ids = {}
170
173
raw_json_data = None
171
174
172
175
try :
173
176
# Load the JSON file
174
- response = requests .get (json_url )
175
- response .raise_for_status () # Raise exception for HTTP errors
176
-
177
- # Parse the JSON data
178
- try :
179
- raw_json_data = response .json ()
180
- data = raw_json_data # Keep reference to the original data
181
- logger .debug ("Successfully parsed JSON data" )
182
- except json .JSONDecodeError as e :
183
- logger .error (f"Failed to parse JSON: { e } " )
184
- logger .debug (f"Response content preview: { response .text [:500 ]} ..." )
185
- raise
177
+ if not offline :
178
+ response = requests .get (json_url )
179
+ response .raise_for_status () # Raise exception for HTTP errors
180
+ # Parse the JSON data
181
+ try :
182
+ raw_json_data = response .json ()
183
+ data = raw_json_data # Keep reference to the original data
184
+ logger .debug ("Successfully parsed JSON data" )
185
+ except json .JSONDecodeError as e :
186
+ logger .error (f"Failed to parse JSON: { e } " )
187
+ logger .debug (f"Response content preview: { response .text [:500 ]} ..." )
188
+ raise
189
+
190
+ else : # if online mode is on read from the lock file
191
+ if not lock_path .exists ():
192
+ logger .warning (f"No FLS lock file found at { lock_path } " ) # TODO: returns an error
193
+ return False , []
194
+ with open (lock_path , 'r' , encoding = 'utf-8' ) as f :
195
+ raw_json_data = f .read ()
196
+ data = json .loads (raw_json_data )
197
+
186
198
187
199
# Check if we have the expected document structure
188
200
if 'documents' not in data :
0 commit comments