11# SPDX-License-Identifier: MIT OR Apache-2.0
22# SPDX-FileCopyrightText: The Coding Guidelines Subcommittee Contributors
33
4+
5+ from .common import logger , get_tqdm , bar_format , logging
6+ import time
47import requests
5- import logging
68import re
79import json
8- from pathlib import Path
910from sphinx .errors import SphinxError
1011from sphinx_needs .data import SphinxNeedsData
1112
12- # Get the Sphinx logger
13- logger = logging .getLogger ('sphinx' )
1413fls_paragraph_ids_url = "https://rust-lang.github.io/fls/paragraph-ids.json"
1514
1615class FLSValidationError (SphinxError ):
@@ -88,9 +87,9 @@ def check_fls_exists_and_valid_format(app, env):
8887 # Regular expression for FLS ID validation
8988 # Format: fls_<12 alphanumeric chars including upper and lowercase>
9089 fls_pattern = re .compile (r'^fls_[a-zA-Z0-9]{9,12}$' )
90+
9191 for need_id , need in needs .items ():
9292 logger .debug (f"ID: { need_id } , Need: { need } " )
93-
9493 if need .get ('type' ) == 'guideline' :
9594 fls_value = need .get ("fls" )
9695
@@ -128,9 +127,15 @@ def check_fls_ids_correct(app, env, fls_ids):
128127 # Track any errors found
129128 invalid_ids = []
130129
130+ # prefiltering: this is mainly done for tqdm progress
131+ guidelines = {k : v for k , v in needs .items () if v .get ('type' ) == 'guideline' }
132+
133+ pbar = get_tqdm (iterable = guidelines .items (), desc = "Validating FLS IDs" ,bar_format = bar_format , unit = "need" )
134+
131135 # Check each guideline's FLS reference
132- for need_id , need in needs . items () :
136+ for need_id , need in pbar :
133137 if need .get ('type' ) == 'guideline' :
138+ pbar .set_postfix (fls_id = need_id )
134139 fls_value = need .get ("fls" )
135140
136141 # Skip needs we already validated format for
@@ -141,17 +146,19 @@ def check_fls_ids_correct(app, env, fls_ids):
141146 if fls_value not in fls_ids :
142147 invalid_ids .append ((need_id , fls_value ))
143148 logger .warning (f"Need { need_id } references non-existent FLS ID: '{ fls_value } '" )
144-
145- # Raise error if any invalid IDs were found
146- if invalid_ids :
147- error_message = "The following needs reference non-existent FLS IDs:\n "
148- for need_id , fls_id in invalid_ids :
149- error_message += f" - Need { need_id } references '{ fls_id } '\n "
150- logger .error (error_message )
151- raise FLSValidationError (error_message )
152-
149+
150+ # Raise error if any invalid IDs were found
151+ if invalid_ids :
152+ error_message = "The following needs reference non-existent FLS IDs:\n "
153+ for need_id , fls_id in invalid_ids :
154+ error_message += f" - Need { need_id } references '{ fls_id } '\n "
155+ logger .error (error_message )
156+ raise FLSValidationError (error_message )
157+
153158 logger .info ("All FLS references in guidelines are valid" )
154159
160+ pbar .close () # Ensure cleanup
161+
155162
156163def gather_fls_paragraph_ids (app , json_url ):
157164 """
@@ -308,8 +315,14 @@ def check_fls_lock_consistency(app, env, fls_raw_data):
308315
309316 # Map of FLS IDs to guidelines that reference them
310317 fls_to_guidelines = {}
311- for need_id , need in needs .items ():
318+
319+ # prefiltering: this is mainly done for tqdm progress
320+ guidelines = {k : v for k , v in needs .items () if v .get ('type' ) == 'guideline' }
321+ pbar = get_tqdm (iterable = guidelines .items (), desc = "Checking fls lock consistency" , bar_format = bar_format , unit = "need" )
322+
323+ for need_id , need in pbar :
312324 if need .get ('type' ) == 'guideline' :
325+ pbar .set_postfix (fls_id = need_id )
313326 fls_value = need .get ("fls" )
314327 if fls_value :
315328 if fls_value not in fls_to_guidelines :
0 commit comments