@@ -20,28 +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
- 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
- error_message += "\n Once resolved, you may run the following to update the local spec lock file:"
41
- error_message += "\n \t ./make.py --update-spec-lock-file"
42
- logger .error (error_message )
43
- raise FLSValidationError (error_message )
44
-
31
+ raise FLSValidationError (error_message )
32
+ if not offline_mode : # in offline mode, ignore checking against the lock file
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
+ error_message += "\n Once resolved, you may run the following to update the local spec lock file:"
41
+ error_message += "\n \t ./make.py --update-spec-lock-file"
42
+ logger .error (error_message )
43
+ raise FLSValidationError (error_message )
45
44
# Check if all referenced FLS IDs exist
46
45
check_fls_ids_correct (app , env , fls_ids )
47
46
@@ -154,7 +153,7 @@ def check_fls_ids_correct(app, env, fls_ids):
154
153
logger .info ("All FLS references in guidelines are valid" )
155
154
156
155
157
- def gather_fls_paragraph_ids (json_url ):
156
+ def gather_fls_paragraph_ids (app , json_url ):
158
157
"""
159
158
Gather all Ferrocene Language Specification paragraph IDs from the paragraph-ids.json file,
160
159
including both container section IDs and individual paragraph IDs.
@@ -166,25 +165,36 @@ def gather_fls_paragraph_ids(json_url):
166
165
Dictionary mapping paragraph IDs to metadata AND the complete raw JSON data
167
166
"""
168
167
logger .info ("Gathering FLS paragraph IDs from %s" , json_url )
168
+ offline = app .config .offline
169
+ lock_path = app .confdir / 'fls.lock'
169
170
170
171
# Dictionary to store all FLS IDs and their metadata
171
172
all_fls_ids = {}
172
173
raw_json_data = None
173
174
174
175
try :
175
176
# Load the JSON file
176
- response = requests .get (json_url )
177
- response .raise_for_status () # Raise exception for HTTP errors
178
-
179
- # Parse the JSON data
180
- try :
181
- raw_json_data = response .json ()
182
- data = raw_json_data # Keep reference to the original data
183
- logger .debug ("Successfully parsed JSON data" )
184
- except json .JSONDecodeError as e :
185
- logger .error (f"Failed to parse JSON: { e } " )
186
- logger .debug (f"Response content preview: { response .text [:500 ]} ..." )
187
- 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
+
188
198
189
199
# Check if we have the expected document structure
190
200
if 'documents' not in data :
0 commit comments