@@ -837,7 +837,15 @@ def load_editor_config(self, source_file: Path) -> EditorConfig:
837
837
# See https://editorconfig.org/
838
838
config = EditorConfig ()
839
839
840
- for p in source_file .resolve ().parents :
840
+ if source_file == Path ('STDIN' ):
841
+ raise MesonException ('Using editorconfig with stdin requires --source-file-path argument' )
842
+
843
+ try :
844
+ source_file_path = source_file .resolve ()
845
+ except FileNotFoundError :
846
+ raise MesonException (f'Unable to resolve path for "{ source_file } "' )
847
+
848
+ for p in source_file_path .parents :
841
849
editorconfig_file = p / '.editorconfig'
842
850
if not editorconfig_file .exists ():
843
851
continue
@@ -955,6 +963,11 @@ def add_arguments(parser: argparse.ArgumentParser) -> None:
955
963
type = Path ,
956
964
help = 'output file (implies having exactly one input)'
957
965
)
966
+ parser .add_argument (
967
+ '--source-file-path' ,
968
+ type = Path ,
969
+ help = 'path to use, when reading from stdin'
970
+ )
958
971
parser .add_argument (
959
972
'sources' ,
960
973
nargs = '*' ,
@@ -981,6 +994,10 @@ def run(options: argparse.Namespace) -> int:
981
994
raise MesonException ('--recursive argument is not compatible with stdin input' )
982
995
if options .inplace and from_stdin :
983
996
raise MesonException ('--inplace argument is not compatible with stdin input' )
997
+ if options .source_file_path and not from_stdin :
998
+ raise MesonException ('--source-file-path argument is only compatible with stdin input' )
999
+ if from_stdin and options .editor_config and not options .source_file_path :
1000
+ raise MesonException ('using --editor-config with stdin input requires --source-file-path argument' )
984
1001
985
1002
sources : T .List [Path ] = options .sources .copy () or [Path (build_filename )]
986
1003
@@ -996,7 +1013,7 @@ def run(options: argparse.Namespace) -> int:
996
1013
997
1014
try :
998
1015
if from_stdin :
999
- src_file = Path ('STDIN' ) # used for error messages and introspection
1016
+ src_file = options . source_file_path or Path ('STDIN' ) # used for error messages and introspection
1000
1017
code = sys .stdin .read ()
1001
1018
else :
1002
1019
code = src_file .read_text (encoding = 'utf-8' )
0 commit comments