10000 BLD Generate warning automatically for templated cython files (#25842) · jeremiedbb/scikit-learn@30f30cd · GitHub
[go: up one dir, main page]

Skip to content

Commit 30f30cd

Browse files
authored
BLD Generate warning automatically for templated cython files (scikit-learn#25842)
1 parent 683028f commit 30f30cd

File tree

8 files changed

+18
-45
lines changed

8 files changed

+18
-45
lines changed

sklearn/_build_utils/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,5 +103,12 @@ def gen_from_templates(templates):
103103

104104
tmpl_ = Tempita.sub(tmpl)
105105

106+
warn_msg = (
107+
"# WARNING: Do not edit this file directly.\n"
108+
f"# It is automatically generated from {template!r}.\n"
109+
"# Changes must be made there.\n\n"
110+
)
111+
106112
with open(outfile, "w") as f:
113+
f.write(warn_msg)
107114
f.write(tmpl_)

sklearn/_loss/_loss.pyx.tp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,6 @@ class_list = [
181181
"cgradient_half_binomial", "cgrad_hess_half_binomial"),
182182
]
183183
}}
184-
"""
185-
WARNING: Do not edit `sklearn/_loss/_loss.pyx` file directly, as it is generated from
186-
`sklearn/_loss/_loss.pyx.tp`. Changes must be made there.
187-
"""
188-
#------------------------------------------------------------------------------
189184

190185
# Design:
191186
# See https://github.com/scikit-learn/scikit-learn/issues/15123 for reasons.

sklearn/linear_model/_sag_fast.pyx.tp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,7 @@ dtypes = [('64', 'double', 'np.float64'),
2424
('32', 'float', 'np.float32')]
2525

2626
}}
27-
28-
#------------------------------------------------------------------------------
29-
30-
# Authors: Danny Sullivan <dbsullivan23@gmail.com>
31-
# Tom Dupre la Tour <tom.dupre-la-tour@m4x.org>
32-
# Arthur Mensch <arthur.mensch@m4x.org
33-
#
34-
# License: BSD 3 clause
35-
36-
"""
37-
SAG and SAGA implementation
38-
WARNING: Do not edit .pyx file directly, it is generated from .pyx.tp
39-
"""
27+
"""SAG and SAGA implementation"""
4028

4129
import numpy as np
4230
from libc.math cimport fabs, exp, log

sklearn/linear_model/_sgd_fast.pyx.tp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ dtypes = [
2424
]
2525

2626
}}
27-
28-
#------------------------------------------------------------------------------
29-
30-
"""
31-
SGD implementation
32-
WARNING: Do not edit .pyx file directly, it is generated from .pyx.tp
33-
"""
27+
"""SGD implementation"""
3428

3529
from cython cimport floating
3630
import numpy as np

sklearn/utils/_seq_dataset.pxd.tp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,16 @@ dtypes = [('64', 'double'),
1717
('32', 'float')]
1818

1919
}}
20-
{{for name_suffix, c_type in dtypes}}
21-
22-
#------------------------------------------------------------------------------
23-
24-
"""
25-
Dataset abstractions for sequential data access.
26-
WARNING: Do not edit .pxd file directly, it is generated from .pxd.tp
27-
"""
20+
"""Dataset abstractions for sequential data access."""
2821

2922
cimport numpy as cnp
3023

3124
# SequentialDataset and its two concrete subclasses are (optionally randomized)
3225
# iterators over the rows of a matrix X and corresponding target values y.
3326

27+
{{for name_suffix, c_type in dtypes}}
28+
29+
#------------------------------------------------------------------------------
3430

3531
cdef class SequentialDataset{{name_suffix}}:
3632
cdef int current_index

sklearn/utils/_seq_dataset.pyx.tp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,7 @@ dtypes = [('64', 'double', 'np.float64'),
2222
('32', 'float', 'np.float32')]
2323

2424
}}
25-
{{for name_suffix, c_type, np_type in dtypes}}
26-
27-
#------------------------------------------------------------------------------
28-
29-
"""
30-
Dataset abstractions for sequential data access.
31-
WARNING: Do not edit .pyx file directly, it is generated from .pyx.tp
32-
"""
25+
"""Dataset abstractions for sequential data access."""
3326

3427
cimport cython
3528
from libc.limits cimport INT_MAX
@@ -40,6 +33,10 @@ cnp.import_array()
4033

4134
from ._random cimport our_rand_r
4235

36+
{{for name_suffix, c_type, np_type in dtypes}}
37+
38+
#------------------------------------------------------------------------------
39+
4340
cdef class SequentialDataset{{name_suffix}}:
4441
"""Base class for datasets with sequential data access.
4542

sklearn/utils/_weight_vector.pxd.tp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ dtypes = [('64', 'double'),
1818

1919
}}
2020

21-
# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp
22-
2321
{{for name_suffix, c_type in dtypes}}
2422

2523
cdef class WeightVector{{name_suffix}}(object):

sklearn/utils/_weight_vector.pyx.tp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ dtypes = [('64', 'double', 1e-9),
2626
#
2727
# License: BSD 3 clause
2828

29-
# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp
30-
3129
cimport cython
3230
from libc.limits cimport INT_MAX
3331
from libc.math cimport sqrt

0 commit comments

Comments
 (0)
0