Skip to content

BLD Generate warning automatically for templated cython files #25842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions sklearn/_build_utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,12 @@ def gen_from_templates(templates):

tmpl_ = Tempita.sub(tmpl)

warn_msg = (
"# WARNING: Do not edit this file directly.\n"
f"# It is automatically generated from {template!r}.\n"
"# Changes must be made there.\n\n"
)

with open(outfile, "w") as f:
f.write(warn_msg)
f.write(tmpl_)
5 changes: 0 additions & 5 deletions sklearn/_loss/_loss.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,6 @@ class_list = [
"cgradient_half_binomial", "cgrad_hess_half_binomial"),
]
}}
"""
WARNING: Do not edit `sklearn/_loss/_loss.pyx` file directly, as it is generated from
`sklearn/_loss/_loss.pyx.tp`. Changes must be made there.
"""
#------------------------------------------------------------------------------

# Design:
# See https://github.com/scikit-learn/scikit-learn/issues/15123 for reasons.
Expand Down
14 changes: 1 addition & 13 deletions sklearn/linear_model/_sag_fast.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,7 @@ dtypes = [('64', 'double', 'np.float64'),
('32', 'float', 'np.float32')]

}}

#------------------------------------------------------------------------------

# Authors: Danny Sullivan <dbsullivan23@gmail.com>
# Tom Dupre la Tour <tom.dupre-la-tour@m4x.org>
# Arthur Mensch <arthur.mensch@m4x.org
#
# License: BSD 3 clause
Comment on lines -30 to -34
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here I just removed the duplicate. Authors are already listed just above


"""
SAG and SAGA implementation
WARNING: Do not edit .pyx file directly, it is generated from .pyx.tp
"""
"""SAG and SAGA implementation"""

import numpy as np
from libc.math cimport fabs, exp, log
Expand Down
8 changes: 1 addition & 7 deletions sklearn/linear_model/_sgd_fast.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ dtypes = [
]

}}

#------------------------------------------------------------------------------

"""
SGD implementation
WARNING: Do not edit .pyx file directly, it is generated from .pyx.tp
"""
"""SGD implementation"""

from cython cimport floating
import numpy as np
Expand Down
12 changes: 4 additions & 8 deletions sklearn/utils/_seq_dataset.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,16 @@ dtypes = [('64', 'double'),
('32', 'float')]

}}
{{for name_suffix, c_type in dtypes}}

#------------------------------------------------------------------------------

"""
Dataset abstractions for sequential data access.
WARNING: Do not edit .pxd file directly, it is generated from .pxd.tp
"""
"""Dataset abstractions for sequential data access."""

cimport numpy as cnp

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

{{for name_suffix, c_type in dtypes}}

#------------------------------------------------------------------------------

cdef class SequentialDataset{{name_suffix}}:
cdef int current_index
Expand Down
13 changes: 5 additions & 8 deletions sklearn/utils/_seq_dataset.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ dtypes = [('64', 'double', 'np.float64'),
('32', 'float', 'np.float32')]

}}
{{for name_suffix, c_type, np_type in dtypes}}

#------------------------------------------------------------------------------

"""
Dataset abstractions for sequential data access.
WARNING: Do not edit .pyx file directly, it is generated from .pyx.tp
"""
"""Dataset abstractions for sequential data access."""

cimport cython
from libc.limits cimport INT_MAX
Expand All @@ -40,6 +33,10 @@ cnp.import_array()

from ._random cimport our_rand_r

{{for name_suffix, c_type, np_type in dtypes}}

#------------------------------------------------------------------------------

cdef class SequentialDataset{{name_suffix}}:
"""Base class for datasets with sequential data access.

Expand Down
2 changes: 0 additions & 2 deletions sklearn/utils/_weight_vector.pxd.tp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ dtypes = [('64', 'double'),

}}

# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp

{{for name_suffix, c_type in dtypes}}

cdef class WeightVector{{name_suffix}}(object):
Expand Down
2 changes: 0 additions & 2 deletions sklearn/utils/_weight_vector.pyx.tp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ dtypes = [('64', 'double', 1e-9),
#
# License: BSD 3 clause

# WARNING: Do not edit this .pyx file directly, it is generated from its .pyx.tp

cimport cython
from libc.limits cimport INT_MAX
from libc.math cimport sqrt
Expand Down