From b3ebd11d9851007f525e2e41de53b7913b24787c Mon Sep 17 00:00:00 2001 From: "Lonnie L. Souder II" Date: Fri, 1 Apr 2022 01:16:10 -0400 Subject: [PATCH] feature: support compilers that use std::experimental::filesystem (#3840) * feature: support compilers that use std::experimental::filesystem such as gcc7 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * only use this feature if cpp17 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * more specific namespace alias + style * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * move to pybind11 namespace * no namespace alias * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci Co-authored-by: Lonnie Souder II Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- include/pybind11/stl/filesystem.h | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/include/pybind11/stl/filesystem.h b/include/pybind11/stl/filesystem.h index 93727424c..e26f42177 100644 --- a/include/pybind11/stl/filesystem.h +++ b/include/pybind11/stl/filesystem.h @@ -13,21 +13,28 @@ #include #ifdef __has_include -# if defined(PYBIND11_CPP17) && __has_include() -# include -# define PYBIND11_HAS_FILESYSTEM 1 +# if defined(PYBIND11_CPP17) +# if __has_include() && \ + PY_VERSION_HEX >= 0x03060000 +# include +# define PYBIND11_HAS_FILESYSTEM 1 +# elif __has_include() +# include +# define PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM 1 +# endif # endif #endif -#if !defined(PYBIND11_HAS_FILESYSTEM) && !defined(PYBIND11_HAS_FILESYSTEM_IS_OPTIONAL) +#if !defined(PYBIND11_HAS_FILESYSTEM) && !defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) \ + && !defined(PYBIND11_HAS_FILESYSTEM_IS_OPTIONAL) # error \ - "#include is not available. (Use -DPYBIND11_HAS_FILESYSTEM_IS_OPTIONAL to ignore.)" + "Neither #include nor #include struct path_caster { @@ -94,9 +101,16 @@ public: PYBIND11_TYPE_CASTER(T, const_name("os.PathLike")); }; +#endif // PYBIND11_HAS_FILESYSTEM || defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) + +#if defined(PYBIND11_HAS_FILESYSTEM) template <> struct type_caster : public path_caster {}; -#endif // PYBIND11_HAS_FILESYSTEM +#elif defined(PYBIND11_HAS_EXPERIMENTAL_FILESYSTEM) +template <> +struct type_caster + : public path_caster {}; +#endif PYBIND11_NAMESPACE_END(detail) PYBIND11_NAMESPACE_END(PYBIND11_NAMESPACE)