File tree Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Expand file tree Collapse file tree 1 file changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ # Copyright (C) 2019-2024 Intel Corporation
2
+ # SPDX-License-Identifier: BSD-3-Clause
3
+
4
+ import os
5
+ from pathlib import Path
6
+ from typing import Union
7
+
8
+
9
+ def is_source_file (filename : Union [str , os .PathLike ]) -> bool :
10
+ """
11
+ Parameters
12
+ ----------
13
+ filename: Union[str, os.Pathlike]
14
+ The filename of a potential source file.
15
+
16
+ Returns
17
+ -------
18
+ bool
19
+ True if the file ends in a recognized extension and False otherwise.
20
+ Only files that can be parsed correctly have recognized extensions.
21
+
22
+ Raises
23
+ ------
24
+ TypeError
25
+ If filename is not a string or Path.
26
+ """
27
+ if not (isinstance (filename , str ) or isinstance (filename , Path )):
28
+ raise TypeError ("filename must be a string or Path" )
29
+
30
+ extension = Path (filename ).suffix
31
+ supported_extensions = [
32
+ ".f90" ,
33
+ ".F90" ,
34
+ ".f" ,
35
+ ".ftn" ,
36
+ ".fpp" ,
37
+ ".F" ,
38
+ ".FOR" ,
39
+ ".FTN" ,
40
+ ".FPP" ,
41
+ ".c" ,
42
+ ".h" ,
43
+ ".c++" ,
44
+ ".cxx" ,
45
+ ".cpp" ,
46
+ ".cc" ,
47
+ ".hpp" ,
48
+ ".hxx" ,
49
+ ".h++" ,
50
+ ".hh" ,
51
+ ".inc" ,
52
+ ".inl" ,
53
+ ".tcc" ,
54
+ ".icc" ,
55
+ ".ipp" ,
56
+ ".cu" ,
57
+ ".cuh" ,
58
+ ".cl" ,
59
+ ".s" ,
60
+ ".S" ,
61
+ ".asm" ,
62
+ ]
63
+ return extension in supported_extensions
You can’t perform that action at this time.
0 commit comments