File tree Expand file tree Collapse file tree 6 files changed +24
-7
lines changed Expand file tree Collapse file tree 6 files changed +24
-7
lines changed Original file line number Diff line number Diff line change @@ -78,6 +78,8 @@ def check_python_h_included_first(name_to_check: str) -> int:
7878 in_comment = False
7979 continue
8080 line = line .split ("//" , 1 )[0 ].strip ()
81+ if len (line ) == 0 :
82+ continue
8183 # Now that there's no comments, look for headers
8284 match = HEADER_PATTERN .match (line )
8385 if match :
@@ -123,7 +125,8 @@ def check_python_h_included_first(name_to_check: str) -> int:
123125 not included_python
124126 and not warned_python_construct
125127 and ".h" not in basename_to_check
126- ) and ("py::" in line or "PYBIND11_" in line ):
128+ ) and ("py::" in line or "PYBIND11_" in line
129+ or " npy_" in line or " Py" in line or line .startswith ("Py" )):
127130 print (
128131 "Python-including header not used before python constructs "
129132 f"in file { name_to_check :s} \n Construct on line { i :d} " ,
@@ -132,4 +135,4 @@ def check_python_h_included_first(name_to_check: str) -> int:
132135 warned_python_construct = True
133136 if not includes_headers :
134137 LEAF_HEADERS .append (basename_to_check )
135- return included_python and len (included_non_python_header )
138+ return ( included_python and len (included_non_python_header )) or warned_python_construct
Original file line number Diff line number Diff line change 1+
2+ const float PI = npy_atanf (1.0 ) * 4f ;
3+
4+ PyMODINIT_Func (& func )
5+ /** I don't actually remember what's supposed to go here
6+ fortunately this doesn't need to compile */
Original file line number Diff line number Diff line change 1+ /** Test file to do things */
2+ #include "myheader.h"
3+
4+ PyMODINIT_Func (& func )
5+ /** I don't actually remember what's supposed to go here
6+ fortunately this doesn't need to compile */
Original file line number Diff line number Diff line change 1- #include <Python.h>
1+ #include <Python.h> // This needs to be first
2+ #include <numpy/npy_common.h>
Original file line number Diff line number Diff line change 1717def test_files (file : str ):
1818 """Test whether function on a single file."""
1919 actual = check_python_h_included_first (file )
20- if os .path .basename (file ).startswith ("system" ):
20+ file_basename = os .path .basename (file )
21+ if file_basename .startswith ("system" ) or file_basename .startswith ("bad" ):
2122 assert actual > 0
2223 else :
2324 assert actual == 0
Original file line number Diff line number Diff line change @@ -42,7 +42,7 @@ def test_process_files():
4242 """
4343 result = process_files (HEADER_LIST + SOURCE_LIST )
4444 assert result == sum (
45- os .path .basename (name ).startswith ("system" )
45+ os .path .basename (name ).startswith ("system" ) or os . path . basename ( name ). startswith ( "bad" )
4646 for name in HEADER_LIST + SOURCE_LIST
4747 )
4848
@@ -55,5 +55,5 @@ def test_process_files():
5555)
5656def test_diff_files ():
5757 """Test whether diff_files picks up the correct files."""
58- new_files = [ os .path .basename (name ) for name in diff_files ("c8bda44" )]
59- assert new_files == [ "system_numpy.c" ]
58+ new_files = { os .path .basename (name ) for name in diff_files ("48eec70" )}
59+ assert new_files == { "myheader.h" , "bad_extension.c" , "good_extension.c" }
You can’t perform that action at this time.
0 commit comments