Skip to content

Commit

Permalink
CI: Check whether Python.h is included first in a file (scipy#20536)
Browse files Browse the repository at this point in the history
Based on script from scipy#20149.

Co-authored-by: Ralf Gommers <ralf.gommers@gmail.com>
  • Loading branch information
DWesl and rgommers committed Apr 23, 2024
1 parent 587c562 commit d55cb95
Show file tree
Hide file tree
Showing 12 changed files with 266 additions and 30 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,8 @@ jobs:
python tools/lint.py --diff-against origin/$GITHUB_BASE_REF
python tools/unicode-check.py
python tools/check_test_name.py
- name: Check that Python.h is first in any file including it.
shell: bash
run: |
python tools/check_python_h_first.py
18 changes: 18 additions & 0 deletions dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,23 @@ def task_lint(fix):
'doc': 'Lint only files modified since last commit (stricter rules)',
}

@task_params([])
def task_check_python_h_first():
# Lint just the diff since branching off of main using a
# stricter configuration.
# emit_cmdstr(os.path.join('tools', 'lint.py') + ' --diff-against main')
cmd = "{!s} --diff-against=main".format(
Dirs().root / 'tools' / 'check_python_h_first.py'
)
return {
'basename': 'check_python_h_first',
'actions': [cmd],
'doc': (
'Check Python.h order only files modified since last commit '
'(stricter rules)'
),
}


def task_unicode_check():
# emit_cmdstr(os.path.join('tools', 'unicode-check.py'))
Expand Down Expand Up @@ -955,6 +972,7 @@ def run(cls, fix):
'lint': {'fix': fix},
'unicode-check': {},
'check-testname': {},
'check_python_h_first': {},
})


Expand Down
5 changes: 2 additions & 3 deletions scipy/io/_fast_matrix_market/src/_fmm_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
// Use of this source code is governed by the BSD 2-clause license found in the LICENSE.txt file.
// SPDX-License-Identifier: BSD-2-Clause

#include <Python.h>
#include "_fmm_core.hpp"

#include <fast_matrix_market/types.hpp>
#include <cstdint>
namespace fast_matrix_market {
Expand All @@ -17,8 +18,6 @@ namespace fast_matrix_market {
}
#include <fast_matrix_market/fast_matrix_market.hpp>

#include "_fmm_core.hpp"

////////////////////////////////////////////////
//// Header methods
////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion scipy/optimize/_pava/pava_pybind.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include <tuple>
#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>
#include <numpy/arrayobject.h>
#include <tuple>

namespace py = pybind11;

Expand Down
6 changes: 3 additions & 3 deletions scipy/spatial/ckdtree/src/count_neighbors.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "ckdtree_decl.h"
#include "rectangle.h"

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand All @@ -11,9 +14,6 @@
#include <stdexcept>
#include <ios>

#include "ckdtree_decl.h"
#include "rectangle.h"

struct WeightedTree {
const ckdtree *tree;
double *weights;
Expand Down
8 changes: 4 additions & 4 deletions scipy/spatial/ckdtree/src/query.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "ckdtree_decl.h"
#include "ordered_pair.h"
#include "rectangle.h"

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand All @@ -10,10 +14,6 @@
#include <stdexcept>
#include <ios>

#include "ckdtree_decl.h"
#include "ordered_pair.h"
#include "rectangle.h"

/*
* Priority queue
* ==============
Expand Down
6 changes: 3 additions & 3 deletions scipy/spatial/ckdtree/src/query_ball_point.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "ckdtree_decl.h"
#include "rectangle.h"

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand All @@ -11,9 +14,6 @@
#include <stdexcept>
#include <ios>

#include "ckdtree_decl.h"
#include "rectangle.h"


static void
traverse_no_checking(const ckdtree *self,
Expand Down
6 changes: 3 additions & 3 deletions scipy/spatial/ckdtree/src/query_ball_tree.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include "ckdtree_decl.h"
#include "rectangle.h"

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand All @@ -11,9 +14,6 @@
#include <stdexcept>
#include <ios>

#include "ckdtree_decl.h"
#include "rectangle.h"


static void
traverse_no_checking(const ckdtree *self, const ckdtree *other,
Expand Down
8 changes: 4 additions & 4 deletions scipy/spatial/ckdtree/src/query_pairs.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "ckdtree_decl.h"
#include "ordered_pair.h"
#include "rectangle.h"

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand All @@ -10,10 +14,6 @@
#include <stdexcept>
#include <ios>

#include "ckdtree_decl.h"
#include "ordered_pair.h"
#include "rectangle.h"


static void
traverse_no_checking(const ckdtree *self,
Expand Down
8 changes: 4 additions & 4 deletions scipy/spatial/ckdtree/src/sparse_distances.cxx
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#include "ckdtree_decl.h"
#include "rectangle.h"
#include "coo_entries.h"

#include <cmath>
#include <cstdlib>
#include <cstring>
Expand All @@ -10,10 +14,6 @@
#include <stdexcept>
#include <ios>

#include "ckdtree_decl.h"
#include "rectangle.h"
#include "coo_entries.h"

template <typename MinMaxDist> static void
traverse(const ckdtree *self, const ckdtree *other,
std::vector<coo_entry> *results,
Expand Down
5 changes: 0 additions & 5 deletions scipy/special/sf_error.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#include <Python.h>

#include <stdarg.h>
#include <stdlib.h>

#include <Python.h>
#include <numpy/npy_math.h>

Expand Down

0 comments on commit d55cb95

Please sign in to comment.