Skip to content

Commit 97ca807

Browse files
authored
Add support for primitive json comments (#37)
To provide some support for comments within the test configs a simple JSON with comments decoder class has been introduced. This only provides support for leading // style comments in an effort to remain lightweight and work with native Python installs, no dependencies on external packages. This should prove sufficient to allow a modicum of annotation to test configs.
2 parents e5d2d0d + dbd96d8 commit 97ca807

2 files changed

Lines changed: 21 additions & 9 deletions

File tree

.ci/JSONCDecoder.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# https://stackoverflow.com/a/72168909
2+
import json
3+
from typing import Any
4+
class JSONCDecoder( json.JSONDecoder ):
5+
def __init__( self, **kw ) :
6+
super().__init__( **kw )
7+
8+
def decode( self, s : str ) -> Any :
9+
# Sanitize the input string for leading // comments ONLY and replace with
10+
# blank line so that line numbers are preserved
11+
s = '\n'.join( l if not l.lstrip().startswith( "//" ) else "" for l in s.split( '\n' ) )
12+
return super().decode( s )

.ci/runner.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from contextlib import redirect_stdout
1313
from datetime import timedelta
1414

15-
15+
import JSONCDecoder
1616
import SubmitCommon as sc
1717

1818
from SubmitAction import SubmitAction
@@ -518,7 +518,7 @@ def runSuite( options ) :
518518
with redirect_stdout( redirect ) :
519519
testSuite = Suite(
520520
basename,
521-
json.load( fp ),
521+
json.load( fp, cls=JSONCDecoder.JSONCDecoder ),
522522
opts,
523523
options,
524524
parent=options.globalPrefix,
@@ -529,13 +529,13 @@ def runSuite( options ) :
529529
# print( options.message )
530530
else :
531531
testSuite = Suite(
532-
basename,
533-
json.load( fp ),
534-
opts,
535-
options,
536-
parent=options.globalPrefix,
537-
rootDir=root
538-
)
532+
basename,
533+
json.load( fp, cls=JSONCDecoder.JSONCDecoder ),
534+
opts,
535+
options,
536+
parent=options.globalPrefix,
537+
rootDir=root
538+
)
539539
success, logs = testSuite.run( options.tests )
540540
# if success and options.message :
541541
# print( options.message )

0 commit comments

Comments
 (0)