Merge branch 'master' into smart_holder

This commit is contained in:
Ralf W. Grosse-Kunstleve 2022-06-27 22:24:23 -07:00
commit cad2609381
7 changed files with 36 additions and 22 deletions

View File

@ -10,6 +10,7 @@ cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-slicing, cppcoreguidelines-slicing,
google-explicit-constructor, google-explicit-constructor,
llvm-namespace-comment, llvm-namespace-comment,
misc-definitions-in-headers,
misc-misplaced-const, misc-misplaced-const,
misc-non-copyable-objects, misc-non-copyable-objects,
misc-static-assert, misc-static-assert,
@ -17,6 +18,7 @@ misc-throw-by-value-catch-by-reference,
misc-uniqueptr-reset-release, misc-uniqueptr-reset-release,
misc-unused-parameters, misc-unused-parameters,
modernize-avoid-bind, modernize-avoid-bind,
modernize-loop-convert,
modernize-make-shared, modernize-make-shared,
modernize-redundant-void-arg, modernize-redundant-void-arg,
modernize-replace-auto-ptr, modernize-replace-auto-ptr,
@ -63,6 +65,8 @@ readability-uniqueptr-delete-release,
CheckOptions: CheckOptions:
- key: performance-for-range-copy.WarnOnAllAutoCopies - key: performance-for-range-copy.WarnOnAllAutoCopies
value: true value: true
- key: performance-inefficient-string-concatenation.StrictMode
value: true
- key: performance-unnecessary-value-param.AllowedTypes - key: performance-unnecessary-value-param.AllowedTypes
value: 'exception_ptr$;' value: 'exception_ptr$;'
- key: readability-implicit-bool-conversion.AllowPointerConditions - key: readability-implicit-bool-conversion.AllowPointerConditions

View File

@ -585,19 +585,25 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
centos: container:
- centos7 # GCC 4.8 - "centos:7" # GCC 4.8
- stream8 - "almalinux:8"
- "almalinux:9"
name: "🐍 3 • CentOS ${{ matrix.centos }} • x64" name: "🐍 3 • ${{ matrix.container }} • x64"
container: "quay.io/centos/centos:${{ matrix.centos }}" container: "${{ matrix.container }}"
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Add Python 3 - name: Add Python 3 (RHEL 7)
if: matrix.container == 'centos:7'
run: yum update -y && yum install -y python3-devel gcc-c++ make git run: yum update -y && yum install -y python3-devel gcc-c++ make git
- name: Add Python 3 (RHEL 8+)
if: matrix.container != 'centos:7'
run: dnf update -y && dnf install -y python3-devel gcc-c++ make git
- name: Update pip - name: Update pip
run: python3 -m pip install --upgrade pip run: python3 -m pip install --upgrade pip

View File

@ -25,7 +25,7 @@ jobs:
- uses: actions/setup-python@v3 - uses: actions/setup-python@v3
- name: Add matchers - name: Add matchers
run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json" run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
- uses: pre-commit/action@v2.0.3 - uses: pre-commit/action@v3.0.0
with: with:
# Slow hooks are marked with manual - slow is okay here, run them too # Slow hooks are marked with manual - slow is okay here, run them too
extra_args: --hook-stage manual --all-files extra_args: --hook-stage manual --all-files

View File

@ -15,7 +15,7 @@
repos: repos:
# Standard hooks # Standard hooks
- repo: https://github.com/pre-commit/pre-commit-hooks - repo: https://github.com/pre-commit/pre-commit-hooks
rev: "v4.2.0" rev: "v4.3.0"
hooks: hooks:
- id: check-added-large-files - id: check-added-large-files
- id: check-case-conflict - id: check-case-conflict
@ -33,7 +33,7 @@ repos:
# Upgrade old Python syntax # Upgrade old Python syntax
- repo: https://github.com/asottile/pyupgrade - repo: https://github.com/asottile/pyupgrade
rev: "v2.32.1" rev: "v2.34.0"
hooks: hooks:
- id: pyupgrade - id: pyupgrade
args: [--py36-plus] args: [--py36-plus]
@ -60,7 +60,7 @@ repos:
# Changes tabs to spaces # Changes tabs to spaces
- repo: https://github.com/Lucas-C/pre-commit-hooks - repo: https://github.com/Lucas-C/pre-commit-hooks
rev: "v1.1.13" rev: "v1.2.0"
hooks: hooks:
- id: remove-tabs - id: remove-tabs
exclude: (^docs/.*|\.patch)?$ exclude: (^docs/.*|\.patch)?$
@ -73,7 +73,7 @@ repos:
# Autoremoves unused imports # Autoremoves unused imports
- repo: https://github.com/hadialqattan/pycln - repo: https://github.com/hadialqattan/pycln
rev: "v1.3.2" rev: "v1.3.5"
hooks: hooks:
- id: pycln - id: pycln
stages: [manual] stages: [manual]
@ -110,7 +110,7 @@ repos:
# PyLint has native support - not always usable, but works for us # PyLint has native support - not always usable, but works for us
- repo: https://github.com/PyCQA/pylint - repo: https://github.com/PyCQA/pylint
rev: "v2.13.8" rev: "v2.14.3"
hooks: hooks:
- id: pylint - id: pylint
files: ^pybind11 files: ^pybind11
@ -126,7 +126,7 @@ repos:
# Check static types with mypy # Check static types with mypy
- repo: https://github.com/pre-commit/mirrors-mypy - repo: https://github.com/pre-commit/mirrors-mypy
rev: "v0.950" rev: "v0.961"
hooks: hooks:
- id: mypy - id: mypy
args: [] args: []
@ -167,7 +167,7 @@ repos:
# Clang format the codebase automatically # Clang format the codebase automatically
- repo: https://github.com/pre-commit/mirrors-clang-format - repo: https://github.com/pre-commit/mirrors-clang-format
rev: "v14.0.3" rev: "v14.0.5"
hooks: hooks:
- id: clang-format - id: clang-format
types_or: [c++, c, cuda] types_or: [c++, c, cuda]

View File

@ -99,7 +99,7 @@ public:
Return operator()(Args... args) const { Return operator()(Args... args) const {
gil_scoped_acquire acq; gil_scoped_acquire acq;
// casts the returned object as a rvalue to the return type // casts the returned object as a rvalue to the return type
return object(hfunc.f(std::forward<Args>(args)...)).template cast<Return>(); return hfunc.f(std::forward<Args>(args)...).template cast<Return>();
} }
}; };

View File

@ -604,7 +604,7 @@ public:
} }
/// type number of dtype. /// type number of dtype.
ssize_t num() const { int num() const {
// Note: The signature, `dtype::num` follows the naming of NumPy's public // Note: The signature, `dtype::num` follows the naming of NumPy's public
// Python API (i.e., ``dtype.num``), rather than its internal // Python API (i.e., ``dtype.num``), rather than its internal
// C API (``PyArray_Descr::type_num``). // C API (``PyArray_Descr::type_num``).
@ -641,10 +641,14 @@ private:
pybind11::str name; pybind11::str name;
object format; object format;
pybind11::int_ offset; pybind11::int_ offset;
field_descr(pybind11::str &&name, object &&format, pybind11::int_ &&offset)
: name{std::move(name)}, format{std::move(format)}, offset{std::move(offset)} {};
}; };
auto field_dict = attr("fields").cast<dict>();
std::vector<field_descr> field_descriptors; std::vector<field_descr> field_descriptors;
field_descriptors.reserve(field_dict.size());
for (auto field : attr("fields").attr("items")()) { for (auto field : field_dict.attr("items")()) {
auto spec = field.cast<tuple>(); auto spec = field.cast<tuple>();
auto name = spec[0].cast<pybind11::str>(); auto name = spec[0].cast<pybind11::str>();
auto spec_fo = spec[1].cast<tuple>(); auto spec_fo = spec[1].cast<tuple>();
@ -653,8 +657,8 @@ private:
if ((len(name) == 0u) && format.kind() == 'V') { if ((len(name) == 0u) && format.kind() == 'V') {
continue; continue;
} }
field_descriptors.push_back( field_descriptors.emplace_back(
{(pybind11::str) name, format.strip_padding(format.itemsize()), offset}); std::move(name), format.strip_padding(format.itemsize()), std::move(offset));
} }
std::sort(field_descriptors.begin(), std::sort(field_descriptors.begin(),
@ -1405,7 +1409,7 @@ PYBIND11_NOINLINE void register_structured_dtype(any_container<field_descriptor>
} }
auto tindex = std::type_index(tinfo); auto tindex = std::type_index(tinfo);
numpy_internals.registered_dtypes[tindex] = {dtype_ptr, format_str}; numpy_internals.registered_dtypes[tindex] = {dtype_ptr, std::move(format_str)};
get_internals().direct_conversions[tindex].push_back(direct_converter); get_internals().direct_conversions[tindex].push_back(direct_converter);
} }

View File

@ -31,8 +31,8 @@ py::bytes return_bytes() {
std::string print_bytes(const py::bytes &bytes) { std::string print_bytes(const py::bytes &bytes) {
std::string ret = "bytes["; std::string ret = "bytes[";
const auto value = static_cast<std::string>(bytes); const auto value = static_cast<std::string>(bytes);
for (size_t i = 0; i < value.length(); ++i) { for (char c : value) {
ret += std::to_string(static_cast<int>(value[i])) + " "; ret += std::to_string(static_cast<int>(c)) + ' ';
} }
ret.back() = ']'; ret.back() = ']';
return ret; return ret;