From d21b02c2eb0190322dbda6a9a07eed4d6f37530e Mon Sep 17 00:00:00 2001 From: Atila Neves Date: Tue, 22 Sep 2020 12:11:46 +0200 Subject: [PATCH] Remove support for Python2 --- pynih/source/autowrap/pynih/wrap.d | 32 +++--------------------------- pynih/source/python/boilerplate.d | 1 - pynih/source/python/cooked.d | 20 ++++--------------- 3 files changed, 7 insertions(+), 46 deletions(-) diff --git a/pynih/source/autowrap/pynih/wrap.d b/pynih/source/autowrap/pynih/wrap.d index 132886f6..7ff3035b 100644 --- a/pynih/source/autowrap/pynih/wrap.d +++ b/pynih/source/autowrap/pynih/wrap.d @@ -8,7 +8,6 @@ public import std.typecons: Yes, No; public import autowrap.types: Modules, Module, isModule, LibraryName, PreModuleInitCode, PostModuleInitCode, RootNamespace, Ignore; static import python.boilerplate; -import python.raw: isPython2, isPython3; import std.meta: allSatisfy; @@ -67,17 +66,9 @@ string createPythonModuleMixin(LibraryName libraryName, Modules modules) private string pyInitFuncName(LibraryName libraryName) @safe pure nothrow { - - string prefix() { - static if(isPython2) - return "init"; - else static if(isPython3) - return "PyInit_"; - else - static assert(false); - } - - return prefix ~ libraryName.value; + import python.raw: isPython3; + static assert(isPython3, "Python2 no longer supported"); + return "PyInit_" ~ libraryName.value; } @@ -144,7 +135,6 @@ auto createPythonModule(LibraryName libraryName, modules...)() mixin template createPythonModule(python.boilerplate.Module module_, alias cfunctions, alias aggregates) - if(isPython3) { static extern(C) export auto _py_init_impl() { // -> ModuleInitRet import python.raw: pyDateTimeImport; @@ -157,19 +147,3 @@ mixin template createPythonModule(python.boilerplate.Module module_, alias cfunc return createModule!(module_, cfunctions, aggregates); } } - - -mixin template createPythonModule(python.boilerplate.Module module_, alias cfunctions, alias aggregates) - if(isPython2) -{ - static extern(C) export void _py_init_impl() { - import python.raw: pyDateTimeImport; - import python.cooked: initModule; - import core.runtime: rt_init; - - rt_init; - - pyDateTimeImport; - initModule!(module_, cfunctions, aggregates); - } -} diff --git a/pynih/source/python/boilerplate.d b/pynih/source/python/boilerplate.d index 202d8573..a4f530d0 100644 --- a/pynih/source/python/boilerplate.d +++ b/pynih/source/python/boilerplate.d @@ -1,7 +1,6 @@ module python.boilerplate; -import python.raw: isPython2, isPython3; import std.traits: isFunction; diff --git a/pynih/source/python/cooked.d b/pynih/source/python/cooked.d index 0811ebb7..84f9decd 100644 --- a/pynih/source/python/cooked.d +++ b/pynih/source/python/cooked.d @@ -13,10 +13,11 @@ import python.boilerplate: Module, CFunctions, Aggregates; Each function has the same name in Python. */ auto createModule(Module module_, alias cfunctions, alias aggregates = Aggregates!())() - if(isPython3 && - is(cfunctions == CFunctions!F, F...) && + if(is(cfunctions == CFunctions!F, F...) && is(aggregates == Aggregates!T, T...)) { + static assert(isPython3, "Python2 no longer supported"); + static PyModuleDef moduleDef; auto pyMethodDefs = cFunctionsToPyMethodDefs!(cfunctions); @@ -29,19 +30,6 @@ auto createModule(Module module_, alias cfunctions, alias aggregates = Aggregate } -/** - Calls Py_InitModule. It's the Python2 way of creating a new Python module. - Each function has the same name in Python. - */ -void initModule(Module module_, alias cfunctions, alias aggregates)() - if(isPython2 && - is(cfunctions == CFunctions!F, F...) && - is(aggregates == Aggregates!T, T...)) -{ - auto module_ = pyInitModule(&module_.name[0], cFunctionsToPyMethodDefs!(cfunctions)); - addModuleTypes!aggregates(module_); -} - private void addModuleTypes(alias aggregates)(PyObject* module_) { import autowrap.common: AlwaysTry; import python.type: PythonType; @@ -85,7 +73,7 @@ private PyMethodDef* cFunctionsToPyMethodDefs(alias cfunctions)() Helper function to get around the C syntax problem with PyModuleDef_HEAD_INIT - it doesn't compile in D. */ -private auto pyModuleDef(A...)(auto ref A args) if(isPython3) { +private auto pyModuleDef(A...)(auto ref A args) { import std.functional: forward; return PyModuleDef(