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)