mirror of
https://github.com/pybind/pybind11.git
synced 2024-11-30 08:57:11 +00:00
Merge branch 'pybind:master' into master
This commit is contained in:
commit
aa4a9ff4d2
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
docs/*.svg binary
|
32
.github/matchers/pylint.json
vendored
Normal file
32
.github/matchers/pylint.json
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
{
|
||||||
|
"problemMatcher": [
|
||||||
|
{
|
||||||
|
"severity": "warning",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"regexp": "^([^:]+):(\\d+):(\\d+): ([A-DF-Z]\\d+): \\033\\[[\\d;]+m([^\\033]+).*$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"code": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"owner": "pylint-warning"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"severity": "error",
|
||||||
|
"pattern": [
|
||||||
|
{
|
||||||
|
"regexp": "^([^:]+):(\\d+):(\\d+): (E\\d+): \\033\\[[\\d;]+m([^\\033]+).*$",
|
||||||
|
"file": 1,
|
||||||
|
"line": 2,
|
||||||
|
"column": 3,
|
||||||
|
"code": 4,
|
||||||
|
"message": 5
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"owner": "pylint-error"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
5
.github/workflows/format.yml
vendored
5
.github/workflows/format.yml
vendored
@ -12,6 +12,9 @@ on:
|
|||||||
- stable
|
- stable
|
||||||
- "v*"
|
- "v*"
|
||||||
|
|
||||||
|
env:
|
||||||
|
FORCE_COLOR: 3
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
pre-commit:
|
pre-commit:
|
||||||
name: Format
|
name: Format
|
||||||
@ -19,6 +22,8 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: actions/setup-python@v2
|
- uses: actions/setup-python@v2
|
||||||
|
- name: Add matchers
|
||||||
|
run: echo "::add-matcher::$GITHUB_WORKSPACE/.github/matchers/pylint.json"
|
||||||
- uses: pre-commit/action@v2.0.3
|
- uses: pre-commit/action@v2.0.3
|
||||||
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
|
||||||
|
@ -59,7 +59,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.11"
|
rev: "v1.1.12"
|
||||||
hooks:
|
hooks:
|
||||||
- id: remove-tabs
|
- id: remove-tabs
|
||||||
|
|
||||||
@ -87,23 +87,30 @@ repos:
|
|||||||
- id: rst-directive-colons
|
- id: rst-directive-colons
|
||||||
- id: rst-inline-touching-normal
|
- id: rst-inline-touching-normal
|
||||||
|
|
||||||
# Flake8 also supports pre-commit natively (same author)
|
|
||||||
- repo: https://github.com/PyCQA/flake8
|
|
||||||
rev: "4.0.1"
|
|
||||||
hooks:
|
|
||||||
- id: flake8
|
|
||||||
additional_dependencies: &flake8_dependencies
|
|
||||||
- flake8-bugbear
|
|
||||||
- pep8-naming
|
|
||||||
exclude: ^(docs/.*|tools/.*)$
|
|
||||||
|
|
||||||
# Automatically remove noqa that are not used
|
# Automatically remove noqa that are not used
|
||||||
- repo: https://github.com/asottile/yesqa
|
- repo: https://github.com/asottile/yesqa
|
||||||
rev: "v1.3.0"
|
rev: "v1.3.0"
|
||||||
hooks:
|
hooks:
|
||||||
- id: yesqa
|
- id: yesqa
|
||||||
|
additional_dependencies: &flake8_dependencies
|
||||||
|
- flake8-bugbear
|
||||||
|
- pep8-naming
|
||||||
|
|
||||||
|
# Flake8 also supports pre-commit natively (same author)
|
||||||
|
- repo: https://github.com/PyCQA/flake8
|
||||||
|
rev: "4.0.1"
|
||||||
|
hooks:
|
||||||
|
- id: flake8
|
||||||
|
exclude: ^(docs/.*|tools/.*)$
|
||||||
additional_dependencies: *flake8_dependencies
|
additional_dependencies: *flake8_dependencies
|
||||||
|
|
||||||
|
# PyLint has native support - not always usable, but works for us
|
||||||
|
- repo: https://github.com/PyCQA/pylint
|
||||||
|
rev: "v2.12.2"
|
||||||
|
hooks:
|
||||||
|
- id: pylint
|
||||||
|
files: ^pybind11
|
||||||
|
|
||||||
# CMake formatting
|
# CMake formatting
|
||||||
- repo: https://github.com/cheshirekow/cmake-format-precommit
|
- repo: https://github.com/cheshirekow/cmake-format-precommit
|
||||||
rev: "v0.6.13"
|
rev: "v0.6.13"
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
|
import os
|
||||||
|
|
||||||
import nox
|
import nox
|
||||||
|
|
||||||
nox.options.sessions = ["lint", "tests", "tests_packaging"]
|
nox.options.sessions = ["lint", "tests", "tests_packaging"]
|
||||||
|
|
||||||
PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11"]
|
PYTHON_VERISONS = ["3.6", "3.7", "3.8", "3.9", "3.10", "3.11", "pypy3.7", "pypy3.8"]
|
||||||
|
|
||||||
|
if os.environ.get("CI", None):
|
||||||
|
nox.options.error_on_missing_interpreters = True
|
||||||
|
|
||||||
|
|
||||||
@nox.session(reuse_venv=True)
|
@nox.session(reuse_venv=True)
|
||||||
@ -14,7 +19,7 @@ def lint(session: nox.Session) -> None:
|
|||||||
session.run("pre-commit", "run", "-a")
|
session.run("pre-commit", "run", "-a")
|
||||||
|
|
||||||
|
|
||||||
@nox.session(python=PYTHON_VERSIONS)
|
@nox.session(python=PYTHON_VERISONS)
|
||||||
def tests(session: nox.Session) -> None:
|
def tests(session: nox.Session) -> None:
|
||||||
"""
|
"""
|
||||||
Run the tests (requires a compiler).
|
Run the tests (requires a compiler).
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
# pylint: disable=missing-function-docstring
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import sysconfig
|
import sysconfig
|
||||||
|
@ -3,16 +3,23 @@ import os
|
|||||||
DIR = os.path.abspath(os.path.dirname(__file__))
|
DIR = os.path.abspath(os.path.dirname(__file__))
|
||||||
|
|
||||||
|
|
||||||
def get_include(user: bool = False) -> str:
|
def get_include(user: bool = False) -> str: # pylint: disable=unused-argument
|
||||||
|
"""
|
||||||
|
Return the path to the pybind11 include directory. The historical "user"
|
||||||
|
argument is unused, and may be removed.
|
||||||
|
"""
|
||||||
installed_path = os.path.join(DIR, "include")
|
installed_path = os.path.join(DIR, "include")
|
||||||
source_path = os.path.join(os.path.dirname(DIR), "include")
|
source_path = os.path.join(os.path.dirname(DIR), "include")
|
||||||
return installed_path if os.path.exists(installed_path) else source_path
|
return installed_path if os.path.exists(installed_path) else source_path
|
||||||
|
|
||||||
|
|
||||||
def get_cmake_dir() -> str:
|
def get_cmake_dir() -> str:
|
||||||
|
"""
|
||||||
|
Return the path to the pybind11 CMake module directory.
|
||||||
|
"""
|
||||||
cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11")
|
cmake_installed_path = os.path.join(DIR, "share", "cmake", "pybind11")
|
||||||
if os.path.exists(cmake_installed_path):
|
if os.path.exists(cmake_installed_path):
|
||||||
return cmake_installed_path
|
return cmake_installed_path
|
||||||
else:
|
|
||||||
msg = "pybind11 not installed, installation required to access the CMake files"
|
msg = "pybind11 not installed, installation required to access the CMake files"
|
||||||
raise ImportError(msg)
|
raise ImportError(msg)
|
||||||
|
@ -239,7 +239,7 @@ def has_flag(compiler: Any, flag: str) -> bool:
|
|||||||
with tmp_chdir():
|
with tmp_chdir():
|
||||||
fname = Path("flagcheck.cpp")
|
fname = Path("flagcheck.cpp")
|
||||||
# Don't trigger -Wunused-parameter.
|
# Don't trigger -Wunused-parameter.
|
||||||
fname.write_text("int main (int, char **) { return 0; }")
|
fname.write_text("int main (int, char **) { return 0; }", encoding="utf-8")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
compiler.compile([str(fname)], extra_postargs=[flag])
|
compiler.compile([str(fname)], extra_postargs=[flag])
|
||||||
@ -303,15 +303,17 @@ def intree_extensions(
|
|||||||
"""
|
"""
|
||||||
exts = []
|
exts = []
|
||||||
|
|
||||||
for path in paths:
|
|
||||||
if package_dir is None:
|
if package_dir is None:
|
||||||
|
for path in paths:
|
||||||
parent, _ = os.path.split(path)
|
parent, _ = os.path.split(path)
|
||||||
while os.path.exists(os.path.join(parent, "__init__.py")):
|
while os.path.exists(os.path.join(parent, "__init__.py")):
|
||||||
parent, _ = os.path.split(parent)
|
parent, _ = os.path.split(parent)
|
||||||
relname, _ = os.path.splitext(os.path.relpath(path, parent))
|
relname, _ = os.path.splitext(os.path.relpath(path, parent))
|
||||||
qualified_name = relname.replace(os.path.sep, ".")
|
qualified_name = relname.replace(os.path.sep, ".")
|
||||||
exts.append(Pybind11Extension(qualified_name, [path]))
|
exts.append(Pybind11Extension(qualified_name, [path]))
|
||||||
else:
|
return exts
|
||||||
|
|
||||||
|
for path in paths:
|
||||||
for prefix, parent in package_dir.items():
|
for prefix, parent in package_dir.items():
|
||||||
if path.startswith(parent):
|
if path.startswith(parent):
|
||||||
relname, _ = os.path.splitext(os.path.relpath(path, parent))
|
relname, _ = os.path.splitext(os.path.relpath(path, parent))
|
||||||
@ -319,8 +321,8 @@ def intree_extensions(
|
|||||||
if prefix:
|
if prefix:
|
||||||
qualified_name = prefix + "." + qualified_name
|
qualified_name = prefix + "." + qualified_name
|
||||||
exts.append(Pybind11Extension(qualified_name, [path]))
|
exts.append(Pybind11Extension(qualified_name, [path]))
|
||||||
|
break
|
||||||
if not exts:
|
else:
|
||||||
msg = (
|
msg = (
|
||||||
f"path {path} is not a child of any of the directories listed "
|
f"path {path} is not a child of any of the directories listed "
|
||||||
f"in 'package_dir' ({package_dir})"
|
f"in 'package_dir' ({package_dir})"
|
||||||
@ -339,7 +341,7 @@ def naive_recompile(obj: str, src: str) -> bool:
|
|||||||
return os.stat(obj).st_mtime < os.stat(src).st_mtime
|
return os.stat(obj).st_mtime < os.stat(src).st_mtime
|
||||||
|
|
||||||
|
|
||||||
def no_recompile(obg: str, src: str) -> bool:
|
def no_recompile(obg: str, src: str) -> bool: # pylint: disable=unused-argument
|
||||||
"""
|
"""
|
||||||
This is the safest but slowest choice (and is the default) - will always
|
This is the safest but slowest choice (and is the default) - will always
|
||||||
recompile sources.
|
recompile sources.
|
||||||
@ -412,7 +414,7 @@ class ParallelCompile:
|
|||||||
self,
|
self,
|
||||||
envvar: Optional[str] = None,
|
envvar: Optional[str] = None,
|
||||||
default: int = 0,
|
default: int = 0,
|
||||||
max: int = 0,
|
max: int = 0, # pylint: disable=redefined-builtin
|
||||||
needs_recompile: Callable[[str, str], bool] = no_recompile,
|
needs_recompile: Callable[[str, str], bool] = no_recompile,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.envvar = envvar
|
self.envvar = envvar
|
||||||
@ -488,6 +490,9 @@ class ParallelCompile:
|
|||||||
return compile_function
|
return compile_function
|
||||||
|
|
||||||
def install(self: S) -> S:
|
def install(self: S) -> S:
|
||||||
|
"""
|
||||||
|
Installs the compile function into distutils.ccompiler.CCompiler.compile.
|
||||||
|
"""
|
||||||
distutils.ccompiler.CCompiler.compile = self.function() # type: ignore[assignment]
|
distutils.ccompiler.CCompiler.compile = self.function() # type: ignore[assignment]
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -30,3 +30,30 @@ strict = true
|
|||||||
[[tool.mypy.overrides]]
|
[[tool.mypy.overrides]]
|
||||||
module = ["ghapi.*", "setuptools.*"]
|
module = ["ghapi.*", "setuptools.*"]
|
||||||
ignore_missing_imports = true
|
ignore_missing_imports = true
|
||||||
|
|
||||||
|
|
||||||
|
[tool.pytest.ini_options]
|
||||||
|
minversion = "6.0"
|
||||||
|
addopts = ["-ra", "--showlocals", "--strict-markers", "--strict-config"]
|
||||||
|
xfail_strict = true
|
||||||
|
filterwarnings = ["error"]
|
||||||
|
log_cli_level = "info"
|
||||||
|
testpaths = [
|
||||||
|
"tests",
|
||||||
|
]
|
||||||
|
timeout=300
|
||||||
|
|
||||||
|
|
||||||
|
[tool.pylint]
|
||||||
|
master.py-version = "3.6"
|
||||||
|
reports.output-format = "colorized"
|
||||||
|
messages_control.disable = [
|
||||||
|
"design",
|
||||||
|
"fixme",
|
||||||
|
"imports",
|
||||||
|
"line-too-long",
|
||||||
|
"imports",
|
||||||
|
"invalid-name",
|
||||||
|
"protected-access",
|
||||||
|
"missing-module-docstring",
|
||||||
|
]
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
// clang-format off
|
|
||||||
/*
|
/*
|
||||||
tests/test_pickling.cpp -- pickle support
|
tests/test_pickling.cpp -- pickle support
|
||||||
|
|
||||||
@ -11,8 +10,6 @@
|
|||||||
|
|
||||||
#include "pybind11_tests.h"
|
#include "pybind11_tests.h"
|
||||||
|
|
||||||
// clang-format on
|
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
@ -63,8 +60,6 @@ void wrap(py::module m) {
|
|||||||
|
|
||||||
} // namespace exercise_trampoline
|
} // namespace exercise_trampoline
|
||||||
|
|
||||||
// clang-format off
|
|
||||||
|
|
||||||
TEST_SUBMODULE(pickling, m) {
|
TEST_SUBMODULE(pickling, m) {
|
||||||
// test_roundtrip
|
// test_roundtrip
|
||||||
class Pickleable {
|
class Pickleable {
|
||||||
@ -76,6 +71,7 @@ TEST_SUBMODULE(pickling, m) {
|
|||||||
void setExtra2(int extra2) { m_extra2 = extra2; }
|
void setExtra2(int extra2) { m_extra2 = extra2; }
|
||||||
int extra1() const { return m_extra1; }
|
int extra1() const { return m_extra1; }
|
||||||
int extra2() const { return m_extra2; }
|
int extra2() const { return m_extra2; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_value;
|
std::string m_value;
|
||||||
int m_extra1 = 0;
|
int m_extra1 = 0;
|
||||||
@ -88,8 +84,7 @@ TEST_SUBMODULE(pickling, m) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
py::class_<Pickleable> pyPickleable(m, "Pickleable");
|
py::class_<Pickleable> pyPickleable(m, "Pickleable");
|
||||||
pyPickleable
|
pyPickleable.def(py::init<std::string>())
|
||||||
.def(py::init<std::string>())
|
|
||||||
.def("value", &Pickleable::value)
|
.def("value", &Pickleable::value)
|
||||||
.def("extra1", &Pickleable::extra1)
|
.def("extra1", &Pickleable::extra1)
|
||||||
.def("extra2", &Pickleable::extra2)
|
.def("extra2", &Pickleable::extra2)
|
||||||
@ -147,7 +142,8 @@ TEST_SUBMODULE(pickling, m) {
|
|||||||
using PickleableWithDict::PickleableWithDict;
|
using PickleableWithDict::PickleableWithDict;
|
||||||
};
|
};
|
||||||
|
|
||||||
py::class_<PickleableWithDict> pyPickleableWithDict(m, "PickleableWithDict", py::dynamic_attr());
|
py::class_<PickleableWithDict> pyPickleableWithDict(
|
||||||
|
m, "PickleableWithDict", py::dynamic_attr());
|
||||||
pyPickleableWithDict.def(py::init<std::string>())
|
pyPickleableWithDict.def(py::init<std::string>())
|
||||||
.def_readwrite("value", &PickleableWithDict::value)
|
.def_readwrite("value", &PickleableWithDict::value)
|
||||||
.def_readwrite("extra", &PickleableWithDict::extra)
|
.def_readwrite("extra", &PickleableWithDict::extra)
|
||||||
@ -176,7 +172,8 @@ TEST_SUBMODULE(pickling, m) {
|
|||||||
.def(py::init<std::string>())
|
.def(py::init<std::string>())
|
||||||
.def(py::pickle(
|
.def(py::pickle(
|
||||||
[](const py::object &self) {
|
[](const py::object &self) {
|
||||||
return py::make_tuple(self.attr("value"), self.attr("extra"), self.attr("__dict__"));
|
return py::make_tuple(
|
||||||
|
self.attr("value"), self.attr("extra"), self.attr("__dict__"));
|
||||||
},
|
},
|
||||||
[](const py::tuple &t) {
|
[](const py::tuple &t) {
|
||||||
if (t.size() != 3) {
|
if (t.size() != 3) {
|
||||||
|
Loading…
Reference in New Issue
Block a user